UnixScripts

From OpenSim

Jump to: navigation, search



For those of you that are running UNIX based servers there are 2 scripts available to automate things a bit on bootup and shutdown of the server.

The first is for grid services. The second is for the standalone OpenSim.exe OR region servers.

OpenSim.Grid.*Server.exe init.d script

#!/bin/bash

# launches an OpenSimulator server via a pipe
PIPE_ROOT="/var/run"

# this is where you want the OpenSimulator directory to be created for the logfiles
LOG_ROOT="/var/log/OpenSim"

# this is where all fo the dll, exe, ini, and Regions stuff is located
BIN_DIR="/root/bin"

# all servers in the grid on one box.
#SERVERS="User Asset Inventory Grid"

# just one server on this box.
SERVERS="User"

# obtain a reverse ordering of the servers to launch for shutdown
SHUTDOWNSERVERS=""
for SERVER in ${SERVERS}
do
  OLD=${SHUTDOWNSERVERS}
  SHUTDOWNSERVERS="${SERVER} ${OLD}"
done

# test to see if ordering is proper. Uncomment to see it.
#echo "Start order ${SERVERS}"
#echo "Stop order  ${SHUTDOWNSERVERS}" 

#exit 0

# ensure that the log dir exists
mkdir -p "${LOG_ROOT}"

TestPipe()
{
   PIPE=${1}
   if ( test -p  ${PIPE} && test -w ${PIPE} && test -r ${PIPE} )
   then
       echo "Pipe OK" > /dev/null 
   else
      rm -f ${PIPE}
      mkfifo ${PIPE}
      chmod 660 ${PIPE}
   fi
}

StartServer()
{
   SERVER="${1}"
   PIPE="${PIPE_ROOT}/OpenSim_${SERVER}.pipe"
   LOGFILE="${LOG_ROOT}/${SERVER}.log"

   echo -n "${SERVER} "
   TestPipe ${PIPE}

   # if an old logfile exists then move it out of the way so we preserve in case of crash.
   if ( test -e ${LOGFILE} )
   then
      mv "${LOGFILE}" "${LOGFILE}.0"
   fi

   # put that puppy into a screen session since windows apps don't understand daemons
   # the cat pipe portion allows us to feed the "shutdown" command to the server later
   screen -d -m bash -c "cd ${BIN_DIR} ; cat ${PIPE} | cli ./OpenSim.Grid.${SERVER}Server.exe 2>&1 > ${LOGFILE}"
}

ShutdownServer()
{
   SERVER="${1}"
   PIPE="${PIPE_ROOT}/OpenSim_${SERVER}.pipe"
   echo -n "${SERVER} "
   echo "shutdown" > "${PIPE}" &
   sleep 1
   # now make certain that the echo isn't hanging around. darned pipes. 8-(
   kill %1
}

case "$1" in 
  start)
    echo -n "Launching OpenSimulator Servers... "
    for SERVER in ${SERVERS}
    do
       StartServer ${SERVER}
       sleep 2
    done
    echo " Done"
    ;;
  stop)
    echo -n "Stopping OpenSimulator Server... "
    for SERVER in ${SHUTDOWNSERVERS}
    do
      ShutdownServer ${SERVER}
    done
    echo " Done"
    ;;
esac

OpenSim.exe init.d script

#!/bin/bash

# launches an OpenSimulator server via a pipe
PIPE_ROOT="/var/run"
LOG_ROOT="/var/log/OpenSim"
BIN_DIR="/root/bin"

# for grid mode. comment out if you want standalone
#GRIDMODE="--gridmode=true"

mkdir -p "${LOG_ROOT}"

# tests to make certain that the pipe is there and creates it if it is not
TestPipe()
{
   PIPE=${1}
   if ( test -p  ${PIPE} && test -w ${PIPE} && test -r ${PIPE} )
   then
      echo "Pipe OK" > /dev/null
   else
      rm -f ${PIPE}
      mkfifo ${PIPE} 

      #lock it down EXPLICITLY. mkfifo has had bugs int eh past. ;-P
      chmod 660 ${PIPE}
      chown root:daemon ${PIPE}
   fi
}

StartServer()
{
   SERVER="${1}"
   PIPE="${PIPE_ROOT}/OpenSim.pipe"
   LOGFILE="${LOG_ROOT}/OpenSim.log"
    TestPipe ${PIPE}
    if ( test -e ${LOGFILE} )
    then
      mv "${LOGFILE}" "${LOGFILE}.0"
    fi
    screen -d -m bash -c "cd ${BIN_DIR} ; cat ${PIPE} | cli ./OpenSim.exe ${GRIDMODE} 2>&1 > ${LOGFILE}"
}

ShutdownServer()
{
    echo "shutdown" > "${PIPE_ROOT}/OpenSim.pipe" &
    sleep 1
    # now make certain that the echo sin't hanging around. 8-(
    kill %1
}

case "$1" in 
  start)
    echo -n "Launching OpenSimulator Server "
    StartServer 
    sleep 2
    echo " Done"
    ;;
  stop)
    echo -n "Stopping OpenSimulator Server "
    ShutdownServer 
    echo " Done"
    ;;
esac


Grab each of these and install then in your /etc/init.d/directory (or alternative master directory if you dont' run a SysV based init)

Personal tools
About This Wiki