Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- ##################################################################################
- # #
- # Usage: ./start.sh {start|stop|status|restart|console} #
- # - start: start the bot #
- # - stop: stop the bot #
- # - status: display the status of the bot (down or up) #
- # - restart: restart the bot #
- # - console: display the bot console #
- # To exit the console without stopping the server, press CTRL + A then D. #
- # #
- ##################################################################################
- SCREEN_NAME="sinusbot"
- USER="sinusbot"
- DIR_ROOT="/home/sinusbot"
- BOT_RUNCMD="xinit ./sinusbot -- /usr/bin/Xvfb :1 -screen 0 800x600x16 -ac"
- # No edits necessary beyond this line
- PATH=/bin:/usr/bin:/sbin:/usr/sbin
- if [ ! -x `which awk` ]; then echo "ERROR: You need awk for this script (try apt-get install awk)"; exit 1; fi
- if [ ! -x `which screen` ]; then echo "ERROR: You need screen for this script (try apt-get install screen)"; exit 1; fi
- function start {
- if [ ! -d $DIR_ROOT ]; then echo "ERROR: $DIR_ROOT is not a directory"; exit 1; fi
- if status; then echo "$SCREEN_NAME is already running"; exit 1; fi
- # Start bot
- if [ `whoami` = root ]
- then
- su - $USER -c "cd $DIR_ROOT ; screen -AmdS $SCREEN_NAME $BOT_RUNCMD"
- else
- cd $DIR_ROOT
- screen -AmdS $SCREEN_NAME $BOT_RUNCMD
- fi
- }
- function stop {
- if ! status; then echo "$SCREEN_NAME could not be found. Probably not running."; exit 1; fi
- if [ `whoami` = root ]
- then
- su - $USER -c "killall ts3bot -u $USER"
- else
- killall ts3bot -u $USER
- fi
- }
- function status {
- if [ `whoami` = root ]
- then
- su - $USER -c "screen -ls" | grep [.]$SCREEN_NAME[[:space:]] > /dev/null
- else
- screen -ls | grep [.]$SCREEN_NAME[[:space:]] > /dev/null
- fi
- }
- function console {
- if ! status; then echo "$SCREEN_NAME could not be found. Probably not running."; exit 1; fi
- if [ `whoami` = root ]
- then
- tmp=$(su - $USER -c "screen -ls" | awk -F . "/\.$SCREEN_NAME\t/ {print $1}" | awk '{print $1}')
- su - $USER -c "screen -r $tmp"
- else
- screen -r $(screen -ls | awk -F . "/\.$SCREEN_NAME\t/ {print $1}" | awk '{print $1}')
- fi
- }
- function usage {
- echo "Usage: $0 {start|stop|status|restart|console}"
- echo "On console, press CTRL+A then D to stop the screen without stopping the server."
- }
- case "$1" in
- start)
- echo "Starting $SCREEN_NAME..."
- start
- sleep 5
- echo "$SCREEN_NAME started successfully"
- ;;
- stop)
- echo "Stopping $SCREEN_NAME..."
- stop
- sleep 5
- echo "$SCREEN_NAME stopped successfully"
- ;;
- restart)
- echo "Restarting $SCREEN_NAME..."
- status && stop
- sleep 10
- start
- sleep 5
- echo "$SCREEN_NAME restarted successfully"
- ;;
- status)
- if status
- then echo "$SCREEN_NAME is UP"
- else echo "$SCREEN_NAME is DOWN"
- fi
- ;;
- console)
- echo "Open console on $SCREEN_NAME..."
- console
- ;;
- *)
- usage
- exit 1
- ;;
- esac
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement