-
Notifications
You must be signed in to change notification settings - Fork 0
/
lictl.sh
96 lines (79 loc) · 1.43 KB
/
lictl.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
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
PROG=$(basename $0)
USER="lithil"
PROGRAM_PATH="/opt/lithil"
DATA_PATH="$PROGRAM_PATH/data"
LOG_FILE="$PROGRAM_PATH/lithil.log"
PYTHON=$(which ${PROGRAM_PATH}/venv/bin/python)
help_message(){
cat <<EOF
Usage ${PROG} [action]
Actions:
start:
Starts the bot
stop:
Stops the bot
restart:
Restarts the bot
update:
Pulls the latest github commit into the local repo.
EOF
}
start_bot(){
echo "Starting..."
clear_logs
nohup ${PYTHON} ${PROGRAM_PATH}/Main.py &
echo "Started"
}
stop_bot(){
echo "Stopping..."
PID=$(pgrep -u ${USER} python)
kill -s 15 ${PID}
sleep 2
echo "Stopped"
}
restart_bot(){
stop_bot
start_bot
}
update_bot(){
if [ "pgrep -u ${USER} python" ]; then
stop_bot
fi
git -C "$PROGRAM_PATH" pull
}
show_logs(){
less +F ${LOG_FILE}
}
clear_logs(){
rm ${LOG_FILE}
}
if [ ! -e "$PYTHON" ]; then
echo "ERROR: Python not found!"
echo "Try installing this with:"
echo "sudo apt-get install python"
exit 1
fi
COMMAND=$1
case "$COMMAND" in
start)
start_bot
;;
stop)
stop_bot
;;
restart)
echo "Restarting..."
restart_bot
echo "Restarted"
;;
update)
echo "Updating..."
update_bot
echo "Updated, you should run sudo make update on $PROGRAM_PATH"
;;
logs)
show_logs
;;
esac
exit 0