Automating Tasks

From OpenSimulator

Jump to: navigation, search

Contents

Automated Grid Startup

Linux/Mac OS X

See

Basic scripts

  • Use Screen Command

Use the screen command to automate startup

  • Setup screen command and setup shell file

Linux install:

apt-get install screen (ubuntu)
pacman -S screen (archlinux)

Mac OS X: Download either MacPorts, http://www.macports.org/, or Fink, http://www.finkproject.org/ to download *nix packages MacPorts

sudo port install screen

Fink

  • Create file runsim.sh
#!/bin/sh
cd opensim/bin
screen -S Robust -d -m  mono OpenSim.Robust.exe
sleep 10
screen -S OpenSimulator -d -m mono OpenSim.exe -gridmode=true

See Also --> Smart Prestart LINUX

  • Bash Scripts:
  • Start multiple instances and backup critical files prior to startup
  • Automated Shutdown of multiple instances with a 2 minute pre-warning to users in-world.
  • NB This can be used to stuff other functions into OpenSimulator Console as well.

Startup and access servers

./runsim.sh

If you have permission issues

chmod 755 runsim.sh

To see a list of the servers in screen:

screen -ls or screen -list

Output will look like the following:

There are screens on:
     8419.OpenSim  (Detached)
     8403.Robust  (Detached)

To access server

screen -r 8419.OpenSim
screen -r 8403.Robust

To exit screen, leaving server running, and to return to shell

ctrl-a d

osstart.sh

example: osstart.sh OpenSim

(Directory name = screen name)

Real examples:

/opt/osstart.sh sim1

/opt/osstart.sh sim2

/opt/osstart.sh sim3

/opt/osstart.sh sim...

#!/bin/bash
sleep 3
if [ -d $1 ]; then
  echo "$(tput setaf 4)OpenSim: $(tput setab 7)$1 Start$(tput sgr 0)"
  cd /opt/$1/bin
  screen -fa -S $1 -d -U -m mono OpenSim.exe
else
  echo "$(tput setaf 2)The following screens were started$(tput sgr 0)"
  screen -ls
   exit 1
fi

osgridstart.sh

#!/bin/bash
sleep 3
robust="/opt/robust/"
if [ -d "$robust" ]; then
  # Take action if $robust exists. #
  echo "$(tput setaf 4)OpenSim: $(tput setab 3)RobustServer Start$(tput sgr 0)"
  cd /opt/robust/bin
  screen -fa -S RO -d -U -m mono Robust.exe
else
  echo "$(tput setaf 2)The following screens were started $(tput sgr 0)RO $(tput setaf 2)and $(tput sgr 0)OS$(tput setaf 2).$(tput sgr 0)"
  screen -ls
   exit 1
fi
sleep 10
money="/opt/robust/"
if [ -d "$money" ]; then
  # Take action if $robust exists. #
  echo "$(tput setaf 4)OpenSim: $(tput setab 3)MoneyServer Start$(tput sgr 0)"
  cd /opt/robust/bin
  screen -fa -S MO -d -U -m mono MoneyServer.exe
else
  echo "$(tput setaf 2)The following screens were started $(tput sgr 0)RO $(tput setaf 2)and $(tput sgr 0)OS$(tput setaf 2).$(tput sgr 0)"
  screen -ls
   exit 1
fi
cd /opt
# echo " Wait 40 seconds and then start regions."
sleep 40
echo "$(tput setaf 2)OpenSim: $(tput setab 0)Welcome Region start$(tput sgr 0)"
/opt/osstart.sh sim1
echo "$(tput setaf 2)OpenSim: $(tput setab 0)Start all other regions$(tput sgr 0)"
/opt/osstart.sh sim2
/opt/osstart.sh sim3
/opt/osstart.sh sim4
/opt/osstart.sh sim5
/opt/osstart.sh sim6
/opt/osstart.sh sim7
/opt/osstart.sh sim8
/opt/osstart.sh sim9
/opt/osstart.sh sim10
echo "$(tput setaf 2)List started screens$(tput sgr 0)"
screen -ls

Shutdown Servers

Either manually access each sceen

screen -r 8419.OpenSim
shutdown

Or

screen -S OpenSim -p 0 -X eval "stuff 'shutdown'^M"

Or use (only in the event of a crash!)

killall screen

Or

for i in `ps afxu | grep -i "mono.*OpenSim" | grep -v grep | awk {'print $2'}`; do kill $i; done

Or to shut down each session clean, make a stop script, stopgrid.sh

#!/bin/bash
screen -S Robust -X quit
sleep 10
screen -S OpenSim -X quit

osstop.sh

example: osstop.sh OpenSim

(Directory name = screen name)

real example:

/opt/osstop.sh sim1

/opt/osstop.sh sim2

/opt/osstop.sh sim...

#!/bin/bash
sleep 10
if screen -list | grep -q $1; then
  echo "$(tput setaf 1)OpenSim: $(tput setab 7)Regionen OpenSimulator $1 Beenden$(tput sgr 0)"
  screen -S $1 -p 0 -X eval "stuff 'shutdown'^M"
else
  echo "$(tput setaf 1)OpenSim: $(tput setab 7)Regionen OpenSimulator $1 nicht vorhanden$(tput sgr 0)"
fi


osgridstop.sh

#!/bin/bash
sleep 3
echo "$(tput setaf 1)OpenSim: $(tput setab 6)Stop regions$(tput sgr 0)"
/opt/osstop.sh sim2
/opt/osstop.sh sim3
/opt/osstop.sh sim4
/opt/osstop.sh sim5
/opt/osstop.sh sim6
/opt/osstop.sh sim7
/opt/osstop.sh sim8
/opt/osstop.sh sim9
/opt/osstop.sh sim10
sleep 30
echo "$(tput setaf 1)OpenSim: $(tput setab 6)Stop the Welcome Region$(tput sgr 0)"
/opt/osstop.sh sim1
if screen -list | grep -q "MO"; then
  echo "$(tput setaf 1)OpenSim: $(tput setab 3)Exit MoneyServer$(tput sgr 0)"
  screen -S MO -p 0 -X eval "stuff 'shutdown'^M"
else
  echo "$(tput setaf 1)OpenSim: $(tput setab 3)MoneyServer does not exist$(tput sgr 0)"
fi
sleep 30
if screen -list | grep -q "RO"; then
  echo "$(tput setaf 1)OpenSim: $(tput setab 3)Exit RobustServer$(tput sgr 0)"
  screen -S RO -p 0 -X eval "stuff 'shutdown'^M"
else
  echo "$(tput setaf 1)OpenSim: $(tput setab 3)RobustServer does not exist$(tput sgr 0)"
fi
sleep 30
echo " List screens"
screen -ls
echo "$(tput setaf 1)$(tput setab 7)Wait 60 seconds and then kill all open screens$(tput sgr 0)"
sleep 60
killall screen

oslogdel.sh

deletes log files (unfortunately the log files get unbearably large.)

example: oslogdel.sh OpenSim

real example:

/opt/oslogdel.sh robust

/opt/oslogdel.sh sim1

/opt/oslogdel.sh sim2

/opt/oslogdel.sh sim...

#!/bin/bash
sleep 3
cd /opt
if [ -d $1 ]; then
  echo "$(tput setaf 1)OpenSim: $(tput setab 7)log $1 deleted$(tput sgr 0)"
  cd /opt/$1/bin
  # echo "/opt/$1/bin"
  rm *.log
else
  echo "$(tput setaf 1)logs not found $(tput sgr 0)"
  exit 1
fi

Simulator Watchdog

Watches the simulator process under Linux

Adding an entry to call a simple script to check the process table can restart regions that crash to the command line. Here User_talk:BlueWall is a script to accomplish this with a sample cron entry for one minute intervals. While it will not fix 100% of the crashes, it will get most cases, and help keep the grid healthy. If you have questions, you can usually find me on irc.freenode.net #opensim or #osgrid

--BlueWall 15:53, 19 June 2008 (PDT)

Automate Updates

Linux (CentOS-5)

This script will save your settings, grab the latest release of OpenSim, build OpenSim, and restore your settings to the new release. It creates the new release in a new directory allowing you to revert to the previous release by just changing the 'current' link to point to whichever release you want to run.

Note: This may not work well if updating from versions that are quite far apart. Minor updates should work well. Sometimes you have to clear out the SAVEDIR to prevent very old files from messing up a new update.

This script assumes you are using the SVN release number as the OpenSimulator directory with a link called 'current' pointing to it. So, you might, for example, have a directory called '/home/opensim/7577' and a link 'current -> 7577'. This script also uses a save folder for moving settings from the old release to the new.

You will also want to compare the 'OpenSim.ini' and the 'OpenSim.ini.example' by hand after running this update script. There are often changes in this file needed for the new release. The 'diff -bB' command helps a lot in this comparison.

#!/bin/bash -x

CWD=`pwd`
MWD="/home/opensim"  # Main Working Directory
SAVEDIR="$MWD/save"  # Save Directory

if [ ! -d $SAVEDIR ]; then mkdir $SAVEDIR; fi
if [ ! -d $SAVEDIR/Regions ]; then mkdir $SAVEDIR/Regions; fi
if [ ! -d $SAVEDIR/DataSnapshot ]; then mkdir $SAVEDIR/DataSnapshot; fi
if [ ! -d $SAVEDIR/config-include ]; then mkdir $SAVEDIR/config-include; fi

cd $MWD

# save current settings
cp current/bin/*.xml $SAVEDIR
cp current/bin/*.db $SAVEDIR
cp current/bin/*.ini $SAVEDIR
cp current/bin/config-include/*.ini $SAVEDIR/config-include/
cp current/bin/Regions/*xml $SAVEDIR/Regions/
cp current/bin/DataSnapshot/*xml $SAVEDIR/DataSnapshot/

# Get fresh copy of OpenSimulator
REV=`svn info http://opensimulator.org/svn/opensim/trunk | fgrep Revision | awk '{print $2}'`
svn -r $REV co http://opensimulator.org/svn/opensim/trunk $REV
rm current
ln -s $REV current
cd current
./runprebuild.sh
nant
cd bin
# restore settings
if [ ! -d ./DataSnapshot ]; then mkdir ./DataSnapshot; fi
cp $SAVEDIR/*.xml .
cp $SAVEDIR/*.db .
cp $SAVEDIR/*.ini .
cp $SAVEDIR/config-include/* config-include/
cp $SAVEDIR/Regions/* Regions/
cp $SAVEDIR/DataSnapshot/* DataSnapshot/
cd $MWD
cd current
#
cd $CWD

Windows

Create a batch file to start up your grid, e.g. startGrid.bat ;

 @Echo OFF

For /F "Usebackq" %%i In (`Tasklist ^| Find /C "OpenSim"`) Do If /I %%i GTR 0 Echo There are %%i OpenSimulator processes running already. I quit! & Goto END

:: %PROGRAMFILES% expands to your normal application path
:: On an English system this is normally C:\Program Files
:: If you run a 64-bit Windows, with OpenSimulator as a 32-bit
:: application, substitute with %PROGRAMFILES(X86)%

Echo Starting Robust Server...
start "Robust" /MIN /D "%PROGRAMFILES%\OpenSim" OpenSim.Robust.exe
sleep 5
Echo Starting Region Server...
start "RegionServer" /MIN /D "%PROGRAMFILES%\OpenSim" OpenSim.exe -gridmode=true

:END

PS! Check that you have sleep command installed, I'm unsure if all Windows versions have that.
If sleep is not installed one can use a localhost ping instead to replace "sleep 3".

PING -n 4 127.0.0.1>nul

This knowledgebase article describes how to add a batch file to startup of Windows (before logon).
http://support.microsoft.com/kb/q243486/
Note that you have to start all applications and answer the configuration questions once before adding it to any startup.

If you start the server before logon then there will be no window to close if you want to shut down the server, so you can create a "StopGrid.BAT" with:

taskkill /FI "IMAGENAME eq OpenSim.*"
sleep 3
taskkill /FI "IMAGENAME eq OpenSim.*"
sleep 3
taskkill /F /FI "IMAGENAME eq OpenSim.*"

Or a more advanced batch that shut server processes down in the opposite order as recommended in the manual.

@Echo OFF

For /F "Usebackq" %%i In (`Tasklist ^| Find /C "OpenSim"`) Do If /I %%i EQU 0 Echo There are no OpenSimulator processes running. Nothing to stop.. & Goto END


Echo Stopping Region Server...
taskkill /T /IM OpenSim.exe > NUL 2>&1
If ERRORLEVEL 128 Echo Region Server was not running! & Echo. & Goto n1
:r1
If ERRORLEVEL 1 taskkill /T /F /IM OpenSim.exe > NUL 2>&1
If ERRORLEVEL 0 Echo Region Server stopped. & Echo. & Goto n1
Goto r1

:n1
Echo Stopping Robust Server...
taskkill /T /IM OpenSim.Grid.Robust.exe > NUL 2>&1
If ERRORLEVEL 128 Echo Robust Server was not running! & Echo. & Goto n2
:r2
If ERRORLEVEL 1 taskkill /T /F /IM OpenSim.Grid.Robust.exe > NUL 2>&1
If ERRORLEVEL 0 Echo Robust Server stopped. & Echo. & Goto n2
:END

See also

Personal tools
General
About This Wiki