just need to add actual start/stop/status functions now

This commit is contained in:
neersighted 2012-03-01 14:54:28 -08:00
parent 52cbd56a15
commit 34d2474f99

View file

@ -1,4 +1,5 @@
#!/bin/sh #!/bin/bash
echo
echo "Welcome to: " echo "Welcome to: "
echo " ______ __ ______ __ __ _______ .______ ______ .___________." echo " ______ __ ______ __ __ _______ .______ ______ .___________."
echo " / || | / __ \ | | | | | \ | _ \ / __ \ | |" echo " / || | / __ \ | | | | | \ | _ \ / __ \ | |"
@ -7,41 +8,66 @@ echo "| | | | | | | | | | | | | | | || _ < | | | |
echo "| \`----.| \`----.| \`--' | | \`--' | | '--' || |_) | | \`--' | | | " echo "| \`----.| \`----.| \`--' | | \`--' | | '--' || |_) | | \`--' | | | "
echo " \______||_______| \______/ \______/ |_______/ |______/ \______/ |__| " echo " \______||_______| \______/ \______/ |_______/ |______/ \______/ |__| "
echo " http://git.io/cloudbot by lukeroge " echo " http://git.io/cloudbot by lukeroge "
echo
checkbackends() { checkbackend() {
backends=0 if dpkg -l| grep ^ii|grep daemon|grep 'turns other' > /dev/null; then
if dpkg -l | grep ^ii | grep screen | grep -i 'turns other' > /dev/null; then
backends=$((backends+1))
else
backend="daemon" backend="daemon"
fi echo "backend: daemon"
if dpkg -l | grep ^ii | grep daemon | grep -i 'terminal multi' > /dev/null; then elif dpkg -l| grep ^ii|grep screen|grep 'terminal multi' > /dev/null; then
backends=$((backends+1))
else
backend="screen" backend="screen"
fi echo "backend: screen"
if [ "$backends" -lt 1 ]; then else
echo "No `daemon` or `screen` detected, running manually"
backend="manual" backend="manual"
echo "backend: manual"
fi fi
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() { processargs() {
if [ "$backend" == "daemon" ]; then args=$1
start = "daemon -r -n cloudbot -O ./bot.log python ./bot.py" case $args in
stop="daemon -n cloudbot --stop" start)
restart="./cloudbot stop > /dev/null 2>&1 && ./cloudbot start > /dev/null 2>&1" start
pid="pidof /usr/bin/daemon" ;;
elif [ "$backend" == "screen" ]; then stop)
start="screen -d -m -S cloudbot -t cloudbot python ./bot.py > ./bot.log 2>&1" stop
stop="kill `pidof /usr/bin/screen`" ;;
restart="./cloudbot stop > /dev/null 2>&1 && ./cloudbot start > /dev/null 2>&1" restart)
pid="pidof /usr/bin/screen" stop
elif [ "$backend" == "manual" ]; then start
} ;;
status)
status
;;
}
main() {
checkbackend
setcommands
processargs
}
main