Automating Tasks
From OpenSimulator
Languages: |
English Français |
Automate Grid Startup
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 OpenSim as a 32-bit :: application, substitute with %PROGRAMFILES(X86)% Echo Starting User Server... start "UserServer" /MIN /D "%PROGRAMFILES%\OpenSim" OpenSim.Grid.UserServer.exe sleep 5 Echo Starting Grid Server... start "GridServer" /MIN /D "%PROGRAMFILES%\OpenSim" OpenSim.Grid.GridServer.exe sleep 5 Echo Starting Asset Server... start "AssetServer" /MIN /D "%PROGRAMFILES%\OpenSim" OpenSim.Grid.AssetServer.exe sleep 5 Echo Starting Inventory Server... start "InventoryServer" /MIN /D "%PROGRAMFILES%\OpenSim" OpenSim.Grid.InventoryServer.exe sleep 5 Echo Starting Messaging Server... start "MessagingServer" /MIN /D "%PROGRAMFILES%\OpenSim" OpenSim.Grid.MessagingServer.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 Messaging Server... taskkill /T /IM OpenSim.Grid.MessagingServer.exe > NUL 2>&1 If ERRORLEVEL 128 Echo Inventory Server was not running! & Echo. & Goto n2 :r2 If ERRORLEVEL 1 taskkill /T /F /IM OpenSim.Grid.MessagingServer.exe > NUL 2>&1 If ERRORLEVEL 0 Echo IMessaging Server stopped. & Echo. & Goto n2 Goto r2 :n2 Echo Stopping Inventory Server... taskkill /T /IM OpenSim.Grid.InventoryServer.exe > NUL 2>&1 If ERRORLEVEL 128 Echo Inventory Server was not running! & Echo. & Goto n3 :r3 If ERRORLEVEL 1 taskkill /T /F /IM OpenSim.Grid.InventoryServer.exe > NUL 2>&1 If ERRORLEVEL 0 Echo Inventory Server stopped. & Echo. & Goto n3 Goto r3 :n3 Echo Stopping Asset Server... taskkill /T /IM OpenSim.Grid.AssetServer.exe > NUL 2>&1 If ERRORLEVEL 128 Echo Asset Server was not running! & Echo. & Goto n4 :r4 If ERRORLEVEL 1 taskkill /T /F /IM OpenSim.Grid.AssetServer.exe > NUL 2>&1 If ERRORLEVEL 0 Echo Asset Server stopped. & Echo. & Goto n4 Goto r4 :n4 Echo Stopping Grid Server... taskkill /T /IM OpenSim.Grid.GridServer.exe > NUL 2>&1 If ERRORLEVEL 128 Echo Grid Server was not running! & Echo. & Goto n5 :r5 If ERRORLEVEL 1 taskkill /T /F /IM OpenSim.Grid.GridServer.exe > NUL 2>&1 If ERRORLEVEL 0 Echo Grid Server stopped. & Echo. & Goto n5 Goto r5 :n5 Echo Stopping User Server... taskkill /T /IM OpenSim.Grid.UserServer.exe > NUL 2>&1 If ERRORLEVEL 128 Echo User Server was not running! & Echo. & Goto END :r6 If ERRORLEVEL 1 taskkill /T /F /IM OpenSim.Grid.UserServer.exe > NUL 2>&1 If ERRORLEVEL 0 Echo User Server stopped. & Echo. & Goto END Goto r6 :END
(Batch edits, Suz 04:46, 27 May 2008 (PDT))
Linux/Mac OS X
You can use this startup script
- 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
Need command line for Fink.
- Create file runsim.sh
#!/bin/sh cd opensim/bin sleep 3 screen -S UserServer -d -m mono OpenSim.Grid.UserServer.exe sleep 3 screen -S GridServer -d -m mono OpenSim.Grid.GridServer.exe sleep 3 screen -S AssetServer -d -m mono OpenSim.Grid.AssetServer.exe sleep 3 screen -S InventoryServer -d -m mono OpenSim.Grid.InventoryServer.exe sleep 3 screen -S OpenSim -d -m mono OpenSim.exe -gridmode=true
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.InventoryServer (Detached) 8378.AssetServer (Detached) 8360.GridServer (Detached) 8347.UserServer (Detached)
To access server
screen -r 8419.OpenSim screen -r 8403.InventoryServer etc.
To exit screen, leaving server running, and to return to shell
ctrl-a d
Shutdown Servers
Either manually access each sceen
screen -r 8419.OpenSim shutdown
Or use
killall mono
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 InventoryServer -X eval "stuff shutdown^M" sleep 5 screen -S AssetServer -X eval "stuff shutdown^M" sleep 5 screen -S GridServer -X eval "stuff shutdown^M" sleep 5 screen -S UserServer -X eval "stuff shutdown^M"
This depends on the screen NAME to be the same as in the startup script described above! --Suz 01:42, 18 May 2008 (PDT)
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.
This script assumes you are using the SVN release number as the OpenSim 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 OpenSim 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
Alternative methods
Start/stop/restart OpenSim on Linux with upstart