forked from moe-serifu-circle/masabot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-masabot.sh
executable file
·83 lines (74 loc) · 1.93 KB
/
run-masabot.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# starts up masabot and redeploys when necessary
#
# options:
#
# $1 - venv-dir - path to the directory to use for the virtual environment, default to '.venv' or 'venv' in that order
# if none is given.
if [ "$#" -ge 1 ]
then
if [ -d "$1" ]
then
virtual_dir="$1"
else
echo "Virtual environemnt directory '$1' not found." >&2
echo "Abort." >&2
exit 1
fi
else
echo "No virtual environment directory given; scanning for '.venv' or 'venv'..." >&2
if [ -d .venv ]
then
virtual_dir=.venv
elif [ -d venv ]
then
virtual_dir=venv
else
echo "Could not auto-detect virtual environment directory '.venv' or 'venv'." >&2
echo "Please create one for masabot before executing, or point to existing one with CLI arguments." >&2
exit 1
fi
fi
running=1
echo "Using virtual environment directory '$virtual_dir'"
if [ -d "$virtual_dir/bin" ]
then
virtualenv_path="$virtual_dir/bin"
elif [ -d "$virtual_dir/Scripts" ]
then
virtualenv_path="$virtual_dir/Scripts"
else
echo "Virtual environment not found in '$virtual_dir/bin' or '$virtual_dir/Scripts'." >&2
echo "Please ensure setup is correct." >&2
exit 1
fi
. "$virtualenv_path/activate"
if [ -d "ipc" ]
then
rm -rf "ipc"/*
else
mkdir "ipc"
fi
python supervisor/supervisor.py initial-deploy "$virtual_dir"
while [ -n "$running" ]
do
python masabot.py
if [ -f "ipc/restart-command" ]
then
cmd="$(cat "ipc/restart-command")"
rm -rf "ipc/restart-command"
if [ "$cmd" = "redeploy" ]
then
git pull
python supervisor/supervisor.py redeploy "$virtual_dir"
elif [ "$cmd" = "quit" ]
then
running=
echo "Clean shutdown"
fi
else
echo "Unclean shutdown; restarting bot in 30 seconds..."
sleep 30
echo '{"reason":"Exited without receiving quit command"}' >> "ipc/unclean-shutdown"
fi
done