Sueta
MC

MCServers - Linux MC Server Management Service Script

1.23 March 3, 2017

Linux Service Script to Start, Stop, Update, and View console of MC Servers easily and Automatic!

·Script

The script originated from the year4000 script made by @ewizid.
https://github.com/Year4000/StartScript

However, with the current version of year4000 listed on their github, if your linux server has updated and made changes to start, restart, or status service commands, the script is nearly useless.
"service year4000 stop" would result in the linux server stopping the whole script and all servers. You couldn't tell it to stop just one server

With MCServers, I've fixed it, though with an additional command.
"service mcservers server stop 2/all" results in the server with the ID Number 2 to be stopped, or the choice of all, with visual information and countdown on screen and on the server announcement in sync.

Script should work on ALL versions of Minecraft.
Either that be the vanilla, snapshot, spigot, and maybe sponge and forge. Not heavily dependent on Minecraft versions.


Commands:

>>> All commands are ran from linux terminal as sudo! No console or ingame use! <<<
If you wish to run these commands from ingame, I suggest looking at wget plugin!

  • Server/Servers +
    • Start ID#/All
      • Start server ID or All servers. Ignores all servers that are already started or Enabled=false in servers.cfg. Requires # or All to run.
      • If the linux server is booting up, it will start all servers that are enabled. Same as though you've done "service mcservers server start all"
      • Example: service mcservers server start all
        • OVERRIDE
          • Will start any server, of choice or with all, with the SERVER_ENABLE=manual.
          • Servers with the manual variable will not auto-start, such as during a computer/system startup, but will start by command as long as OVERRIDE is listed at the end.
          • Note: Must Be Capitalized.
          • Example: service mcservers server start 3 OVERRIDE
    • Stop ID#/All
      • Stop server ID or All servers. Countdown on screen and on the server, then server shutdown. Requires # or All to run.
      • If the linux server is shutting down, it will stop all servers. Same as though you've don "service mcservers server stop all"
      • Example: service mcservers server stop all
    • Restart ID#/All
      • Restarts server ID or All servers. Stops the server as shown above, followed by a few seconds before Starting. Startup ignores servers with Enabled-false. Requires # or All to run.
      • Example: service mcservers server restart all
    • Status (ID#)
      • Shows the online/offline/disabled status of all servers. ID# can be stated for info on one server, but not needed.
      • Example: service mcservers server status
  • Update +
    • Spigot/Minecraft/Snapshot/Bungeecord/All +
      • If a URL for the specified update is set to "none," the update for related file(s) will be skipped.
      • Example: service mcservers update minecraft
      • Y/N
        • While updating anything, if you are wanting the update quick, or automated, adding "y" after what you want to update will skip the question. In turn, if you say "n" the update is skipped.
        • Example: service mcservers update Spigot/All y
      • Clean
        • While updating Spigot, only Spigot, setting the last variable to "clean" will delete all buildtools files, download buildtools, and run it. Starting fresh. Useful if having build issues.
        • Example 1: service mcservers update Spigot/All clean
        • Example 2: service mcservers update Spigot/All y clean
  • Screen ID# +
    • View the console/screen of choice server.
    • Example: service mcservers screen 0
    • Send
      • Any number of variables/words to send to select screen.
      • Example: service mcservers screen 0 send tell console this is a message from console, to console.
    • Kill
      • Kills select screen ID#
      • Example: service mcservers screen 0 kill
  • Edit/View FILE-OPTION ID#
    • View/Edit the Servers.cfg, as well as Server.Properties, Bukkit.yml, Spigot.yml, commands.yml, or log of choice server ID#. Can also be used to edit template versions.
    • Example: service mcservers edit server.properties 0
  • Create FILE-OPTION
    • Create a template file of server.properties, Bukkit.yml, Spigot.yml, and Commands.yml.
    • These templates are pre-coded into mcservers script and can be altered to output default templates of your liking.
    • Example: service mcservers create spigot.yml
  • Overwrite/Import FILE-OPTION ID#
    • Imports selected template into server choice.
      • It's wise to edit the template to your preferences before overwriting, such as bungee, max players, and port settings.
    • Example: service mcservers overwrite spigot.yml 0
  • Backup +
    • ID#
      • Backup server directory choice, displays the size of choice server.
      • Example: service mcservers backup 0
        • Y
          • If you place Y at the end, it will skip the question. Same with N, however nothing will be done.
      • I personally have the backups saving to a dropbox directory, which uploads them to my account. Couple things to keep in mind on this:
        • Datacap usage. Not just your server, but other computers that have the same folder allowed to by synced to them. Highly suggested to go to each computer linked to the dropbox account and deselect the folder which holds the backups. That way all backups are saved to the cloud, and not also to each computer unneedingly.
    • Clean ID# Xdays
      • Clean out backup directory by filtering out any backups exceeding X number of days of ID# Server.
      • Example: service mcservers backup clean 0 5
        • 0 = Server ID# and 5 = days old.
        • Y
          • If you place Y at the end, it will skip the question.

Features:

  • CTRL+C friendly at any moment of server script managing. NOT DURING SCREEN/CONSOLE ACCESS! If a mcservers command to start or shut down ran when CTRL+C is used, nothing is damaged. The server will continue to start or stop as normal. If a screen/console of a server refuses to shut down, View screen, CTRL+A, hit K, then Y for yes.
    • Spoiler

      Notice 3-12-16: I've noticed in Spigot since 1.9, killing a server with CTRL+A then K doesn't always kill the server. You will need a taskmanager program, such as TOP or HTOP to kill off the threads. Even then, it's weird. This is considered outside the script and not part of the script to be considered a bug that I can fix. However I am keeping an eye out for a possible solution around killing a server when it's entirely non-responsive.

  • Many help menus for sub-menus to help guide you. Much still under work as I have been adding, switching, and changing more than I would like to keep the help menus updated. The main help menu is up to date 99% of the time.
  • Countdown timer displays on server shutdowns.
  • Backup entire server directories. This idea came from minebackup, but not nearly as efficient.
    • The backup command will tell you the current size of the chosen server directory, and the size of the directory holding all the backups. Best not to let either get too large.
    • Has a clean option to clean out any backups exceeding X number of days old. "(sudo) service mcservers backup clean 0 5" would clean out any backups older than 5 days on 0 ID# server.
    • Announces to server, if online, of backup starting and complete, along with save-all, save-off, then once done, save-on. Note: A bit odd on Bungee, but harmless at this time.
    • Capable of skipping check questions for easier automated backups and cleans. Some Y/N questions can be skipped by add Y or N at the end of the command.
    • Planned Feature: Filter to skip certain files or directories upon backup, similar to minebackup.
  • Access to server screens/consoles are easily accessible through mcservers "(sudo) service mcservers screen ID#", otherwise "screen -x screenname" Which ever you prefer.
  • Terminal is color coded. Easier on the eyes and doesn't look bland. Future plans to allow users to customize the colors. Currently Green, LightGreen, Yellow, and Red are used.
    • Rough setup been added to mcservers file near the top. Alter at your own risk!!!
  • Many error checks and output messages for success or failures, such as missing files during server startup core file upgrade, or server core.jar missing after update, such as a failed download or buildtools.jar outputting a new spigot_version.jar file.
  • Script designed to start and stop all enabled servers upon linux system startup or shutdown. I cannot guarantee the servers will shut down safely and completely before the computer/system shuts down. Please monitor your mc servers shutdown time spand.
  • Customize server time of announcements per server. Such as Survival having 20 seconds of shutdown countdown warning, meaning 20 spam message ingame, while another server, such as bungeecord, has 5 seconds.
  • Each server group has variables to customize which server runs which server_core.jar copied from root directory.
  • Need certain commands ran before starting certain servers? Able to add in your own commands under Server_extras[serverIDvariable]=""
  • Instead of commenting out each server group you wish to disable, followed by changing the ID# at the beginning of each. Each server grouping as a Server_enabled variable to state if the server should be allowed to start. Default is True. Set to disabled and the server grouping will be skipped upon startup.
  • If the servers.cfg is none-existent, either first time running the service, the servers.cfg is deleted or renamed, a new one will be generated upon next mcservers command run. This is the only time the service script makes any changes to servers.cfg.
  • Creation of template files for use of easy server creation and setup with lease number of needed changes. Spigot.yml, bukkit.yml, commands.yml, and server.properties.
  • The script's update downloads the jars, while with spigot, it will download and run buildtools.jar. All server core.jar files will be saved to the root directory where servers.cfg is at.

servers.cfg

# Server Settings servers.cfg
BUNGEECORD_URL="http://ci.md-5.net/job/BungeeCord/lastBuild/artifact/bootstrap/target/BungeeCord.jar"  #Newest Builds of Bungeecord.jar. Type "none" if you do not wish to download this.
BUNGEECORD="BungeeCord.jar"  #Choice name of saved and displayed .jar
BUILDTOOLS_URL="https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar" #Newest Builds of Buildtools. Type "none" if you do not wish to download this.
BUILDTOOLS_BUILD_VERSION="--rev latest"  #Leave blank for current release version of MC. If specific build wanted, add: --rev 1.8, --rev 1.8.8, --rev latest.
BUILDTOOLS_SPIGOT="spigot-1.11.2.jar"  #Make sure this is the exact name of the spigot file output from BuildTools.jar.
BUILDTOOLS_OUTPUT="Spigot.jar"  #Choice name of buildtools.jar output to be renamed to when copied out of buildtools.
SPIGOT_LATEST="Spigot.jar"  #Choice name of saved and displayed .jar
MINECRAFT_SERVER_URL="https://s3.amazonaws.com/Minecraft.Download/versions/1.11.2/minecraft_server.1.11.2.jar"  #Choice version of minecraft_server.jar. Update URL when Mojang releases newer versions.  Type "none" if you do not wish to download this.
MINECRAFT_SERVER="Minecraft_Server.jar"  #Choice name of saved and displayed .jar
MINECRAFT_SNAPSHOT_URL="none"  #Choice version of minecraft__snapshot_server.jar. Update URL to your choice. Can be used for custom versions of MC/Forge/Sponge/etc.  Type "none" if you do not wish to download this.
MINECRAFT_SNAPSHOT="Minecraft_Snapshot_Server.jar"  #Choice name of saved and displayed .jar
MANUAL_BACKUPS_LOCATION="none"  #Choice of where backups are saved. Default: none = Disables Backup until directory is set.
SHOW_SCREENS="True"  #Do you want to show the screen listings after server Start, Stop, and Restarts?
## Survival Server Settings
#EXAMPLESURVIVAL=0  #Server Group Unique Name. Must be different than other server groups. Increment the ID# for each additional server listing. Best if you keep these in order.
#SERVER_ENABLED[$EXAMPLESURVIVAL]="true"  #Is this server allowed to start? If Yes, "true", otherwise "false." By Command Request: "manual" then service mcservers server start ID# OVERRIDE. Note: OVERRIDE must be capitalized!
#SERVER_NAME[$EXAMPLESURVIVAL]="Survival"  #Server Group Display/Screen Name. Can be anything.
#SERVER_PATH[$EXAMPLESURVIVAL]="Survival"  #Server root directory where the server_core.jar will be saved and executed? Directory must be in same location as this config.
#SERVER_CORE[$EXAMPLESURVIVAL]="Spigot.jar"  #Server Core .jar name to run off of. Good use if using custom .jar files separate from last Buildtools run.
#SERVER_EXTRAS[$EXAMPLESURVIVAL]="none"  #If none to place, place: "none". Ex: "rm /plugins/plugin/data.txt && command two"
#START_ARGS[$EXAMPLESURVIVAL]="java -server -Xmx1024M -XX:+UseConcMarkSweepGC -jar"  #Server starting arguments. Best only to change the -Xmx for memory use and server.jar at the end.
#SHUTDOWN_CMD[$EXAMPLESURVIVAL]="stop"  #Command used to tell the server, nicely, to shut down via screen/console.
#MSG_CMD[$EXAMPLESURVIVAL]="say"  #Command used to announce the SHUTDOWN_MSG1 and 2 prior to shutdown. Used for announced countdown.
#SHUTDOWN_MAX_WAIT[$EXAMPLESURVIVAL]=30  #How long to wait until server is shut down completely, before continueing on with the script. If server is down before the set number, the script exits.
#SHUTDOWN_SECONDS[$EXAMPLESURVIVAL]=20  #Number of seconds until MSG_CMD is used to shut down. Each second repeates the shutdown_msgs as the countdown decreases.
#SHUTDOWN_MSG1[$EXAMPLESURVIVAL]="&KD&rShutting down in "  #First half of the shutdown message, followed by the number of seconds remaining.
#SHUTDOWN_MSG2[$EXAMPLESURVIVAL]=" Seconds&KD&r."  #Second half of the shutdown message, after the number of seconds remaining.
# BungeeCord Server Settings
BUNGEE=0
SERVER_ENABLED[$BUNGEE]=false
SERVER_NAME[$BUNGEE]="BungeeCord"
SERVER_PATH[$BUNGEE]="BungeeCord"
SERVER_CORE[$BUNGEE]="BungeeCord.jar"
SERVER_EXTRAS[$BUNGEE]="none"
START_ARGS[$BUNGEE]="java -server -Xmx200M -XX:+UseConcMarkSweepGC -jar -DIReallyKnowWhatIaAmDoingISwear"
SHUTDOWN_CMD[$BUNGEE]="end"
MSG_CMD[$BUNGEE]="alert"
SHUTDOWN_MAX_WAIT[$BUNGEE]=30
SHUTDOWN_SECONDS[$BUNGEE]=5
SHUTDOWN_MSG1[$BUNGEE]="Bungee shutting down in "
SHUTDOWN_MSG2[$BUNGEE]=" Seconds."
# Spigot Survival Server Settings
SURVIVAL=0
SERVER_ENABLED[]=true
SERVER_NAME[$SURVIVAL]="Survival"
SERVER_PATH[$SURVIVAL]="Survival"
SERVER_CORE[$SURVIVAL]="Spigot.jar"
SERVER_EXTRAS[$SURVIVAL]="none"
START_ARGS[$SURVIVAL]="java -server -Xmx1024M -XX:+UseConcMarkSweepGC -jar"
SHUTDOWN_CMD[$SURVIVAL]="stop"
MSG_CMD[$SURVIVAL]="say"
SHUTDOWN_MAX_WAIT[$SURVIVAL]=30
SHUTDOWN_SECONDS[$SURVIVAL]=5
SHUTDOWN_MSG1[$SURVIVAL]="Survival shutting down in "
SHUTDOWN_MSG2[$SURVIVAL]=" Seconds."

Please note: There are more spaces in front of the commented text. ["code"] doesn't seem to like empty lines or multiple spaces...

Installation:

Similar projects

Script →