Home›Java›Mods›MCServers - Linux MC Server Management Service Script
ModsJava

MCServers - Linux MC Server Management Service Script

⬇ Download on Spigot
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.
Click to expand...
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.
Click to expand...
servers.cfg
Code (Text):

# 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."
 
Click to expand...
Please note: There are more spaces in front of the commented text. ["code"] doesn't seem to like empty lines or multiple spaces...

Installation:
  1. If not already made, create a user for minecraft servers to be ran under. If you are using your own, ignore this step.
    1. Run: sudo adduser minecraft.
      1. Replace "minecraft" with what ever name you want. No need to make the user a root/sudo user.
  2. Copy the mcservers file to /etc/init.d.
    1. Run: cd /etc/init.d
    2. Run: sudo touch mcservers
    3. Run: sudo nano mcservers
    4. Copy contents of mcservers file downloaded, to the created mcservers file on the server.
    5. Edit line: IfRootDefaultUserDirectory="minecraft"
      • Replace minecraft with the username you chose during step 1
    6. Edit line: MINECRAFT_DIRECTORY="MCServers"
      • Replace MCServers to what sub folder you want your Minecraft servers under. Example: /home/minecraft/MCServers, minecraft being the username/home folder.
    7. When all changes are done, press CTRL+X, Press Y, then Enter.
  3. Make the script executable: (sudo) chmod +x mcservers
  4. Initial run.
    • Run "(sudo) service mcservers" and it will generate the servers.cfg file for you in the server_settings set directory. The service will then list the Help menu.
    • If successful, no errors. Should be all colored text.
  5. Update servers.cfg.
    • Then either "(sudo) service mcservers edit servers.cfg" and edit with your preferred editor (VIM, NANO, etc.), or through FTP (Notepad++). NO TABS! 4 spaces for indentions!
    • Make sure that all the server files you want (Buildtools, Minecraft, snapshot, bungeecord) have their respective URLs or set to "none" to be disabled during updates.
    • Each server has it's own grouping of variables. Survival server is commented with details of each variable. First line refers to it's ID#, which is shown with "service mcservers server status".
    • Make sure the Server_Path refers to the directory name of the server, found in the same directory as servers.cfg.
  6. Update server core files.
    • Run "(sudo) service mcservers update all", or a single choice, to be created/updated. These files will be copied into their respective server directories upon startup.
    • If you don't want updated server.jar files, but custom/unique/old jar files, rename the jar file you want to keep, then update servers.cfg to reflect that name. You may/will get an error about unable to copy the file because it doesn't exist, you are perfectly fine, only because your file doesn't exist in update directory.
  7. Start servers.
    • Start one or all servers: "(sudo) service mcservers start all" or replace All with the ID# of which server you'd wish to start.
    • If an error appears about unable to stat a file, the update step was either skipped or failed. Refer to step 6 above, second bullet. If this is not your intention, please check your settings.
  8. Status Check.
    • After a few moments, check the status of the servers for any issues.
    • Either this be with "(sudo) service mcservers status", "(sudo) service mcservers view log ID#" or open the screen/console with "(sudo) service mcservers screen ID#."
    • If the server is fresh and new, you may need to alter your eula.txt to agree to the terms of Mojang/Minecraft. "(sudo) service mcservers edit eula ID#" If you agree, change the "false" to "true", save (CTRL+X then hit Y), then start the server again.
  9. (*OPTIONAL*) Want to make the script to start ENABLED servers at computer/system startup? And stop all servers on shutdown?
    • We need to make the script auto run at startup: "sudo update-rc.d mcservers defaults"
Click to expand...
If you find any issues or have any questions, please let me know!

Source Code

Todo:
  • Need better line spaces in some areas. Some functions and messages should not be next to each other.
  • Fix information output for backup command.
  • Add in automated backups, similar to MineBackup. Including Dropbox support. Not going to implement, made it easier to setup and run in cron jobs. Y/N Question friendly by adding y at the end of the command!
  • Condense some redundancies in some areas. Much has been reduced during coding in the last week, but I'm certain I can reduce a little bit more here and there.
  • Fix/Add in more help menus. Start and Stop without an ID#/All currently doesn't do anything.
  • Should file editing be done by Nano, or VIM? Or should I make this an option script/config? Currently set with NANO.
  • Add in a function to allow users to customize their color scheme, or disable it? Currently only Lightgreen, Green, Yellow, and Red text. Editable in the mcservers file, but not much explanation currently. Edit at your own risk!!!
  • Should I bother adding in a language file for translations? I'm not highly interested, but shouldn't be too hard to implement. I'll announce when this is added and ready for translators. Pig-laten be first maybe?
  • Add in functions to create/remove servers groups in servers.cfg.
  • Add in ways to change variables of servers in servers.cfg. Currently users must manually change the file directly. Either by SSH/NANO or FTP.
  • Add in function to kill a server if normal means do not work. Until then, "(sudo) service mcservers screen ID#" and CTRL+A, then K, then Y. Simple addition, didn't add it in yet. Not a high priority at this time, but is very useful. TIP: If can't start server after killing? (sudo) htop (or top), select the server's java threads, then kill them.
  • With as much code I have added, I've tried to make sure all needed error-checks are in place. Every now and then I find an issue with the code for possible errors or exploits. This is an ongoing task and I will do what I need to improve the script.
  • Implement a way for "update spigot" which runs buildtools to scan and copy the spigot file without the user needing to update servers.cfg with the new spigot_version.jar for every MC release. Will not do as "forcing" users to upgrade when not ready is not a wise idea. Idea came from people being forced to Windows 10 by microsoft, and it's just plain not ethical.
  • Bug found 11-6-15: If you have two servers, one named Survival and another VanillaSurvival, Survival will not start because it's seen as "running/active" because Survival is found in VanillaSurvival. Need to find a way to prevent this. For now, don't use unique server names in each server group. May tag server ID at the end of the name.
  • Move the config creation back to it's own function. I switched from Debian to Ubuntu and started having the same results as other people reporting. No config creation. Issue is fixed in a lazy way currently.
Click to expand...
Considering how much I've added and changed, I've still got a lot of ideas.

This is my first release of coding of any kind. It may not be java or C/C++, however I'm proud of myself to have achieved my first step in publicly usable coding that wasn't assigned in some way through school. Once this project has plateaued as being stable and containing all needed feature, at least by the majority, I do have another project in mind for plugin creation, obviously in java.
Quick facts

Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.

MCServers - Linux MC Server Management Service Script is a free Minecraft Java mod. Compatible with Minecraft 1.7, 1.8, 1.9, 1.10 and newer. Downloaded 1,800 times (via Spigot). Download it and open it directly in the game.

Explore more