README: Bash Scripts
--------------------

These scripts were developed for use with the "Minecraft Is Too Easy" mod. Place all of these scripts into the same directory as your minecraft server jar file.

***

Here is an explanation what each script does:

run.command: This runs the server as a foreground process, it is recommended that you use run_nohup.command instead.

run_nohup.command: This runs the server as a background process. This allows the server to continue running after you close your terminal session or it becomes inactive.

pid: This displays the process id (PID) of the server. Use this to see if the process is running. Also called by the other scripts.

stop.command: Stops the server, giving it a chance to shutdown gracefully. Players are given 20 seconds notice before shutdown occurs.

kill: Stops the server almost immediately while still giving it a chance to shutdown gracefully. Players are not notified of shutdown before it occurs.

backup.command: Stops the server gracefully and copies the current world to a tar.gz. Players are given 20 seconds notice before shutdown occurs. Restarts the server automatically if it was previously running.

upload.command: Uploads the world backup archive created by backup.command to a remote ftp server that you specify (you will need to edit the file). Uploading the world backups to another server is a good idea if you're using an EC2 Spot Instance because it could terminate at any time, depending on current bid prices. Another option is to create a permanent EBS volume and attach it to the instance (see instructions near the bottom of this file). You can also specify a single file as an argument to this script and it will upload it to the destination server.

update.command: If you want to update your server jar then place the new version of it in the same directory as the current server jar with ".new" appended to its filename, then run this script. This script will shut the server down gracefully, apply the update (overwrite the old jar with the new one) and restart the server if it was previously running.

world.name: Called by the other scripts, you don't need to worry about it.

log: Called by the other scripts, you don't need to worry about it.

***

In the interest of preserving your multiplayer world it is recommended that you run backup.command and upload.command as cron jobs, scheduled once per day.

To add cron jobs for these two scripts change to root user and type "crontab -e". Paste in the following two lines:

0 8 * * * /home/ec2-user/backup.command >/dev/null 2>&1
0 9 * * * /home/ec2-user/upload.command >/dev/null 2>&1

Adjust the paths so that they are correct for you server. In this example, backup.command will be run at 8AM and upload.command at 9AM (every day).

Alternatively, you can specify the -u option for backup.command and it will upload the world archive immediately after it has been created. In this case the backup and upload tasks are accomplished by a single cron job (instead of the two above):

0 8 * * * /home/ec2-user/backup.command -u >/dev/null 2>&1

You can type "crontab -l" to view the current list of user-defined cron jobs.

***

Common steps to take after creating a new EC2 Instance:
1. sudo -s
2. yum update (optional)
3. yum install ftp
4. Edit custom fields in upload.command
5. Adjust memory allocation in run.command and run_nohup.command, if desired
6. Configure cron jobs for backup and upload

Attaching and Mounting an EBS Volume to a Running Instance:
1. Use EC2 web interface to attach volume to instance
2. sudo -s
3. Type lsblk to find the name of the device that was attached in step 1
4. Format device (ONLY IF REQUIRED) by typing mkfs -t ext4 <device name>, for example: mkfs -t ext4 /dev/xvdf
5. mkdir /mnt
6. mount <device name> /mnt, for example: mount /dev/xvdf /mnt