User:M3tal Warrior/Server Scripts
NOTE: This is a Debian Squeeze script which needs rsync and screen installed. I'd say it works on Ubuntu too, but haven't tested it.
- Version 1.31
- Fix: Vanilla download location (Mojang changed the way they provide updates - submitted by caboose684)
- Fix: Minor version issue with autoconf.sh which led to a security warning
- Version 1.3
- Added: Installer script for easy setup, reinstall & migration from pre-1.3 versions
- Added: autoconf.sh for automatic update of your init file
- Added: commandgrid.conf for a planned v1.4 feature (might contain spoilers ;))
- Added: updateurls.conf for easy (INTERNAL!) URL management - not user editable!
- Added: Strict separation of security critical server structure and data
- Added: binupdate option to update only the server binary (for users who have no root access)
- Changed: Standard updating process will now update your scripts as well
- Changed: Clearlog now gives out a daily log file
- Fix: Do command now works even if you don't tell the server what to do (Submitted by Ben Albon)
- Fix: Feedback now works with a 1 second delay to give the server time to write the logfile (Submitted by Ben Albon)
- Fix: The script should now always return the right state of the server (up/down)
- Version 1.20
- Added: Easy rollback function (see below)
- Added: Full Bukkit support
- Added: Stats for data processed during copy/saveback
- Added: Download location
- Changed: Splitted into two files (see below)
- Changed: Settings section (for easy overview)
- Changed: Commands are now independend of script version
- Changed: Direct command pipein with "do" (see below)
- Changed: Better timeout flexibility when shutting down etc.
- Fix: Invocating now works from every user with su rights
- Fix: "Give" works now smooth with damage ranges
- Fix: rsync issue
- Removed: Addons for Vanilla
- Copyright: Everything now GNU GPL, nothing left of other authors
- Known major issue (but not tested): On sytems with multiple non-sudoer users having access to the minecraft account it might be possible to gain root access by exploiting the maintenance file and restart the server with cron/startup. To prevent this issue, change its owner to root and chmod to 755.
- Known issue: without RAMFS enabled mc_feedback might not be able to display results due to hdd delay. (THX @ Ben Albon for submitting!)
- Known issue: 'do' does not work for commands longer than 6 words
- Known (minor) issue: Startup/restart may result in 'could not be started' despite startup is successful
- Version 1.10
- Modular construction
- Update check possible without server restart
- Backup now rsync
- Backup number decreased - only one backup per minute possible
- Commands "give" and "xp" work with unlimited amounts
- Command "give" is able to do damage value ranges
- ALPHA: Bukkit can be used, but isn't working well
- Known issue: Invocating from another user might fail
- Known issue: rsync might change ownership of files
- Known issue: "give" works a little odd with damage value ranges
From v1.3 on there is no use in posting an init script here, since it only contains the user defined settings, an installer/updater section and the invocation for the maintenance file.
To download it, look here.
Install/Update from pre-1.3 versions
Download mcinstall.sh, chmod it to executable and invocate it with a sudoer or root. It will guide you through every step of the installation progress, which are:
- Creating or choosing a minecraft user (for running the server)
- Downloading the scripts and configs
- Writing a new init script (for that it invocates autoconf.sh, where you get the possibility to either repair, install or update your init file with four levels of detail)
- Downloading the desired binary (Bukkit/Vanilla)
- Updating/installing everything & creating the directories
This explains every setting you find in the init file and/or will be asked during installation/update. This resembles the level of detail available during installation.
Those are set by mcinstall.sh, and there is no way in avoiding them
- The name of the server hosting user. Default is 'minecraft'.
- This tells the script if the user set in MCUSERNAME is able to do sudo actions. This determines lateron how update actions are proceeded in the final state. Default is 'no'.
- It is highly discouraged to give the minecraft user sudo rights!
If you choose 'Automatic update/install' during the process, all other options are set to default value and you don't get asked.
Those are asked by the autoconf.sh when choosing 'Standard update/install' or higher levels of detail.
- Here you have to provide the path to the maintenance script that will do all the work. You can store it where you like, preferably though is the home directory of the invocating user. Default is '/home/$MCUSERNAME'.
- The name of the maintenance script. Default name is 'server_control'.
- This is where your config files (apart from the maintenance script) are stored. Don't store them inside the server path, for the owner is root! Default path is '$MAINTAIN_SCRIPT_PATH/scriptconf'.
- This file is user editable, although doesn't serve any function yet. Default name is 'commandgrid.conf'.
- Determines which URLs are to use to download the scripts and server binaries - it will be overwritten if anything changes in here. Default name is 'updateurls.conf'.
- This script writes/updates the init file. Although not needed after the installation/update, the file is stored to fast-detect changes. Default name is 'autoconf.sh'.
- Choose what you want to use - BUKKIT or VANILLA (the capitals are important!). It not only affects the update but also the processing of some commands. Default setting is 'VANILLA'.
- The server binary. Default name is 'minecraft_server.jar'
- Defines the path to your server and files. This DOESN'T include the script config files, which are stored separately (see above). Default path is '$MAINTAIN_SCRIPT_PATH/server'
- Defines the path to your backup directory. Default path is '$MAINTAIN_SCRIPT_PATH/backup'
Those are asked by the autoconf.sh when choosing 'Advanced update/install' or the highest level of detail.
- Defines how many cores of your machine minecraft/java is allowed to use at the same time. autoconf.sh will detect how many cores are installed on your machine and gives you the choice. Default setting is '1'.
- Defines with how much RAM the JAVA VM will start. For Bukkit this might even need to be 1500MB, depending on the plugins used. Default is '500M'.
- Defines how much RAM the JAVA VM is allowed to use. Shouldn't be all your RAM though; default is '2G'.
- This way your server will be transferred to your RAM at startup and run out of your RAM. Therefore you have the advantage of a super fast server without delays due to HDD reading, but the great disadvantage of less RAM available for running processes and CERTAIN data loss when your server suffers a power loss or is shut down a wrong way.
- It is strongly recommended to use Cron for very frequent savebacks to your server directory on your HDD!
- Choose the frequency on the decision how much you want to redo in a worst case scenario, since rsync needs just one or two seconds to write back the data, but the more often you save, the more often your HDD has to be waked. 10 Minutes is good, but if your server is running 24/7 for years without problems, you can do it with the backup routine (which does a saveback prior to the backup).
- Invocation for Cron: "/etc/init.d/minecraft cronsave"
- Note that depending on your world size this might cause you to lose 2 GB and more RAM.
- To activate the option set the variable to 'yes'. Default setting is 'no'.
- Since some people use the RAM for working on documents (and other stuff) it is a good idea to create a unique directory in your RAM to separate the server from everything else. Choose a name you like or leave it be. Default directory name is 'minecraft'.
- This option is only used/asked when USERAMFS is set to 'yes'.
Only shown and asked if you wanted an 'Expert install/update', which is discouraged for 99%.
- You might render the JAVA VM options here. Default is only 'nogui'.
- For the JAVA nerds. If you have no clue what this means, leave it alone! Default is 'java -Xmx$MAX_SERVER_RAM -Xms$MIN_SERVER_RAM -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=$CPU_COUNT -XX:+AggressiveOpts -jar $SERVICE $JVM_OPTIONS'
You only need to alter them if you want to tweak your JVM. Most users should keep out here.
This is a list of all available invocations. All are invocated as /etc/init.d/<YOURINITNAME> <INVOCATION>
Naturally these commands are only available with the console, you can't escape the game and invocate the script with the provided chat utility.
- Shows the most important invocations.
- Starts the server
- Stops the server
- Restarts the server
- Checks the server status (up/down)
- Executes a command directly from the console (see the special for do)
- Updates server binary and script files (root access needed!)
- Updates only the server binary (no root access needed)
- This is only for people who have USE_RAMFS set to 'yes'. It writes the whole RAM directory back to the server directory.
- This will backup the whole directory provided by "SERVERPATH" to a directory named after the date and time of creation inside the provided "BACKUPPATH", including every settings file and the server jar, so you can rollback with a single invocation if things go rimwards. If you backup more than once a minute, the script will just update the existing folder.
Rolls back to a previous backup. This works as follows:
- rollback dir <directory>
- Will use provided directory to overwrite the server
- rollback last <number>
- Will browse through your backup directory and will use the latest (in case of not providing any number or providing 1) backup in there. By providing the number 2, you take the one before the latest backup and so on. Unreasonably high numbers will not cause the script to interfere or cry out, it will then just take the first backup ever made (since there's nothing before it).
- rollback sel
- Will show you the list of all available backups - you just type the one of your desire in.
- rollback undo
- You made a misstake and rolled some ancient stuff over your fancy new server? No problem - the script keeps a backup of the state of your server before you've done the rollback. But be careful: It only keeps one! One step back is no problem, two won't be possible (if you did not backup manually before).
- rollback help
- displays all the options and a brief description
Rollback is designed to be clever - and to prevent you doing anything wrong. Of course you are the admin, and thus able to hurt yourself, but the script will ask you at least before executing the rollback if you really want to do that.
For Cron there are separate invocations, since visual feedback is usually not very interesting for it. So these are mostly like the standard invocation, only with less (to no) feedback.
- See 'save' above.
- See 'backup' above.
- It rearranges your logfile and splits it into different files:
- This is the old server.log, without every line containing the following phrases:
- This is a server which checks for the minecraft server to be online. If you haven't announced your server in public, you won't recognize anything, if you have, you'll save yourself about 150 entries a day.
- Disabling level saving..
- If you have Cron running cronsave or cronbackup, you'd see that every time it runs in your original server.log
- CONSOLE: Forcing save..
- Same as above
- CONSOLE: Save complete.
- Same as above
- CONSOLE: Enabling level saving..
- Same as - Yeah, I know, it's a curse, that's why I remove them from the file.
- You may add a line of your own, just go to the mc_clearlog section in the script, copy one of the middle lines to the following and modify that.
- If your server is white-listed, every connection attempt that is rejected by the server is logged here.
- Contains every warning the server is printing to the server.log, and only those, except the warning about the server not being able to keep up. Useful for finding griefers who attempt to fly and so on...
If you like to use console commands, you just need to invocate the script with
/etc/init.d/minecraft do <desired console command>
There are only two major tweaks to them:
- You're now able to give your players almost any amount of things - the script will calculate how often it has to pipe the command to the server utilizing the maximum amount (64 for give on vanilla, 5000 for xp on both) per invocation. So giving 1000 stone or 1,000,000 experience to anybody with a single command won't be a problem any longer. NOTICE: Being very generous might crash your server and making whole chunks inaccessible. Be careful!
- GIVE - Damage value
- Since I'd like to give people sometimes a whole set of things (like maps or dyes) with a single command, I included a "damage value range". So if you provide a second damage value like
/etc/init.d/minecraft command give Player 358 1 0 24
- the script will give "Player" 25 maps, beginning with map_0 until map_24 (inclusive), one each. Combined with the ability to skip the amount limit, the script will now gently paste as much items of a single damage value as you've given the user, then repeating that with every other damage value in the row. Be careful, this leads to excessive amounts of entities on the server if used generously!
Since they're saver and I already have one or the other idea with those links, you might download the script(s) directly from my server:
Problems & Ideas
If you encounter some bugs or have some ideas to implement in here please let me know either on the bug & suggestions page or via Twitter. You may also follow me on Twitter to ask your questions, post me your ideas and get news first when a new version is about to hit the floor.