Advertisement
masa-

minecraft_server_jomb.sh (2018-10-13)

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