-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathuguubot
executable file
·128 lines (120 loc) · 2.96 KB
/
uguubot
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
echo ""
echo " __ __ "
echo " / / / /___ ___ ____ __"
echo " / / / / __ / / / / / / /"
echo "/ /_/ / /_/ / /_/ / /_/ / "
echo "\____/\__, /\__,_/\__,_/ "
echo " /____/ "
echo ""
locatefiles() {
botfile="/bot.py"
botfile=$(pwd)$botfile
logfile="/bot.log"
logfile=$(pwd)$logfile
}
running() {
if [[ $(ps aux|grep bot.py|grep -v grep|grep -v daemon|grep -v SCREEN) != "" ]]; then
true
else
false
fi
}
checkbackend() {
if dpkg -l| grep ^ii|grep daemon|grep 'turns other' > /dev/null; then
backend="daemon"
elif dpkg -l| grep ^ii|grep screen|grep 'terminal multi' > /dev/null; then
backend="screen"
else
backend="manual"
fi
return 0
}
setcommands() {
status() {
if running; then
echo "UguuBot is running!"
else
echo "UguuBot is not running!"
fi
}
clear() {
: > $logfile
}
if [ "$backend" == "daemon" ]; then
start() {
daemon -r -n uguubot -O $logfile python $botfile
}
stop() {
daemon -n uguubot --stop
}
elif [ "$backend" == "screen" ]; then
start() {
screen -d -m -S uguubot -t uguubot python $botfile > $logfile 2>&1
}
stop() {
pid=`ps ax|grep -v grep|grep python|grep -v SCREEN|grep $botfile|awk '{print $1}'`
kill $pid
}
elif [ "$backend" == "manual" ]; then
start() {
$botfile
}
stop() {
pid=`ps ax|grep -v grep|grep python|grep $botfile|awk '{print $1}'`
kill $pid
}
fi
}
processargs() {
case $1 in
start|-start|--start)
if running; then
echo "Cannot start! Bot is already running!"
exit 1
else
echo "Starting UguuBot... ($backend)"
start
fi
;;
stop|-stop|--stop)
if running; then
echo "Stopping UguuBot... ($backend)"
stop
else
echo "Cannot stop! Bot is not already running!"
exit 1
fi
;;
restart|-restart|--restart)
if running; then
echo "Restarting UguuBot... ($backend)"
stop
sleep 3
start
else
echo "Cannot restart! Bot is not already running!"
exit 1
fi
;;
clear|-clear|--clear)
echo "Clearing logs..."
clear
;;
status|-status|--status)
status
;;
*)
usage="usage: ./uguubot {start|stop|restart|clear|status}"
echo $usage
;;
esac
}
main() {
locatefiles
checkbackend
setcommands
processargs $1
}
main $*
exit 0