Advertisement
EntenPlayz

Untitled

May 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. ##################################################################################
  4. # #
  5. # Usage: ./start.sh {start|stop|status|restart|console} #
  6. # - start: start the bot #
  7. # - stop: stop the bot #
  8. # - status: display the status of the bot (down or up) #
  9. # - restart: restart the bot #
  10. # - console: display the bot console #
  11. # To exit the console without stopping the server, press CTRL + A then D. #
  12. # #
  13. ##################################################################################
  14.  
  15. SCREEN_NAME="sinusbot"
  16. USER="sinusbot"
  17. DIR_ROOT="/home/sinusbot"
  18. BOT_RUNCMD="xinit ./sinusbot -- /usr/bin/Xvfb :1 -screen 0 800x600x16 -ac"
  19.  
  20. # No edits necessary beyond this line
  21. PATH=/bin:/usr/bin:/sbin:/usr/sbin
  22. if [ ! -x `which awk` ]; then echo "ERROR: You need awk for this script (try apt-get install awk)"; exit 1; fi
  23. if [ ! -x `which screen` ]; then echo "ERROR: You need screen for this script (try apt-get install screen)"; exit 1; fi
  24.  
  25. function start {
  26. if [ ! -d $DIR_ROOT ]; then echo "ERROR: $DIR_ROOT is not a directory"; exit 1; fi
  27. if status; then echo "$SCREEN_NAME is already running"; exit 1; fi
  28.  
  29. # Start bot
  30. if [ `whoami` = root ]
  31. then
  32. su - $USER -c "cd $DIR_ROOT ; screen -AmdS $SCREEN_NAME $BOT_RUNCMD"
  33. else
  34. cd $DIR_ROOT
  35. screen -AmdS $SCREEN_NAME $BOT_RUNCMD
  36. fi
  37. }
  38.  
  39. function stop {
  40. if ! status; then echo "$SCREEN_NAME could not be found. Probably not running."; exit 1; fi
  41.  
  42. if [ `whoami` = root ]
  43. then
  44. su - $USER -c "killall ts3bot -u $USER"
  45. else
  46. killall ts3bot -u $USER
  47. fi
  48. }
  49.  
  50. function status {
  51. if [ `whoami` = root ]
  52. then
  53. su - $USER -c "screen -ls" | grep [.]$SCREEN_NAME[[:space:]] > /dev/null
  54. else
  55. screen -ls | grep [.]$SCREEN_NAME[[:space:]] > /dev/null
  56. fi
  57. }
  58.  
  59. function console {
  60. if ! status; then echo "$SCREEN_NAME could not be found. Probably not running."; exit 1; fi
  61.  
  62. if [ `whoami` = root ]
  63. then
  64. tmp=$(su - $USER -c "screen -ls" | awk -F . "/\.$SCREEN_NAME\t/ {print $1}" | awk '{print $1}')
  65. su - $USER -c "screen -r $tmp"
  66. else
  67. screen -r $(screen -ls | awk -F . "/\.$SCREEN_NAME\t/ {print $1}" | awk '{print $1}')
  68. fi
  69. }
  70.  
  71. function usage {
  72. echo "Usage: $0 {start|stop|status|restart|console}"
  73. echo "On console, press CTRL+A then D to stop the screen without stopping the server."
  74. }
  75.  
  76. case "$1" in
  77.  
  78. start)
  79. echo "Starting $SCREEN_NAME..."
  80. start
  81. sleep 5
  82. echo "$SCREEN_NAME started successfully"
  83. ;;
  84.  
  85. stop)
  86. echo "Stopping $SCREEN_NAME..."
  87. stop
  88. sleep 5
  89. echo "$SCREEN_NAME stopped successfully"
  90. ;;
  91.  
  92. restart)
  93. echo "Restarting $SCREEN_NAME..."
  94. status && stop
  95. sleep 10
  96. start
  97. sleep 5
  98. echo "$SCREEN_NAME restarted successfully"
  99. ;;
  100.  
  101. status)
  102. if status
  103. then echo "$SCREEN_NAME is UP"
  104. else echo "$SCREEN_NAME is DOWN"
  105. fi
  106. ;;
  107.  
  108. console)
  109. echo "Open console on $SCREEN_NAME..."
  110. console
  111. ;;
  112.  
  113. *)
  114. usage
  115. exit 1
  116. ;;
  117.  
  118. esac
  119.  
  120. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement