working prototype
This commit is contained in:
parent
34d2474f99
commit
99ae86bc9b
113
cloudbot.sh
113
cloudbot.sh
|
@ -10,6 +10,16 @@ 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() {
|
||||||
|
botfile="/bot.py"
|
||||||
|
botfile=$(pwd)$botfile
|
||||||
|
logfile="/botlog"
|
||||||
|
logfile=$(pwd)$logfile
|
||||||
|
}
|
||||||
|
|
||||||
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"
|
||||||
|
@ -24,50 +34,85 @@ checkbackend() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
setcommands() {
|
|
||||||
if [ "$backend" == "daemon" ]; then
|
|
||||||
start="daemon -r -n cloudbot -O ./bot.log python ./bot.py"
|
|
||||||
stop="daemon -n cloudbot --stop"
|
|
||||||
pid="pidof /usr/bin/daemon"
|
|
||||||
elif [ "$backend" == "screen" ]; then
|
|
||||||
start="screen -d -m -S cloudbot -t cloudbot python ./bot.py > ./bot.log 2>&1"
|
|
||||||
stop="kill $(pidof /usr/bin/screen)"
|
|
||||||
pid="pidof /usr/bin/screen"
|
|
||||||
elif [ "$backend" == "manual" ]; then
|
|
||||||
start="./bot.py"
|
|
||||||
stop="kill $(pidof ./bot.py)"
|
|
||||||
restart="./cloudbot stop > /dev/null 2>&1 && ./cloudbot start > /dev/null 2>&1"
|
|
||||||
fi
|
|
||||||
restart="./cloudbot stop > /dev/null 2>&1 && ./cloudbot start > /dev/null 2>&1"
|
|
||||||
}
|
|
||||||
|
|
||||||
running() {
|
running() {
|
||||||
ps ax|grep bot|grep -v grep|grep -v ./cloudbot
|
ps ax|grep bot|grep -v grep|grep -v ./cloudbot
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
||||||
|
if running; then
|
||||||
|
echo "CloudBot is running!"
|
||||||
|
pid
|
||||||
|
else
|
||||||
|
echo "CloudBot is not running!"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
clear() {
|
||||||
|
: > $logfile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
processargs() {
|
processargs() {
|
||||||
args=$1
|
case $1 in
|
||||||
case $args in
|
start)
|
||||||
start)
|
start
|
||||||
start
|
;;
|
||||||
;;
|
stop)
|
||||||
stop)
|
stop
|
||||||
stop
|
;;
|
||||||
;;
|
restart)
|
||||||
restart)
|
stop
|
||||||
stop
|
start
|
||||||
start
|
;;
|
||||||
;;
|
clear)
|
||||||
status)
|
clear
|
||||||
status
|
;;
|
||||||
;;
|
status)
|
||||||
|
status
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo $usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
locatefiles
|
||||||
checkbackend
|
checkbackend
|
||||||
setcommands
|
setcommands
|
||||||
processargs
|
processargs $1
|
||||||
}
|
}
|
||||||
|
|
||||||
main
|
main $*
|
Reference in a new issue