Automating Tasks

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(Windows)
(Lump windows bits together)
Line 1: Line 1:
 
{{Quicklinks}}
 
{{Quicklinks}}
  
== Automated Grid Startup ==
+
= Automated Grid Startup =
=== Windows ===
+
== Windows ==
 
Create a batch file to start up your grid, e.g. startGrid.bat ;
 
Create a batch file to start up your grid, e.g. startGrid.bat ;
  
Line 21: Line 21:
 
   
 
   
 
  :END
 
  :END
 
  
 
PS! Check that you have sleep command installed, I'm unsure if all Windows versions have that.<br />
 
PS! Check that you have sleep command installed, I'm unsure if all Windows versions have that.<br />
Line 61: Line 60:
 
  :END
 
  :END
  
See Also --> [[Smart Prestart WIN]]
+
=== See also ===
 +
* [[Smart Prestart WIN]]
 +
* [[Automated Upgrade WIN]]  
  
 
=== Linux/Mac OS X ===
 
=== Linux/Mac OS X ===
 
 
You can use this [[Startup script linux|startup script]]  
 
You can use this [[Startup script linux|startup script]]  
  
Line 205: Line 205:
 
* '''Bash Script:'''  
 
* '''Bash Script:'''  
 
* Automated Upgrade from Web Sourced ZIP (default uses OSGrid Repository) but can be adjusted to another repository
 
* Automated Upgrade from Web Sourced ZIP (default uses OSGrid Repository) but can be adjusted to another repository
 
 
=== Windows ===
 
 
[[Automated Upgrade WIN]]
 
 
* '''Batch Files:'''
 
* Automatic Upgrade batch file to make a complete upgrade from Web Source&nbsp;ZIP (default uses OSGrid Repository) or Local repository safely &amp; complete
 
* Automated "Switcher" Batch file to switch all instances over to run the new upgrade
 
* Automated "Reversion" Batch file to revert to previous version in case you have to
 
 
  
 
== Alternative methods ==
 
== Alternative methods ==

Revision as of 17:52, 6 November 2013

Contents

Automated 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 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

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

  • 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

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 Robust -X quit
sleep 10
screen -S OpenSim -X quit

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

Linux

Automated Upgrade LINUX

  • Bash Script:
  • Automated Upgrade from Web Sourced ZIP (default uses OSGrid Repository) but can be adjusted to another repository

Alternative methods

Start/stop/restart OpenSimulator on Linux with upstart

Configure a Linux service with systemd

Personal tools
General
About This Wiki