Advertisement
i_gnatenko_brain

/etc/init.d/teeworlds_all_ctf

Dec 21st, 2012
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.60 KB | None | 0 0
  1. #!/bin/bash
  2. ### BEGIN INIT INFO
  3. # Provides:     teeworlds_all_ctf
  4. # Required-Start:   $remote_fs $network
  5. # Required-Stop:    $remote_fs
  6. # Default-Start:        2 3 4 5
  7. # Default-Stop:    
  8. # Short-Description:    Teeworlds all ctf server
  9. ### END INIT INFO
  10.  
  11. SCREEN_NAME="teeworlds_all_ctf"
  12. USER="server"
  13. DIR="/home/$USER/teeworlds"
  14. CONFIG="$DIR/$SCREEN_NAME.cfg"
  15. DAEMON_GAME="/usr/games/teeworlds-server"
  16. PARAM_START="-f $CONFIG"
  17.  
  18. # Do not change this path
  19. PATH=/bin:/usr/bin:/sbin:/usr/sbin
  20.  
  21. function start {
  22.   if status; then echo "$SCREEN_NAME is already running"; exit 1; fi
  23.   if [ `whoami` = root ]
  24.   then
  25.     su - $USER -c "cd $DIR_USER; screen -AmdS $SCREEN_NAME $DAEMON_GAME $PARAM_START"
  26.   else
  27.     cd $DIR_USER
  28.     screen -AmdS $SCREEN_NAME $DAEMON_GAME $PARAM_START
  29.   fi
  30. }
  31.  
  32. function stop {
  33.   if ! status; then echo "$SCREEN_NAME could not be found. Probably not running."; exit 1; fi
  34.   if [ `whoami` = root ]
  35.   then
  36.     tmp=$(su - $USER -c "screen -ls" | awk -F . "/\.$SCREEN_NAME\t/ {print $1}" | awk '{print $1}')
  37.     su - $USER -c "screen -r $tmp -X quit"
  38.   else
  39.     screen -r $(screen -ls | awk -F . "/\.$SCREEN_NAME\t/ {print $1}" | awk '{print $1}') -X quit
  40.   fi
  41. }
  42.  
  43. function status {
  44.   if [ `whoami` = root ]
  45.   then
  46.     su - $USER -c "screen -ls" | grep [.]$SCREEN_NAME[[:space:]] > /dev/null
  47.   else
  48.     screen -ls | grep [.]$SCREEN_NAME[[:space:]] > /dev/null
  49.   fi
  50. }
  51.  
  52. function console {
  53.   if ! status; then echo "$SCREEN_NAME could not be found. Probably not running."; exit 1; fi
  54.   if [ `whoami` = root ]
  55.   then
  56.     tmp=$(su - $USER -c "screen -ls" | awk -F . "/\.$SCREEN_NAME\t/ {print $1}" | awk '{print $1}')
  57.     su - $USER -c "screen -r $tmp"
  58.   else
  59.     screen -r $(screen -ls | awk -F . "/\.$SCREEN_NAME\t/ {print $1}" | awk '{print $1}')
  60.   fi
  61. }
  62.  
  63. function usage {
  64.   echo "Usage: $0 {start|stop|status|restart|console}"
  65.   echo "On console, press CTRL+A then D to stop the screen without stopping the server."
  66. }
  67.  
  68. case "$1" in
  69.  
  70.   start)
  71.     echo "Starting $SCREEN_NAME..."
  72.     start
  73.     sleep 5
  74.     echo "$SCREEN_NAME started successfully"
  75.   ;;
  76.  
  77.   stop)
  78.     echo "Stopping $SCREEN_NAME..."
  79.     stop
  80.     sleep 5
  81.     echo "$SCREEN_NAME stopped successfully"
  82.   ;;
  83.  
  84.   restart)
  85.     echo "Restarting $SCREEN_NAME..."
  86.     status && stop
  87.     sleep 5
  88.     start
  89.     sleep 5
  90.     echo "$SCREEN_NAME restarted successfully"
  91.   ;;
  92.  
  93.   status)
  94.     if status
  95.     then echo "$SCREEN_NAME is UP"
  96.     else echo "$SCREEN_NAME is DOWN"
  97.     fi
  98.   ;;
  99.  
  100.   console)
  101.     echo "Open console on $SCREEN_NAME..."
  102.     console
  103.   ;;
  104.  
  105.   *)
  106.     usage
  107.     exit 1
  108.   ;;
  109.  
  110. esac
  111.  
  112. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement