Advertisement
skaviouz

gameserver

Apr 30th, 2015
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. #!/bin/bash
  2. # /etc/init.d/gameserver
  3. # version 0.1b 9MAR2015
  4.  
  5. ### BEGIN INIT INFO
  6. # Provides: gameserver
  7. # Required-Start: $local_fs $remote_fs
  8. # Required-Stop: $local_fs $remote_fs
  9. # Should-Start: $network
  10. # Should-Stop: $network
  11. # Default-Start: 2 3 4 5
  12. # Default-Stop: 0 1 6
  13. # Short-Description: CustomGameServer
  14. # Description: Starts the custom game server
  15. ### END INIT INFO
  16.  
  17. #Settings
  18. JARFILE='cauldron-1.7.10-1.1307.06.218-server.jar'
  19. USERNAME="minecraft"
  20. GAMESTORE="/var/www/html/game"
  21. GAMEPATH="/dev/shm/game"
  22. BACKUPPATH="/var/www/html/game_backup"
  23.  
  24. CPU_COUNT=1
  25. INVOCATION="java -Xmx3072M -Xms3072M -server -jar $JARFILE -o false"
  26. WORLD=rr3world
  27.  
  28. #DONT EDIT BELOW THIS LINE
  29.  
  30. #SPECIAL CHARACTER CODES
  31. ENTER="`echo -ne '\015'`"
  32.  
  33. to_screen() {
  34. #TO_SCREEN="screen -p 0 -S gameserver -X eval 'stuff "
  35. screen -S gameserver -p 0 -X stuff "$1"
  36. }
  37.  
  38. to_screenNL() {
  39. #TO_SCREEN="screen -p 0 -S gameserver -X eval 'stuff "
  40. screen -S gameserver -p 0 -X stuff "$1$ENTER"
  41. }
  42.  
  43. game_status() {
  44. ps aux |grep -F -v grep|grep -F -v SCREEN|grep -F --quiet $JARFILE
  45. return $?
  46. }
  47.  
  48. game_start() {
  49. if [ -d $GAMESTORE/$WORLD.bak ]; then
  50. echo "last $WORLD.bak still exist, crashed warning! manual check required!!!"
  51. exit 1
  52. fi
  53. cd $MCPATH
  54. if [ ! -f "$GAMEPATH/$JARFILE" ]; then
  55. mkdir /dev/shm/game
  56. cp -R $GAMESTORE/* $GAMEPATH/
  57. chmod -R 777 $GAMEPATH
  58. fi
  59. to_screenNL "exit"
  60. screen -dmS gameserver
  61. to_screenNL "cd $GAMEPATH"
  62. to_screenNL "$INVOCATION"
  63. sleep 7
  64. if game_status; then
  65. echo "$JARFILE : running."
  66. else
  67. echo "Could not start : $JARFILE?"
  68. sleep 13
  69. if game_status; then
  70. echo "$JARFILE : running finally."
  71. else
  72. echo "Could not start : $JARFILE after waiting 20 seconds"
  73. fi
  74. fi
  75.  
  76. }
  77.  
  78. game_stop() {
  79. echo "...prepare to be stopped"
  80. to_screenNL "say SERVER SHUTTING DOWN IN 5 SECONDS. SAVING"
  81. to_screenNL "save-all"
  82. echo "... 35 seconds left - save complete"
  83. sleep 5
  84. to_screenNL "stop"
  85. echo "... 20 seconds left - sent stop command"
  86. sleep 10
  87. to_screenNL "exit"
  88. echo "... 10 seconds left - sent exit command for terminal"
  89. sleep 10
  90. }
  91.  
  92.  
  93. #Start-Stop here
  94. case "$1" in
  95. status)
  96. if game_status; then
  97. echo "$JARFILE is running."
  98. else
  99. echo "$JARFILE is not running."
  100. fi
  101. ;;
  102. start)
  103. if game_status; then
  104. echo "$JARFILE was already running"
  105. else
  106. game_start
  107. fi
  108. ;;
  109. stop)
  110. if game_status; then
  111. echo "$JARFILE is running..."
  112. game_stop
  113. if game_status; then
  114. echo "$JARFILE could not be shut down... check in 20 seconds?"
  115. sleep 20
  116. if game_status; then
  117. echo "$JARFILE could not be shut down... restart system?"
  118. else
  119. echo "$JARFILE finally shut down... lots of lag? upgrade your system."
  120. fi
  121. else
  122. echo "$JARFILE is shut down."
  123. fi
  124. else
  125. echo "$JARFILE was already not running."
  126. fi
  127. ;;
  128. exek)
  129. echo "exec - $2"
  130. $2
  131. ;;
  132. help)
  133. echo " start - start server"
  134. echo " stop - stop server"
  135. echo " status - if server running or not"
  136. echo " check - if ramdisk game directory empty or not"
  137. echo " build - copy game-folder from STORE to SHM"
  138. echo " stabalize - delete STORE_1"
  139. echo " rename STORE to STORE_1"
  140. echo " MOVE game-folder from SHM to STORE"
  141. echo " fsave - force save"
  142. echo " command - send command to server"
  143. echo " exec - use only for advanced debugging"
  144. ;;
  145. *)
  146. echo "Usage: /etc/init.d/gameserver {help|start|stop|status|check|build|stabalize|fsave|command|exec}"
  147. exit 1
  148. ;;
  149. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement