Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/sbin/runscript
- # User that should run the server
- USERNAME="minecraft"
- # Server name, used for folder name in locating everything on disk and for world location on ramdisk
- SERVERNAME='realm'
- # Root where all minecraft servers are stored
- MCROOT='/var/lib/minecraft'
- #List of MySQL databases to include in backups
- DATABASES='commandshops pex'
- #Remote console information. Required for proper saving!!
- RCONPORT='25575'
- RCONPASS='password'
- RCONEXEC='/opt/mcrcon'
- RCONCALL="${RCONEXEC} -s -H localhost -P ${RCONPORT} -p ${RCONPASS}"
- # Path to the main minecraft directory for this particular server
- MCBASE="${MCROOT}/${SERVERNAME}"
- # Folder containing actual server
- MCPATH="${MCBASE}/server"
- # Path to server.jar file
- SERVICE="${MCPATH}/craftbukkit.jar"
- CPU_COUNT=12
- # When deciding on ram limit remember to make room for the ramdisk
- INVOCATION="java -- -Xmx64G -Xms1G -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=$CPU_COUNT -XX:+AggressiveOpts -jar $SERVICE nogui"
- # Where the world backups should go
- BACKUPPATH="${MCBASE}/backups"
- # Where the logs are copied when running log-roll
- LOGPATH="${MCBASE}/logs"
- # Where the world is located on the disk
- WORLDSTORAGE="${MCPATH}/diskworld"
- #Path to the the mounted ramdisk default in ubuntu: /dev/shm
- RAMDISKROOT="/dev/shm"
- RAMDISKMC="${RAMDISKROOT}/minecraft"
- RAMDISK="${RAMDISKMC}/${SERVERNAME}"
- ME=`whoami`
- depend() {
- use net mysql
- }
- as_user() {
- if [ $ME == $USERNAME ] ; then
- bash -c "$1"
- else
- su - $USERNAME -c "$1"
- fi
- }
- datepath() {
- # datepath path filending-to-check returned-filending
- if [ -e $1`date +%x`$2 ]
- then
- echo $1`date +%FT%T`$3
- else
- echo $1`date +%F`$3
- fi
- }
- start() {
- ebegin "Starting minecraft server '$SERVERNAME'"
- einfo "Copying world to ram"
- as_user "mkdir $RAMDISKMC"
- as_user "mkdir $RAMDISK"
- chown -R $USERNAME:root $RAMDISK
- as_user "rsync -rtpg $WORLDSTORAGE/ $RAMDISK"
- einfo "World copied to ram. Starting Bukkit"
- cd $MCPATH
- start-stop-daemon --start --name $SERVERNAME --user $USERNAME --background --make-pidfile --pidfile /var/run/$SERVERNAME.pid --exec $INVOCATION
- eend $?
- }
- stop() {
- ebegin "Stopping minecraft server '$SERVERNAME'"
- $RCONCALL save-all
- $RCONCALL stop
- start-stop-daemon --stop --pidfile /var/run/$SERVERNAME.pid --name $SERVERNAME
- einfo "Copying world to disk"
- as_user "rsync -rt $RAMDISK/* $WORLDSTORAGE"
- eend $?
- }
- extra_commands="backup todisk logroll"
- backup() {
- todisk
- einfo "Backing up FS data"
- path=`datepath $BACKUPPATH/mine_`
- as_user "mkdir $path"
- as_user "cp -r $MCPATH $path/server"
- einfo "Backing up databases"
- as_user "mysqldump --no-create-db --no-create-info --no-tablespaces --databases $DATABASES >$path/databases.sql"
- einfo "Backup done."
- find $BACKUPPATH -maxdepth 1 -type d -mtime +30 -exec rm -r {} \;
- einfo "Old backups pruned."
- }
- todisk() {
- $RCONCALL save-all
- as_user "rsync -rt $RAMDISK/* $WORLDSTORAGE"
- einfo "Worlds saved to disk."
- }
- logroll() {
- # Moves and Gzips the logfile, a big log file slows down the
- # server ALOT (what was notch thinking?)
- path=`datepath $LOGPATH/server_ .log.gz .log`
- as_user "cp $MCPATH/server.log $path && gzip $path"
- as_user "truncate $MCPATH/server.log --size 0"
- einfo "Log rotated."
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement