Advertisement
zolcos

minecraft

May 25th, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.34 KB | None | 0 0
  1. #!/sbin/runscript
  2.  
  3. # User that should run the server
  4. USERNAME="minecraft"
  5.  
  6. # Server name, used for folder name in locating everything on disk and for world location on ramdisk
  7. SERVERNAME='realm'
  8.  
  9. # Root where all minecraft servers are stored
  10. MCROOT='/var/lib/minecraft'
  11.  
  12. #List of MySQL databases to include in backups
  13. DATABASES='commandshops pex'
  14.  
  15. #Remote console information. Required for proper saving!!
  16. RCONPORT='25575'
  17. RCONPASS='password'
  18. RCONEXEC='/opt/mcrcon'
  19. RCONCALL="${RCONEXEC} -s -H localhost -P ${RCONPORT} -p ${RCONPASS}"
  20.  
  21. # Path to the main minecraft directory for this particular server
  22. MCBASE="${MCROOT}/${SERVERNAME}"
  23. # Folder containing actual server
  24. MCPATH="${MCBASE}/server"
  25. # Path to server.jar file
  26. SERVICE="${MCPATH}/craftbukkit.jar"
  27. CPU_COUNT=12
  28. # When deciding on ram limit remember to make room for the ramdisk
  29. INVOCATION="java -- -Xmx64G -Xms1G -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=$CPU_COUNT -XX:+AggressiveOpts -jar $SERVICE nogui"
  30. # Where the world backups should go
  31. BACKUPPATH="${MCBASE}/backups"
  32. # Where the logs are copied when running log-roll
  33. LOGPATH="${MCBASE}/logs"
  34. # Where the world is located on the disk
  35. WORLDSTORAGE="${MCPATH}/diskworld"
  36. #Path to the the mounted ramdisk default in ubuntu: /dev/shm
  37. RAMDISKROOT="/dev/shm"
  38. RAMDISKMC="${RAMDISKROOT}/minecraft"
  39. RAMDISK="${RAMDISKMC}/${SERVERNAME}"
  40.  
  41. ME=`whoami`
  42.  
  43. depend() {
  44.   use net mysql
  45. }
  46.  
  47. as_user() {
  48.     if [ $ME == $USERNAME ] ; then
  49.         bash -c "$1"
  50.     else
  51.         su - $USERNAME -c "$1"
  52.     fi
  53. }
  54.  
  55. datepath() {
  56.     # datepath path filending-to-check returned-filending
  57.     if [ -e $1`date +%x`$2 ]
  58.     then
  59.         echo $1`date +%FT%T`$3
  60.     else
  61.         echo $1`date +%F`$3
  62.     fi
  63. }
  64.  
  65. start() {
  66.     ebegin "Starting minecraft server '$SERVERNAME'"
  67.     einfo "Copying world to ram"
  68.     as_user "mkdir $RAMDISKMC"
  69.     as_user "mkdir $RAMDISK"
  70.     chown -R $USERNAME:root $RAMDISK
  71.     as_user "rsync -rtpg $WORLDSTORAGE/ $RAMDISK"
  72.     einfo "World copied to ram. Starting Bukkit"
  73.     cd $MCPATH
  74.     start-stop-daemon --start --name $SERVERNAME --user $USERNAME --background --make-pidfile --pidfile /var/run/$SERVERNAME.pid --exec $INVOCATION
  75.     eend $?
  76. }
  77.  
  78. stop() {
  79.     ebegin "Stopping minecraft server '$SERVERNAME'"
  80.     $RCONCALL save-all
  81.     $RCONCALL stop
  82.     start-stop-daemon --stop --pidfile /var/run/$SERVERNAME.pid --name $SERVERNAME
  83.     einfo "Copying world to disk"
  84.     as_user "rsync -rt $RAMDISK/* $WORLDSTORAGE"
  85.     eend $?
  86. }
  87.  
  88. extra_commands="backup todisk logroll"
  89.  
  90. backup() {
  91.     todisk
  92.         einfo "Backing up FS data"
  93.         path=`datepath $BACKUPPATH/mine_`
  94.         as_user "mkdir $path"
  95.         as_user "cp -r $MCPATH $path/server"
  96.         einfo "Backing up databases"
  97.         as_user "mysqldump --no-create-db --no-create-info --no-tablespaces --databases $DATABASES >$path/databases.sql"
  98.         einfo "Backup done."
  99.         find $BACKUPPATH -maxdepth 1 -type d -mtime +30 -exec rm -r {} \;
  100.     einfo "Old backups pruned."
  101. }
  102.  
  103. todisk() {
  104.     $RCONCALL save-all
  105.     as_user "rsync -rt $RAMDISK/* $WORLDSTORAGE"
  106.     einfo "Worlds saved to disk."
  107. }
  108.  
  109. logroll() {
  110.     # Moves and Gzips the logfile, a big log file slows down the
  111.     # server ALOT (what was notch thinking?)
  112.         path=`datepath $LOGPATH/server_ .log.gz .log`
  113.         as_user "cp $MCPATH/server.log $path && gzip $path"
  114.         as_user "truncate $MCPATH/server.log --size 0"
  115.     einfo "Log rotated."
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement