Advertisement
masa-

Minecraft server script - per-server part

Aug 16th, 2017
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.85 KB | None | 0 0
  1. #!/bin/bash
  2. # version x.x.x 2013-11-14 (YYYY-MM-DD)
  3.  
  4. #########################
  5. #       Settings        #
  6. #########################
  7. INSTANCE='jomb'     # Server instance name (used in several places, such as the path, the server process (file)name, etc.)
  8. WORLD_NAME='world'  # World directory name
  9. HOST="localhost"    # Host address used for pinging the server
  10. PORT="25565"        # Server port, used when running the check_ping command
  11.  
  12. ALLOW_UPDATES='false'           # Allow upgrading the server version using the mc_update() function?
  13. ALLOW_DOWNGRADES='false'        # Allow downgrading the server version using the mc_update() function?
  14. DISABLE_AUTOSAVE='false'        # Run the save-off command after start?
  15. USE_TEMP_LOCATION='true'        # Copy the world to /tmp when starting, and back on stop
  16.  
  17. SCREEN_SESSION="mc_${INSTANCE}" # The screen session name that will be used for this server instance
  18. BACKUP_PREFIX="${INSTANCE}"     # filename prefix (<prefix>_YYYY-mm-dd_HH.MM.SS.tar.gz)
  19. BACKUP_SERVICE='false'          # backup the server file (jar)?
  20. BACKUP_USING_TAR='false'        # Create a tarball of the server instance (or the world)?
  21. BACKUP_USING_GIT='true'         # Create backups using git?
  22.                                 # NOTE: You have to run git init manually in the instance path (or the world path) before first backup
  23.                                 # NOTE 2: There must NOT be a world-only git repo under the world directory when doing
  24.                                 # full-server backups using git! Otherwise the world directory will not get backed up!
  25.  
  26. BACKUP_WORLD_ONLY='false'       # Back up only the world directory, not the full server instance?
  27.  
  28. #########################
  29. #       Paths           #
  30. #########################
  31. BASE_PATH="/data/game_servers/minecraft"
  32. INSTANCE_PATH="${BASE_PATH}/servers/${INSTANCE}"
  33.  
  34. WORLD_PATH_REAL="${INSTANCE_PATH}/${WORLD_NAME}"
  35. WORLD_PATH_SYMLINK="${INSTANCE_PATH}/${WORLD_NAME}_symlink"
  36.  
  37. INSTANCE_PATH_TMP="/tmp/minecraft/${INSTANCE}"
  38. WORLD_PATH_TMP="${INSTANCE_PATH_TMP}/${WORLD_NAME}"
  39.  
  40. SERVICE="minecraft_server_${INSTANCE}.jar"  # Server filename (symlink filename) in the INSTANCE directory
  41.  
  42. BACKUP_PATH="/mnt/640_jemma/mc_backups/${INSTANCE}"
  43. STATE_FILE="/tmp/mc_server_${INSTANCE}_running.txt"
  44. EVENT_LOG_FILE="${BASE_PATH}/event_logs/${INSTANCE}_events.log"
  45. BACKUP_LOG_FILE="${BASE_PATH}/event_logs/${INSTANCE}_backups.log"
  46.  
  47. COMMON_FUNCTIONS_SCRIPT="${BASE_PATH}/scripts/mc_common_functions.sh"
  48. PING_SCRIPT="${BASE_PATH}/scripts/ping.py"
  49. PING_INVOCATION="python ${PING_SCRIPT} ${HOST} ${PORT} 1.6 2" # host, port, timeout, protocol [1|2|3]
  50.  
  51. # Update related things (mc_update()):
  52. SERVER_FILES_PATH="/data/minecraft/server"  # Path where all the server jar files are saved (used when running mc_update())
  53. SERVER_FILE_PREFIX="minecraft_server_"      # Filename prefix used for the server files in SERVER_FILES_PATH directory
  54. VERSIONS_JSON="/tmp/minecraft_versions.json" # The path where the version json is saved, used for upgrades/downgrades
  55.  
  56. # Server process invocation and JVM arguments:
  57. #OPTIONS='nogui --log-strip-color'  # Spigot/Bukkit
  58. OPTIONS='nogui'
  59. USERNAME='masa'
  60. CPU_COUNT=2
  61.  
  62. #JVM_OPTS="-XX:+UseConcMarkSweepGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=${CPU_COUNT} -XX:+AggressiveOpts"
  63. JVM_OPTS="-XX:+UseConcMarkSweepGC"
  64. JVM_MEM_OPTS="-Xms1024M -Xmx2048M"
  65. INVOCATION="java ${JVM_MEM_OPTS} ${JVM_OPTS} -Dlog4j.configurationFile=log4j2.xml -jar ${SERVICE} ${OPTIONS}"
  66.  
  67. #########################
  68. #       Delays          #
  69. #########################
  70.  
  71. POST_START_DELAY=1      # Delay after the command, before entering the check loop
  72. START_GRACE_DELAY=10    # How many times to loop/how long to wait for the server to come up
  73.  
  74. START_TO_DISABLE_AUTOSAVE_DELAY=5   # Delay after server start before issuing the save-off command (if DISABLE_AUTOSAVE='true')
  75.  
  76. POST_STOP_DELAY=1       # Delay after the command, before entering the check loop
  77. STOP_GRACE_DELAY=10     # How many times to loop/how long to wait for the server to shut down
  78.  
  79. POST_SAVEALL_DELAY=3    # How long to wait after a save-all command before continuing
  80. SAVEALL_BACKUP_INTERVAL=5   # How long to wait after doing a save-all, before starting the backup
  81.  
  82. RESTART_FIRST_WARNING=5 # Broadcast a warning message on the server and wait this long before restarting
  83. RESTART_LAST_WARNING=2  # The second and last warning is broadcast this long before restarting
  84.  
  85. SAVEALL_STOP_INTERVAL=3 # How long to wait after the save-all command, before the stop command
  86.  
  87. POST_KILL_DELAY=5       # How long to wait after issuing the kill signal, before entering the check loop
  88. KILL_GRACE_DELAY=10     # How many times to loop/how long to wait for the server to die, before throwing an error
  89.  
  90. PING_RETRY_DELAY=10     # How long to wait before ping commands
  91. PING_RETRY_COUNT=3      # How many times to try the ping, before killing and restarting the server
  92. KILL_TO_START_DELAY=10  # How long to wait after killing the server and before restarting it
  93.  
  94. #########################
  95. #### End of settings ####
  96. #########################
  97.  
  98. source ${COMMON_FUNCTIONS_SCRIPT}
  99.  
  100.  
  101. # Process the commands
  102. case "${1}" in
  103.     start)
  104.         mc_start
  105.         ;;
  106.     stop)
  107.         mc_stop
  108.         ;;
  109.     restart)
  110.         mc_restart ${2} ${3}
  111.         ;;
  112.     restartifup)
  113.         mc_restart_if_up ${2} ${3}
  114.         ;;
  115.     check)
  116.         mc_startifcrashed_basic
  117.         ;;
  118.     check_ping)
  119.         mc_startifcrashed_ping
  120.         ;;
  121.     backup)
  122.         mc_backup_wrapper
  123.         ;;
  124.     saveoff)
  125.         mc_saveoff
  126.         ;;
  127.     saveon)
  128.         mc_saveon
  129.         ;;
  130.     saveall)
  131.         mc_saveall
  132.         ;;
  133.     kill)
  134.         mc_kill
  135.         ;;
  136.     update)
  137.         mc_update "${2}"
  138.         ;;
  139.     say)
  140.         mc_say "${2}"
  141.         ;;
  142.     status)
  143.         L_TIMESTAMP=`date "+%Y-%m-%d %H:%M:%S"`
  144.         L_PREFIX="[${L_TIMESTAMP}]"
  145.  
  146.         if pgrep -u ${USERNAME} -f ${SERVICE} > /dev/null
  147.         then
  148.             echo "${L_PREFIX} [INFO] ${SERVICE} is running"
  149.         else
  150.             echo "${L_PREFIX} [INFO] ${SERVICE} is not running"
  151.         fi
  152.         ;;
  153.     command)
  154.         mc_command "${2}"
  155.         ;;
  156.  
  157.     *)
  158.         echo "Usage: /etc/init.d/minecraft {start|stop|restart|restartifup|check|check_ping|backup|saveoff|saveon|saveall|kill|update|say|status|command \"server command\"}"
  159.         exit 1
  160.         ;;
  161. esac
  162.  
  163. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement