Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ### BEGIN INIT INFO
- # Provides: teeworlds_all_ctf
- # Required-Start: $remote_fs $network
- # Required-Stop: $remote_fs
- # Default-Start: 2 3 4 5
- # Default-Stop:
- # Short-Description: Teeworlds all ctf server
- ### END INIT INFO
- SCREEN_NAME="teeworlds_all_ctf"
- USER="server"
- DIR="/home/$USER/teeworlds"
- CONFIG="$DIR/$SCREEN_NAME.cfg"
- DAEMON_GAME="/usr/games/teeworlds-server"
- PARAM_START="-f $CONFIG"
- # Do not change this path
- PATH=/bin:/usr/bin:/sbin:/usr/sbin
- function start {
- if status; then echo "$SCREEN_NAME is already running"; exit 1; fi
- if [ `whoami` = root ]
- then
- su - $USER -c "cd $DIR_USER; screen -AmdS $SCREEN_NAME $DAEMON_GAME $PARAM_START"
- else
- cd $DIR_USER
- screen -AmdS $SCREEN_NAME $DAEMON_GAME $PARAM_START
- fi
- }
- function stop {
- 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 -X quit"
- else
- screen -r $(screen -ls | awk -F . "/\.$SCREEN_NAME\t/ {print $1}" | awk '{print $1}') -X quit
- 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 5
- 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 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement