every thing but restart works. as always

This commit is contained in:
neersighted 2012-03-01 16:09:45 -08:00
parent 99ae86bc9b
commit 6e47185c6c

View file

@ -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)
start if running; then
echo "Cannot start! Bot is already running!"
else
echo "Starting... ($backend)"
start
fi
;; ;;
stop) stop)
stop if running; then
echo "Stoppinging... ($backend)"
stop
else
echo "Cannot stop! Bot is not already running!"
fi
;; ;;
restart) restart)
stop if running; then
start echo "Restarting... ($backend)"
stop
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