From ebc84ad13f6d3f1911672b1a2d449d8cddf1ae2f Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sat, 26 Nov 2011 10:09:51 +1000 Subject: First commit. --- README | 62 ++++++++++++++++++++++++++++++++++++ create_region.sh | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ go_live.sh | 17 ++++++++++ install_opensim.sh | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++ opensim-crontab.txt | 11 +++++++ opensim-monit.conf | 34 ++++++++++++++++++++ start-sim-in-rest | 43 +++++++++++++++++++++++++ 7 files changed, 341 insertions(+) create mode 100644 README create mode 100755 create_region.sh create mode 100755 go_live.sh create mode 100755 install_opensim.sh create mode 100644 opensim-crontab.txt create mode 100644 opensim-monit.conf create mode 100755 start-sim-in-rest diff --git a/README b/README new file mode 100644 index 0000000..d0573db --- /dev/null +++ b/README @@ -0,0 +1,62 @@ +Use this to create a sim that links into Infinite Grid from Linux. + +I'ts been tested on Umuntu 10.04, YMMV. + +Follow these steps. + +Go to - + +http://wiki.infinitegrid.org/index.php/Howto_Link_your_Opensim_region_to_Infinite_Grid + +and follow the directions to create an admin user account. You can skip +that bit if you already have a suitable user with sudo access. + +Note that these scripts pretty much follow that above wiki description, +with some exceptions. REST is used for console access, instead of +screen. The configuration information per sim has been rearranged so +that there is only ONE copy of the OpenSim installation. + +Next you need to figure out what password you want to use for OpenSims +access to the database. We will call this "DatabasePassword". Run the +following script - + +./install_opensim.sh DatabasePassword + +This will do most of the work fo you, except for creating sims. A +separate script is here for sim creation, you can use it to create many +sims. You will need - + +Your host name, or it could be your IP, we will use "sims.example.net". + +A name for your sim, we will use "My new sim". It should be unique on +the grid. + +A location for your sim, we will use "1234,5678". You can use the +Infinite Grid web based map to poke around and find a good location. +Choose an empty spot. + +Optionally, you might need your IP address if you are creating more than +one sim, we will use "1.2.3.4". + +Once you have all that information sorted out, run this script if ONLY +hosting a single sim on this computer - + +./create_sim.sh "My new sim" "1234,5678" "sims.example.net" + +Or this if you plan on running more than one sim - + +./create_sim.sh "My new sim" "1234,5678" "sims.example.net" "1.2.3.4" + +No you can go to /opt/opensim/config/sim01 and run the following script +to start it up - + +./start-sim-in-rest + +You will see the REST console. You can run the REST console again by +running that command once more. + +Once it's all tested, you can use this to finish things off (back in +this directory) - + +./go_live.sh + diff --git a/create_region.sh b/create_region.sh new file mode 100755 index 0000000..f13eaef --- /dev/null +++ b/create_region.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +NAME=$1 +LOCATION=$2 +URL=$3 +IP=$4 + +cd /opt/opensim/config + +k=0 +for i in $(seq 99) +do + j=$(printf "sim%02d" $i) + if [ -e "$j" ] + then + k=$i + fi +done + +if [ "x$NAME" = "x" ] +then + NAME="No name sim $RANDOM" # Should be unique per grid. +fi + +if [ "x$LOCATION" = "x" ] +then + LOCATION="$RANDOM,$RANDOM" # again UNIQUE (i.e. ONLY ONE) per grid in THIS case! +fi + +if [ "x$URL" = "x" ] +then + URL=$(hostname) # URL is best (without the HTTP://), but IP (e.g. 88.109.81.55) works too. +fi + +if [ "x$IP" = "x" ] +then + IP="0.0.0.0" # 0.0.0.0 will work for a single sim per physical machine, otherwise we need the real internal IP. +fi + +NUM=$(printf "%02d" $(($k + 1)) ) +PORT=$(( 9005 + ($k * 5) )) # 9002 is used for HTTP/UDP so START with port 9003! CAUTION Diva/D2 starts at port 9000. +UUID=$(uuidgen) + +echo "Creating sim$NUM on port $PORT @ $LOCATION - $NAME." + +mkdir -p sim$NUM/Regions +cd sim$NUM +cat > Regions/sim.ini << zzzzEOFzzzz +[$NAME] +RegionUUID = $UUID +Location = $LOCATION +InternalAddress = 0.0.0.0 +InternalPort = $(( $PORT + 1 )) +AllowAlternatePorts = False +ExternalHostName = $URL +zzzzEOFzzzz + +ln -s ../../setup/start-sim-in-rest start-sim-in-rest +#ln -s ../../current current +cp ../../current/bin/OpenSim.exe.config OpenSim.exe.config +sed -i "s@@@" OpenSim.exe.config + +#cp current/bin/OpenSim.ini OpenSim.ini +#sed -i "s@regionload_regionsdir=\"/opt/opensim/config\"@regionload_regionsdir=\"/opt/opensim/config/sim$NUM/Regions\"@" OpenSim.ini +#sed -i "s@; PIDFile = \"/var/run/opensim/opensim.pid\"@PIDFile = \"/var/run/opensim/sim$NUM.pid\"@" OpenSim.ini +#sed -i "s@;http_listener_port = 9000@http_listener_port = $(( $PORT + 0))@" OpenSim.ini +#sed -i "s@; console_port = 0@console_port = $(( $PORT + 2 ))@" OpenSim.ini + +cat > ThisSim.ini << zzzzEOFzzzz +[Startup] + PIDFile = "/var/run/opensim/sim$NUM.pid" + regionload_regionsdir="/opt/opensim/config/sim$NUM/Regions" + +[Network] + console_port = $(( $PORT + 2 )) + http_listener_port = $(( $PORT + 0)) +zzzzEOFzzzz + +cp ../../current/bin/OpenSim.ConsoleClient.ini OpenSim.ConsoleClient.ini +sed -i "s@; port = 9002@port = $(( $PORT + 2 ))@" OpenSim.ConsoleClient.ini + +cp ../../setup/opensim-monit.conf opensim-monit.conf +sed -i "s@sim01@sim$NUM@g" opensim-monit.conf + diff --git a/go_live.sh b/go_live.sh new file mode 100755 index 0000000..65e4a08 --- /dev/null +++ b/go_live.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +for i in $(seq 99) +do + j=$(printf "sim%02d" $i) + if [ -e "/opt/opensim/config/$j" ] + then + sudo chown -R opensim:opensim /opt/opensim/config/$j + sudo ln -s /opt/opensim/config/$j/opensim-monit.conf /etc/monit/conf.d/$j.conf + fi +done + +sudo chmod 755 /var/log/opensim +sudo chmod 755 /var/run/opensim +sudo chown -R opensim:opensim /opt/opensim/opensim-0.7.1.1-infinitegrid-03 +sudo chown -R opensim:opensim /opt/opensim/modules + diff --git a/install_opensim.sh b/install_opensim.sh new file mode 100755 index 0000000..0c8c659 --- /dev/null +++ b/install_opensim.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +if [ x$1 = x ] +then + MYSQL_PASSWORD="OpenSimSucks" +else + MYSQL_PASSWORD=$1 +fi +USER=$(whoami) + +sudo apt-get install mysql-server screen mono-complete monit mc +sudo /etc/init.d/mysql restart + +echo "Setting up mySQL" +mysql -u root -p -h localhost << zzzzEOFzzz +drop database opensim; +create database opensim; +drop user opensim; +drop user 'opensim'@'localhost'; +FLUSH PRIVILEGES; +create user opensim identified by '$MYSQL_PASSWORD'; +create user 'opensim'@'localhost' identified by '$MYSQL_PASSWORD'; +grant all on opensim.* to opensim; +grant all on opensim.* to 'opensim'@'localhost'; +FLUSH PRIVILEGES; +zzzzEOFzzz + +echo "Setting up OpenSim" +sudo deluser opensim +sudo adduser --system --shell /bin/false --group opensim +sudo mkdir -p /var/log/opensim +sudo chown opensim:opensim /var/log/opensim +sudo chmod 777 /var/log/opensim +sudo mkdir -p /var/run/opensim +sudo chown opensim:opensim /var/run/opensim +sudo chmod 777 /var/run/opensim +sudo mkdir -p /opt/opensim +sudo chown $USER:$USER /opt/opensim + +cd /opt/opensim +wget https://github.com/downloads/infinitegrid/InfiniteGrid-Opensim/opensim-0.7.1.1-infinitegrid-03.tar.bz2 +tar xjf opensim-0.7.1.1-infinitegrid-03.tar.bz2 +ln -s opensim-0.7.1.1-infinitegrid-03 current +mkdir -p config +mkdir -p modules +mkdir -p setup +cp setup/opensim-crontab.txt config +cat setup/opensim-crontab.txt | sudo crontab -u opensim - + +cd current/bin +mv OpenSim.Forge.Currency.dll ../../modules/ +ln -s ../../modules/OpenSim.Forge.Currency.dll OpenSim.Forge.Currency.dll +mv OpenSimSearch.Modules.dll ../../modules/ +ln -s ../../modules/OpenSimSearch.Modules.dll OpenSimSearch.Modules.dll +mv NSLModules.Messaging.MuteList.dll ../../modules/ +ln -s ../../modules/NSLModules.Messaging.MuteList.dll NSLModules.Messaging.MuteList.dll +mv OpenSimProfile.Modules.dll ../../modules/ +ln -s ../../modules/OpenSimProfile.Modules.dll OpenSimProfile.Modules.dll +#sudo chown -R opensim:opensim ../../modules +ln -s ../../config config + +cat > OpenSim.ConsoleClient.ini << zzzzEOFzzzz +[Startup] + ; Set here or use the -user command-line switch + user = RestingUser + + ; Set here or use the -host command-line switch + host = localhost + + ; Set here or use the -port command-line switch + ; port = 9002 + + ; Set here or use the -pass command-line switch + ; Please be aware that this is not secure since the password is in the clear + ; we recommend the use of -pass wherever possible + pass = SecretRestingPLace +zzzzEOFzzzz + +sed -i 's@@@' OpenSim.exe.config +sed -i 's@; ConsoleUser = "Test"@ConsoleUser = "RestingUser"@' OpenSim.ini +sed -i 's@; ConsolePass = "secret"@ConsolePass = "SecretRestingPlace"@' OpenSim.ini + +cd config-include/ +sed -i 's@Include-Storage = "config-include/storage/SQLiteStandalone.ini";@; Include-Storage = "config-include/storage/SQLiteStandalone.ini";@' GridCommon.ini +sed -i 's@; StorageProvider = "OpenSim.Data.MySQL.dll"@StorageProvider = "OpenSim.Data.MySQL.dll"@' GridCommon.ini +sed -i "s@; ConnectionString = \"Data Source=localhost;Database=opensim;User ID=opensim;Password=\*\*\*\*;\"@ConnectionString = \"Data Source=localhost;Database=opensim;User ID=opensim;Password=$MYSQL_PASSWORD;\"@" GridCommon.ini + +cd ../../.. +#sudo chown -R opensim:opensim opensim-0.7.1.1-infinitegrid-03 + diff --git a/opensim-crontab.txt b/opensim-crontab.txt new file mode 100644 index 0000000..ab694f7 --- /dev/null +++ b/opensim-crontab.txt @@ -0,0 +1,11 @@ +# to see current crontab for opensim +# $ sudo crontab -u opensim -l +# +# to install this crontab for opensim: +# $ cat /opt/opensim/config/opensim-crontab.txt | sudo crontab -u opensim - +# +# at midnight, remove old logs, files created 3 or more days ago +#0 0 * * * find /var/log/opensim -ctime +1 -delete +# experimental version using savelog -c cycles all opensim log files over 7 days +0 0 * * * /usr/bin/savelog -c 7 /var/log/opensim/*.log + diff --git a/opensim-monit.conf b/opensim-monit.conf new file mode 100644 index 0000000..e300720 --- /dev/null +++ b/opensim-monit.conf @@ -0,0 +1,34 @@ +# manage the OpenSim process for Your Sim +# +# usage: +# monit start your_sim +# monit stop your_sim +# monit restart your_sim +# +# see 'daemon' setting in /etc/monit/monitrc for the cycle length. +# on ubuntu/debian, this is overridden by the CHECK_INTERVALS var in +# /etc/default/monit . the below assumes you've set it to 30 seconds. +# +# if process dies, will restart sim within 30 seconds. if process +# dies 5 times in as many tries, will stop trying and send email +# alert. +# +# if SimFPS drops to 0 for 2 minutes, restart. +# +# if process CPU usage stays above 300% for 2 minutes, restart. +# +# see ../README for configuration instructions. +# +check process sim01 with pidfile /var/run/opensim/sim01.pid + start program = "/bin/bash -c 'cd /opt/opensim/config/sim01 && /opt/opensim/sim01/start-sim-in-rest'" + as uid opensim and gid opensim + stop program = "/bin/kill -9 `cat /var/run/opensim/sim01.pid`" +# if cpu usage > 300% for 4 cycles then restart +# if 5 restarts within 5 cycles then timeout +# if failed url http://127.0.0.1:9005/jsonSimStats/ +# and content != '"SimFPS":0.0,' for 4 cycles +# then restart +# if failed url http://127.0.0.1:9008/jsonSimStats/ +# and content == '"SimFPS":' for 4 cycles +# then restart + diff --git a/start-sim-in-rest b/start-sim-in-rest new file mode 100755 index 0000000..d6aac2c --- /dev/null +++ b/start-sim-in-rest @@ -0,0 +1,43 @@ +#!/bin/bash + +osversion="current" +NeedARest=" -console=rest" +NeedARest="" + +if [ x$1 = x ]; then + pathname=$(pwd) + tgt=$(basename $pathname) +elif [ -d ./$1 ]; then + tgt=$1 +elif [ -d ./sim$1 ]; then + tgt=sim$1 +fi + +if [ x$tgt = x ]; then + echo "usage:" + echo " $ start-sim-in-rest " + echo "where is one of: " robust sim[0-9][0-9] + exit 1 +fi + +inidir=/opt/opensim/config/${tgt} +bindir=/opt/opensim/${osversion}/bin +if [ x$tgt = xrobust ]; then + exe="Robust" +else + exe="OpenSim" +fi + +if [ ! -e /var/run/opensim/${tgt} ] +then + cd ${bindir} + /usr/bin/mono ${exe}.exe -inidirectory=${inidir} -logconfig=${inidir}/${exe}.exe.config $NeedARest +fi + +if [ "x$NeedARest" = x } +then + echo "Starting rest client." + cd ${inidir} + /usr/bin/mono ${bindir}/OpenSim.ConsoleClient.exe -logconfig=${inidir}/${exe}.exe.config +fi + -- cgit v1.1