every thing but restart works. as always
This commit is contained in:
parent
99ae86bc9b
commit
6e47185c6c
1 changed files with 55 additions and 48 deletions
95
cloudbot.sh
95
cloudbot.sh
|
@ -10,71 +10,36 @@ echo " \______||_______| \______/ \______/ |_______/ |______/ \______/
|
||||||
echo " http://git.io/cloudbot by lukeroge "
|
echo " http://git.io/cloudbot by lukeroge "
|
||||||
echo
|
echo
|
||||||
|
|
||||||
args=$*
|
|
||||||
usage="./cloudbot {start|stop|restart|clear|status}"
|
|
||||||
|
|
||||||
locatefiles() {
|
locatefiles() {
|
||||||
botfile="/bot.py"
|
botfile="/bot.py"
|
||||||
botfile=$(pwd)$botfile
|
botfile=$(pwd)$botfile
|
||||||
logfile="/botlog"
|
logfile="/bot.log"
|
||||||
logfile=$(pwd)$logfile
|
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() {
|
checkbackend() {
|
||||||
if dpkg -l| grep ^ii|grep daemon|grep 'turns other' > /dev/null; then
|
if dpkg -l| grep ^ii|grep daemon|grep 'turns other' > /dev/null; then
|
||||||
backend="daemon"
|
backend="daemon"
|
||||||
echo "backend: daemon"
|
|
||||||
elif dpkg -l| grep ^ii|grep screen|grep 'terminal multi' > /dev/null; then
|
elif dpkg -l| grep ^ii|grep screen|grep 'terminal multi' > /dev/null; then
|
||||||
backend="screen"
|
backend="screen"
|
||||||
echo "backend: screen"
|
|
||||||
else
|
else
|
||||||
backend="manual"
|
backend="manual"
|
||||||
echo "backend: manual"
|
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
running() {
|
|
||||||
ps ax|grep bot|grep -v grep|grep -v ./cloudbot
|
|
||||||
return $?
|
|
||||||
}
|
|
||||||
|
|
||||||
setcommands() {
|
setcommands() {
|
||||||
if [ "$backend" == "daemon" ]; then
|
|
||||||
start() {
|
|
||||||
daemon -r -n cloudbot -O $logfile python $botfile
|
|
||||||
}
|
|
||||||
stop() {
|
|
||||||
daemon -n cloudbot --stop
|
|
||||||
}
|
|
||||||
pid() {
|
|
||||||
pidof /usr/bin/daemon
|
|
||||||
}
|
|
||||||
elif [ "$backend" == "screen" ]; then
|
|
||||||
start() {
|
|
||||||
screen -d -m -S cloudbot -t cloudbot python $botfile > $logfile 2>&1
|
|
||||||
}
|
|
||||||
stop() {
|
|
||||||
kill $(pidof /usr/bin/screen)
|
|
||||||
}
|
|
||||||
pid() {
|
|
||||||
pidof /usr/bin/screen
|
|
||||||
}
|
|
||||||
elif [ "$backend" == "manual" ]; then
|
|
||||||
start() {
|
|
||||||
$botfile
|
|
||||||
}
|
|
||||||
stop() {
|
|
||||||
kill $(pidof $botfile)
|
|
||||||
}
|
|
||||||
pid() {
|
|
||||||
pidof $botfile
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
status() {
|
status() {
|
||||||
if running; then
|
if running; then
|
||||||
echo "CloudBot is running!"
|
echo "CloudBot is running!"
|
||||||
pid
|
|
||||||
else
|
else
|
||||||
echo "CloudBot is not running!"
|
echo "CloudBot is not running!"
|
||||||
fi
|
fi
|
||||||
|
@ -82,19 +47,60 @@ setcommands() {
|
||||||
clear() {
|
clear() {
|
||||||
: > $logfile
|
: > $logfile
|
||||||
}
|
}
|
||||||
|
if [ "$backend" == "daemon" ]; then
|
||||||
|
start() {
|
||||||
|
daemon -r -n cloudbot -O $logfile python $botfile
|
||||||
|
}
|
||||||
|
stop() {
|
||||||
|
daemon -n cloudbot --stop
|
||||||
|
}
|
||||||
|
elif [ "$backend" == "screen" ]; then
|
||||||
|
start() {
|
||||||
|
screen -d -m -S cloudbot -t cloudbot python $botfile > $logfile 2>&1
|
||||||
|
}
|
||||||
|
stop() {
|
||||||
|
proc=`ps ax|grep -v grep|grep screen|grep $botfile`
|
||||||
|
pid=`top -n 1 -p ${proc:0:5} | grep ${proc:0:5}`
|
||||||
|
kill $pid
|
||||||
|
}
|
||||||
|
elif [ "$backend" == "manual" ]; then
|
||||||
|
start() {
|
||||||
|
$botfile
|
||||||
|
}
|
||||||
|
stop() {
|
||||||
|
proc=`ps ax|grep -v grep|grep python|grep $botfile`
|
||||||
|
pid=`top -n 1 -p ${proc:0:5} | grep ${proc:0:5}`
|
||||||
|
kill $pid
|
||||||
|
}
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
processargs() {
|
processargs() {
|
||||||
case $1 in
|
case $1 in
|
||||||
start)
|
start)
|
||||||
|
if running; then
|
||||||
|
echo "Cannot start! Bot is already running!"
|
||||||
|
else
|
||||||
|
echo "Starting... ($backend)"
|
||||||
start
|
start
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
|
if running; then
|
||||||
|
echo "Stoppinging... ($backend)"
|
||||||
stop
|
stop
|
||||||
|
else
|
||||||
|
echo "Cannot stop! Bot is not already running!"
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
restart)
|
restart)
|
||||||
|
if running; then
|
||||||
|
echo "Restarting... ($backend)"
|
||||||
stop
|
stop
|
||||||
start
|
start
|
||||||
|
else
|
||||||
|
echo "Cannot restart! Bot is not already running!"
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
clear)
|
clear)
|
||||||
clear
|
clear
|
||||||
|
@ -109,6 +115,7 @@ processargs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
usage="./cloudbot {start|stop|restart|clear|status}"
|
||||||
locatefiles
|
locatefiles
|
||||||
checkbackend
|
checkbackend
|
||||||
setcommands
|
setcommands
|
||||||
|
|
Reference in a new issue