FreeBSD rc.d script for craftbukkit

Discussion in 'Bukkit Tools' started by shadowen, Sep 5, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    shadowen

    Hey everyone,
    I run craftbukkit from a FreeBSD server and thought I'd share an rc.d script I put together to handle starting, stopping and pulling status from a running craftbukkit server. The script itself is setup to handle running multiple craftbukkit servers from the same machine via simple rc.conf configuration and manages them using tmux sessions (preferred over screen as screen has issues inside of jails).

    You'll note throughout the rc.d/minecraft script I reference a user - minecraftsvc. This is just a low privilege user I setup to run the minecraft/craftbukkit services under. You can change this to whatever user you'd like (at some point I may change this to a variable to help with that, for not just find/replace).

    Right now its still somewhat basic, but it may help ease some administration for those of you running FreeBSD.
    UPDATE: Major re-work to the rc.d script. I've added code for the following features:
    1. backup command to allow for setting easy cron-based backups.
    2. tmpfs support! You can now run you servers on a tmpfs partition which allows for excellent performance. I run my primary server on a 1GB tmpfs partition (basically 1GB of RAM set aside for this partition). The support in the script, along with a couple of simple cronjobs, manages syncing the tmpfs partition back to your HDD (as tmpfs is in memory, if you shutdown without syncing you'll lose everything). The syncing is done on an interval and at shutdown. You may use multiple servers on one tmpfs partition, however this is untested.
    3. Other fixes/minor mods that I cant think of.

    Prerequisites:
    Code:
    tmux -- screen-like terminal multiplexer - jail friendly
    java -- required for craftbukkit
    rsync -- used for tmpfs support.  If you don't want to use the tmpfs stuff, just remove the check for rsync at the top of the script.
    
    Directories and Files you need to know about (some of these are my layouts - yours may differ):
    Code:
    /etc/rc.conf -- system rc.d configuration stored here (including the below listed settings)
    /usr/local/etc/rc.d -- third party rc.d scripts - the minecraft rc.d script should go here
    /usr/local/etc/rc.d/minecraft -- the rc.d script I wrote for managing craftbukkit server instances
    /usr/local/craftbukkit/servers/xxx/startServer.sh -- simple startup script to get each server instance running - should only contain the java command and any parameters; I'll attach an example
    /usr/local/craftbukkit/md -- where I happen to have my tmpfs partition mounted; each server run under tmpfs is given its own sub-directory here.
    
    Here is the basic outline of the configuration settings for rc.conf:
    Code:
    minecraft_enable  -- YES or NO - allows the start/stop of minecraft via the rc.d script
    minecraft_instpath -- <path to top level servers directory> - set this to the top level of where your server instances exist; in my case its /usr/local/craftbukkit/servers (this is also the default if not set)
    minecraft_startscript -- <name of craftbukkit startup script> - set this to the name of the startup script you use to get each craftbukkit instance going - mine is startServer.sh - each server instance will require there own
    minecraft_instlist -- <name of server instances> - space separated list of server instance names, needs to map to sub directories under minecraft_instpath
    minecraft_backuppath -- <location to place server backups> - base directory where tar/gzip backups of your minecraft servers should go
    minecraft_ramdisk -- <location of tmpfs partition mount> - where is the memory file system is mounted for use.
    minecraft_ramdisk_<worldname> -- YES or NO - is <worldname> suppose to be run off of the tmpfs partition configured in minecraft_ramdisk (above)
    
    At some point I will update this to call out instance names rather than doing all instances in lockstep with each other, but for now this should cover most cases and hopefully ease some pain. UPDATE - You can now call out instance names independently as needed.

    rc.d script commands:
    Code:
    minecraft start -- starts all craftbukkit instances configured in rc.conf
    minecraft start <instName> -- start named instance
    minecraft stop -- stops all craftbukkit instances configured in rc.conf after 5 seconds
    minecraft stop <instName> -- stop named instance after 5 seconds
    minecraft stopnow -- same as stop, except stops immediately
    minecraft stopnow <instName> same as stop <instName>, except stops immediately
    minecraft status -- shows the status for all craftbukkit instances configured in rc.conf
    minecraft status <instName> -- shows the status for name instance
    minecraft console <instName> -- open the tmux console for instName. BE CAREFUL - READ THE TMUX MAN PAGE BEFORE USE!
    minecraft isrunning <instName> -- is <instName> running
    minecraft backup -- backup all minecraft servers
    minecraft backup <instName> -- backup <instName> minecraft server
    minecraft persistramdisk -- forces the running servers on the tmpfs partition to persist back to the HDD
    minecraft persistramdisk <instName> -- force <instName> running on the tmpfs partition to persist back to the HDD
    
    Rather than attaching these as files I'm just going to drop their contents in code blocks below. My layout (mentioned above), is as follows:
    Code:
    /usr/local/craftbukkit/servers/ <-- top level of all server instances
    /usr/local/craftbukkit/servers/xxx <-- server instance name 'xxx'
    
    Each instance would have its own startServer.sh (to allow per-instance customization without polluting the rc.conf too heavily).

    Hopefully all of this makes sense and is helpful to someone out there. Let me know if you have any questions or requests.

    minecraft rc.d file:
    Code:
    #!/bin/sh
    #
    # PROVIDE: minecraft
    # REQUIRE: NETWORKING
    # KEYWORD: shutdown
    #
     
    # Sanity Checks
    # Validate that our required components are installed: java, rsync and tmux
    which -s java tmux rsync
    if [ $? -ne 0 ]; then
      echo "A required component was not found"
      exit 0
    fi
     
    # see if we're being called by a valid tty (interactive mode)
    tty -s
    _notInteractive=$?
     
    tmuxCmd=`which tmux`
    rsyncCmd=`which rsync`
    # We don't use java in this script directly, so no need to pull it
     
    . /etc/rc.subr
     
    name="minecraft"
    rcvar=`set_rcvar`
    start_precmd="${name}_prestart"
    start_cmd="${name}_start"
    stop_cmd="${name}_stop"
    stopnow_cmd="${name}_stopnow"
    restart_cmd="${name}_restart"
    status_cmd="${name}_status"
    console_cmd="${name}_console"
    isrunning_cmd="${name}_isrunning"
    backup_cmd="${name}_backup"
    persistramdisk_cmd="${name}_persistramdisk"
    extra_commands="stopnow status console isrunning backup persistramdisk"
     
    load_rc_config $name
    eval "${rcvar}=\${${rcvar}:-'NO'}"
    minecraft_instpath=${minecraft_instpath:-"/usr/local/craftbukkit/servers"}
    minecraft_instlist=${minecraft_instlist:-""} # each name in the instlist is considered a sub-directory of instpath
    minecraft_startscript=${minecraft_startscript:-""} # startup script can be relative or to instpath or an absolute path on its own
    minecraft_backuppath=${minecraft_backuppath:-"${minecraft_instpath}/../backup"}
    minecraft_ramdisk=${minecraft_ramdisk:-"${minecraft_instpath}/../md"}
     
    printMsg()
    {
      if [ $_notInteractive -eq 0 ]; then
          echo $1
      fi
    }
     
    ramdiskEnabled()
    {
      local instName
      local ramdiskEnabledVarName
      local ramdiskEnabledVal="NO"
      if [ $# -eq 1 ]; then
          instName=$1
          # check instance for ramdisk config
          ramdiskEnabledVarName="minecraft_ramdisk_${instName}"
          eval ramdiskEnabledVal=\$${ramdiskEnabledVarName}
          ramdiskEnabledVal=`echo $ramdiskEnabledVal | awk '{print toupper($0)}'`
          if [ "$ramdiskEnabledVal" = "YES" ]; then
            return 1
          fi
      else
          printMsg "Failed to check if ramdisk is enabled because we got an improper number of parameters (need 1, got $#)"
      fi
     
      return 0
    }
     
    minecraft_prestart()
    {
      local instNameList
      if [ $# -ge 1 ]; then
          instNameList=$@
      else
          instNameList=$minecraft_instlist
      fi
     
      for instName in $instNameList; do
          # Check to see we have a valid directory to work with
          if [ ! -d $minecraft_instpath/$instName ]; then
            printMsg "Directory $minecraft_instpath/$instName does not exist..."
            return 1
          fi
     
          # If the supplied startup script for the minecraft servers is blank or not found
          # then we need to bail as we won't be able to start up...
          if [ $minecraft_startscript ]; then
            if [ ! -e $minecraft_instpath/$instName/$minecraft_startscript -a ! -e $minecraft_startscript ]; then
                printMsg "Unable to locate the Minecraft Server Startup Script ($minecraft_startscript)..."
                return 1
            fi
          else
            printMsg "Minecraft Server Startup Script not set in rc.conf..."
            return 1
          fi
     
      done
     
      return 0
    }
     
    minecraft_isrunning()
    {
      local instName=$1
      local interactiveMode=1
     
      if [ $# -lt 1 ]; then
          printMsg "Exactly one instance is required for this command"
          return 0
      elif [ $# -eq 2 ]; then
          interactiveMode=$2
          echo "$interactiveMode" | grep -q -E '^[0-9]+$' # make sure the second arg is a number
          if [ $? -ne 0 ]; then
            printMsg "The second paramter can only be 1 or 0"
            return 0
          fi
      fi
     
      # now check if it is running
      su -l minecraftsvc -c "$tmuxCmd has-session -t '$instName'" >/dev/null 2>&1
      if [ $? -eq 0 ]; then
          if [ $interactiveMode -gt 0 ]; then
            printMsg "$instName is running"
          fi
          return 1
      fi
      if [ $interactiveMode -gt 0 ]; then
          printMsg "$instName not running"
      fi
      return 0
    }
     
    minecraft_start()
    {
      local instRamdiskOn
      local instNameList
      if [ $# -ge 1 ]; then
          instNameList=$@
      else
          instNameList=$minecraft_instlist
      fi
     
      for instName in $instNameList; do
          minecraft_isrunning $instName 0
          if [ $? -eq 0 ]; then
            # check instance for ramdisk config
            ramdiskEnabled $instName
            instRamdiskOn=$?
            if [ -d $minecraft_ramdisk -a $instRamdiskOn -eq 1 ]; then
                printMsg "Using ramdisk for $instName"
                if [ -d $minecraft_ramdisk/$instName ]; then
                  printMsg "$instName found in ramdisk but its not running?"
                  printMsg "Removing $instName from ramdisk and replacing with HDD copy"
                  su -l minecraftsvc -c "rm -rf '$minecraft_ramdisk/$instName'" >/dev/null
                fi
     
                printMsg "Copying $instName to ramdisk"
                su -l minecraftsvc -c "cp -Rf '$minecraft_instpath/$instName' '$minecraft_ramdisk/$instName'" >/dev/null
             
                printMsg "Starting $instName from ramdisk..."
                su -l minecraftsvc -c "$tmuxCmd new-session -s '$instName' -d 'cd $minecraft_ramdisk/$instName; ./$minecraft_startscript'" >/dev/null
            else
                printMsg "Starting $instName..."
                su -l minecraftsvc -c "$tmuxCmd new-session -s '$instName' -d 'cd $minecraft_instpath/$instName; ./$minecraft_startscript'" >/dev/null
            fi
          else
            printMsg "Minecraft Server $instName is already running..."
          fi
      done
    }
     
    minecraft_persistramdisk()
    {
      local instRamdiskOn
      local instNameList
      local curSessionChk
      local maxSessionChk=6
      if [ $# -ge 1 ]; then
          instNameList=$@
      else
          instNameList=$minecraft_instlist
      fi
     
      for instName in $instNameList; do
          if [ -f "/tmp/persist_in_prog_$instName" ]; then
            printMsg "Ramdisk persistance of $instName already in progress"
            continue
          fi
          # if we have an existing ramdisk and the current instance is found to be there /and/ the HDD copy of the image is configured
          # to run on the ramdisk - overwrite the HDD with what we have on the ramdisk as its likely the latest copy
          # check instance for ramdisk config
          ramdiskEnabled $instName
          instRamdiskOn=$?
          if [ -d $minecraft_ramdisk/$instName -a $instRamdiskOn -eq 1 ]; then
            # hold off on persisting if a backup is in progress...
            curSessionChk=0
            while [ -f "/tmp/backup_in_prog_$instName" ]; do
                if [ $curSessionChk -ge $maxSessionChk ]; then
                  printMsg "Backup is taking too long, attempting to persist anyway..."
                  break
                fi
                printMsg "Backup currently in progress on $instName, delaying persist for 30 seconds"
                sleep 30
                curSessionChk=`expr $curSessionChk + 1`
            done
            su -l minecraftsvc -c "touch '/tmp/persist_in_prog_$instName'"
            minecraft_isrunning $instName 0
            local isRunning=$?
            if [ $isRunning -eq 1 ]; then
                printMsg "Forcing world save before persist for $instName"
                su -l minecraftsvc -c "$tmuxCmd send-keys -t '$instName' 'save-off' C-m" >/dev/null
                su -l minecraftsvc -c "$tmuxCmd send-keys -t '$instName' 'save-all' C-m" >/dev/null
                sync
            fi
     
            printMsg "Syncing $instName from ramdisk to HDD"
            $rsyncCmd -aq --exclude=*.lck --exclude=*.core --exclude=*.lock --delete "$minecraft_ramdisk/$instName/" "$minecraft_instpath/$instName"
     
            if [ $isRunning -eq 1 ]; then
                su -l minecraftsvc -c "$tmuxCmd send-keys -t '$instName' 'save-on' C-m" >/dev/null
            fi
            su -l minecraftsvc -c "rm -f '/tmp/persist_in_prog_$instName'"
          else
            printMsg "$instName not configured to run or is not running in the ramdisk"
          fi
      done
    }
     
    minecraft_stopnow()
    {
      local curSessionChk=0
      local maxSessionChk=5  # this amounts to 5 checks, with a 1 second pause (5 seconds of checking per server!)
      local isRunning=0
      local instRamdiskOn
      local instNameList
      if [ $# -ge 1 ]; then
          instNameList=$@
      else
          instNameList=$minecraft_instlist
      fi
     
      for instName in $instNameList; do
          minecraft_isrunning $instName 0
          if [ $? -eq 1 ]; then
            printMsg "Stopping $instName..."
            su -l minecraftsvc -c "$tmuxCmd send-keys -t '$instName' 'say Server shutdown - Autosaving map.' C-m" >/dev/null
            su -l minecraftsvc -c "$tmuxCmd send-keys -t '$instName' 'save-all' C-m" >/dev/null
            su -l minecraftsvc -c "$tmuxCmd send-keys -t '$instName' 'stop' C-m" >/dev/null
     
            # if we were running in a ramdisk, persist it out and clean it up
            ramdiskEnabled $instName
            instRamdiskOn=$?
            if [ -d $minecraft_ramdisk/$instName -a $instRamdiskOn -eq 1 ]; then
                # give the instance some time to stop...
                curSessionChk=0
                minecraft_isrunning $instName 0
                isRunning=$?
                while [ $isRunning -eq 1 ]; do
                  # if the session is still open, wait a second and check again
                  sleep 1
                  minecraft_isrunning $instName 0
                  isRunning=$?
                  curSessionChk=`expr $curSessionChk + 1`
                  if [ $curSessionChk -ge $maxSessionChk ]; then
                      printMsg "$instName did not stop within $maxSessionChk seconds"
                      printMsg "We will persist the ramdisk anyway"
                      break
                  fi
                done
                # make sure we're fully persisted before cleaning up the ramdisk...
                if [ -f "/tmp/persist_in_prog_$instName" ]; then
                  while [ -f "/tmp/persist_in_prog_$instName" ]; do
                      printMsg "Waiting for pending ramdisk persist to complete..."
                      sleep 1
                  done
                else
                  minecraft_persistramdisk $instName
                fi
                printMsg "Cleaning up ramdisk for $instName"
                su -l minecraftsvc -c "rm -rf '$minecraft_ramdisk/$instName'" >/dev/null
            fi
          else
            printMsg "Minecraft Server $instName is not running..."
          fi
      done
    }
     
    minecraft_stop()
    {
      local instNameList
      if [ $# -ge 1 ]; then
          instNameList=$@
      else
          instNameList=$minecraft_instlist
      fi
     
      local waitSeconds=5
     
      for instName in $instNameList; do
          minecraft_isrunning $instName 0
          if [ $? -eq 1 ]; then
            printMsg "Waiting $waitSeconds seconds to stop $instName..."
            su -l minecraftsvc -c "$tmuxCmd send-keys -t '$instName' 'say Server shutting down in $waitSeconds seconds.' C-m" >/dev/null
            sleep $waitSeconds
            minecraft_stopnow $instName
          else
            printMsg "Minecraft Server $instName is not running..."
          fi
      done
    }
     
    minecraft_restart()
    {
      local maxSessionChk=5  # this amounts to 5 checks, with a 1 second pause (5 seconds of checking per server!)
      local curSessionChk=0
      local isRunning=0
      local instNameList
      if [ $# -ge 1 ]; then
          instNameList=$@
      else
          instNameList=$minecraft_instlist
      fi
     
      printMsg "Restarting Minecraft Servers [$instNameList]"
     
      minecraft_stop $instNameList
     
      # wait for them to stop before restarting them...
      for instName in $instNameList; do
          #check if we're running
          curSessionChk=0
          minecraft_isrunning $instName 0
          isRunning=$?
          while [ $isRunning -eq 1 ]; do
            # if the session is still open, wait a second and check again
            sleep 1
            minecraft_isrunning $instName 0
            isRunning=$?
            curSessionChk=`expr $curSessionChk + 1`
            if [ $curSessionChk -ge $maxSessionChk ]; then
                printMsg "$instName did not stop within $maxSessionChk seconds"
                break
            fi
          done
      done
     
      minecraft_start $instNameList
    }
     
    minecraft_status()
    {
      local instNameList
      if [ $# -ge 1 ]; then
          instNameList=$@
      else
          instNameList=$minecraft_instlist
      fi
     
      for instName in $instNameList; do
          minecraft_isrunning $instName 0
          if [ $? -eq 1 ]; then
            printMsg "Status for $instName:"
            # Lets pull from the console directly rather than a log (that may be disabled)
            su -l minecraftsvc -c "$tmuxCmd capture-pane -t '$instName'" >/dev/null 2>&1
            su -l minecraftsvc -c "$tmuxCmd show-buffer" | tail -n 16
            su -l minecraftsvc -c "$tmuxCmd delete-buffer"
          else
            printMsg "$instName not running..."
          fi
          printMsg "================================"
      done
    }
     
    minecraft_console()
    {
      local instName
      if [ $# -eq 1 ]; then
          instName=$@
     
          minecraft_isrunning $instName 0
          if [ $? -eq 1 ]; then
            su -l minecraftsvc -c "$tmuxCmd attach-session -t '$instName'" >/dev/null 2>&1
            if [ $? -ne 0 ]; then
                printMsg "Unable to get console for $instName"
            fi
          else
            printMsg "$instName does not appear to be running"
          fi
      else
          printMsg "Exactly one instance name required for this command"
      fi
    }
     
    minecraft_backup()
    {
      local isRunning=0
      local curTime=`date "+%a_%H_%M"`
      local instNameList
      local instRamdiskOn
      #local lastBackupNum
      local maxBackupNum=3  # this is zero based so 3 will keep 4 around
      if [ $# -ge 1 ]; then
          instNameList=$@
      else
          instNameList=$minecraft_instlist
      fi
     
      for instName in $instNameList; do
          if [ -f "/tmp/backup_in_prog_$instName" ]; then
            printMsg "Backup of $instName already in progress"
            continue
          fi
          printMsg "Starting backup of $instName"
          # check instance for ramdisk config
          ramdiskEnabled $instName
          instRamdiskOn=$?
          if [ -d $minecraft_ramdisk/$instName -a $instRamdiskOn -eq 1 ]; then
            su -l minecraftsvc -c "$tmuxCmd send-keys -t '$instName' 'say Server backup starting.' C-m" >/dev/null
            # make sure we've persisted out to disk recently prior to backing up...
            if [ -f "/tmp/persist_in_prog_$instName" ]; then
                while [ -f "/tmp/persist_in_prog_$instName" ]; do
                  printMsg "Ramdisk persistance in progress..."
                  sleep 1
                done
            else
                minecraft_persistramdisk $instName
            fi
          else
            # check for a running server and set to read-only mode before doing the backup...
            minecraft_isrunning $instName 0
            isRunning=$?
            if [ $isRunning -eq 1 ]; then
                printMsg "Switching $instName to read-only mode."
                su -l minecraftsvc -c "$tmuxCmd send-keys -t '$instName' 'say Server backup starting. Switching to read-only mode.' C-m" >/dev/null
                su -l minecraftsvc -c "$tmuxCmd send-keys -t '$instName' 'save-off' C-m" >/dev/null
                su -l minecraftsvc -c "$tmuxCmd send-keys -t '$instName' 'save-all' C-m" >/dev/null
                sync
            fi
          fi
     
          # do the backup
          su -l minecraftsvc -c "touch '/tmp/backup_in_prog_$instName'"
     
          local filename=`echo $instName\_$curTime.tgz | tr -d " "`
          if [ -f "$minecraft_backuppath/$filename" ]; then
            printMsg "Removing old backup $instName taken last $curTime"
            su -l minecraftsvc -c "rm -f '$minecraft_backuppath/$filename'" >/dev/null
          fi
     
          printMsg "Backing up $instName..."
          su -l minecraftsvc -c "cd $minecraft_instpath; tar zcf '$minecraft_backuppath/$filename' $instName" >/dev/null 2>&1
          su -l minecraftsvc -c "rm -f '/tmp/backup_in_prog_$instName'" >/dev/null
          #su -l minecraftsvc -c "echo $lastBackupNum > /tmp/lastBackup_$instName"
     
          # re-enable read-write mode if the server is running
          if [ -d $minecraft_ramdisk/$instName -a $instRamdiskOn -eq 1 ]; then
            su -l minecraftsvc -c "$tmuxCmd send-keys -t '$instName' 'say Server backup ending.' C-m" >/dev/null
          else
            if [ $isRunning -eq 1 ]; then
                su -l minecraftsvc -c "$tmuxCmd send-keys -t '$instName' 'save-on' C-m" >/dev/null
                su -l minecraftsvc -c "$tmuxCmd send-keys -t '$instName' 'say Server backup ending. Switching to read-write mode.' C-m" >/dev/null
                printMsg "Switching $instName to read-write mode."
            fi
          fi
          printMsg "Finished backup of $instName"
      done
    }
     
    run_rc_command "$@"
    
    cronjobs I use (with the minecraftsvc user):
    Code:
    # Backup our minecraft servers every 6 hours
    0 */6 * * *    /usr/lcoal/etc/rc.d/minecraft backup
    # Persist all servers running on the tmpfs memory partition to HDD every 5 minutes
    */5 * * * *    /usr/local/etc/rc.d/minecraft persistramdisk
    
    startServer.sh example script:
    Code:
    #!/bin/sh
     
    javaCmd=`which java`
    craftBukkitJar=craftbukkit-1.3.1-R1.0.jar
     
    $javaCmd -Xmx6144M -Xms2048M -jar "$craftBukkitJar" nogui
    
    Just a quick update - added code to allow calling out specific instances rather than doing them all every time. Should make this rc.d script much more flexible. See above for changes.

    UPDATE - Wow, I completely forgot to document the fact that I have a user account called minecraftsvc which is used to run the tmux/java commands for starting/stopping the craftbukkit instances...

    If people would like to see it, I can turn this into a FreeBSD Craftbukkit how to wiki page somewhere...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  2. Offline

    hawkfalcon

    This looks like a worthy addition for the tools index:)
     
  3. Offline

    shadowen

    Its been about a year since I last posted here and this is a bit of a revive of the thread, but I feel its worth it as over the past year or so I made some major changes to these scripts, specifically adding support to automatically running and managing minecraft servers on a tmpfs partition (RAM disk). That feature alone gave me measurable boosts in performance.

    This script is fairly generic for the most part and can be used outside of craftbukkit too, I may post this around, but I wanted to drop it here first since this is where it all started.

    Anyway, see the original post for all the changes/additions.
     
  4. Offline

    lmamakos

    I made a few tweaks to parameterize the userid that's going to own all these processes. This also caused me to update the various su commands to su -m since my minimal privileged user doesn't have a login shell, and the su -l invocation fails.

    Also, the backup operation fails for me unless I run it as root -- the su command of course fails when invoked as the minecraft user.

    Rather than dump all the diffs, this is representative of the sort of changes I made in my version:
    Code:
    @@ -210,13 +216,13 @@
                sleep 30
                curSessionChk=`expr $curSessionChk + 1`
            done
    -        su -l minecraftsvc -c "touch '/tmp/persist_in_prog_$instName'"
    +        su -m $minecraft_user -c "touch '/tmp/persist_in_prog_$instName'"
            minecraft_isrunning $instName 0
            local isRunning=$?
            if [ $isRunning -eq 1 ]; then
                printMsg "Forcing world save before persist for $instName"
    -            su -l minecraftsvc -c "$tmuxCmd send-keys -t '$instName' 'save-off' C-m" >/dev/null
    -            su -l minecraftsvc -c "$tmuxCmd send-keys -t '$instName' 'save-all' C-m" >/dev/null
    +            su -m $minecraft_user -c "$tmuxCmd send-keys -t '$instName' 'save-off' C-m" >/dev/null
    +            su -m $minecraft_user -c "$tmuxCmd send-keys -t '$instName' 'save-all' C-m" >/dev/null
                sync
            fi
     
    
    I also added a default for minecraft_user in the same fashion as the other variables.

    Thanks for this work; its really nicely done and saved me a bunch of time. I'm running a couple of minecraft server instances inside of a jail on a FreeBSD 9.2 system using this.
     
  5. Offline

    shadowen

    Without knowing what your system fully looks like I can't really speculate on why backup only works as root - my guess is directory/file permission issues somewhere. I run the backup and persist scripts as part of minecraftsvc's crontab (noted above I think)...

    I'm glad this is helping though, always good to hear! Are you by chance using the tempfs functionality at all? I've found a reasonable performance gain when I went to loading the instances fully into memory (at the risk of losing up to 5 minutes of changes in the case of a crash, or worse case 6 hours if everything goes wrong and I have to restore from backup).
     
Thread Status:
Not open for further replies.

Share This Page