From 554583496a2fdd3b9399c73a7fc526f99956e5bc Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Mon, 28 Nov 2011 04:53:09 +1000 Subject: Backup sim regularly. Rest don't work, screen would be better even if it did work. New scripts for stopping the sim, backing up the sim, and showing the console. Monit script works now. --- backup-sims.sh | 16 +++++++++++ create_region.sh | 3 ++ opensim-crontab.txt | 3 ++ opensim-monit.conf | 8 +++--- start-sim | 83 ++++++++++++++++++++++++++--------------------------- 5 files changed, 66 insertions(+), 47 deletions(-) create mode 100755 backup-sims.sh diff --git a/backup-sims.sh b/backup-sims.sh new file mode 100755 index 0000000..775ebbe --- /dev/null +++ b/backup-sims.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +OSPATH="/opt/opensim" + +for i in $(seq 99) +do + j=$(printf "sim%02d" $i) + if [ -e "$OSPATH/config/$j" ] + then + cd $OSPATH/config/$j + ./backup-sim + # sleep for three minutes, so that there is plenty of time to do the backup, + # and we are not keeping the computer very busy if there are lots of sims. + sleep(180) + fi +done diff --git a/create_region.sh b/create_region.sh index 5c27052..33257fd 100755 --- a/create_region.sh +++ b/create_region.sh @@ -65,6 +65,9 @@ ExternalHostName = $URL zzzzEOFzzzz ln -s ../../setup/start-sim start-sim +ln -s ../../setup/backup-sim start-sim +ln -s ../../setup/sim-console start-sim +ln -s ../../setup/stop-sim start-sim cp ../../current/bin/OpenSim.exe.config OpenSim.exe.config sed -i 's@@@' OpenSim.exe.config sed -i "s@@@" OpenSim.exe.config diff --git a/opensim-crontab.txt b/opensim-crontab.txt index ab694f7..caaaafc 100644 --- a/opensim-crontab.txt +++ b/opensim-crontab.txt @@ -9,3 +9,6 @@ # experimental version using savelog -c cycles all opensim log files over 7 days 0 0 * * * /usr/bin/savelog -c 7 /var/log/opensim/*.log +# Backup the sims every 6 hours. +0 */6 * * * /opt/opensim/setup/backup-sims.sh + diff --git a/opensim-monit.conf b/opensim-monit.conf index c98ad91..7d26a82 100644 --- a/opensim-monit.conf +++ b/opensim-monit.conf @@ -20,11 +20,11 @@ # 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 -q'" + start program = "/bin/bash -c 'cd /opt/opensim/config/sim01 && /opt/opensim/config/sim01/start-sim -q'" 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 + stop program = "/bin/bash -c 'cd /opt/opensim/config/sim01 && /opt/opensim/config/sim01/stop-sim'" with timeout 600 seconds + if cpu usage > 200% 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 diff --git a/start-sim b/start-sim index dbb1beb..ea77553 100755 --- a/start-sim +++ b/start-sim @@ -1,12 +1,5 @@ #!/bin/bash -# Pick one of these depending on how you want your access. -# NOTE - REST does not work. B-( -#NeedARest=" -console=rest" -NeedARest="" -Screaming="true" -#Screaming="" - USER=$(whoami) console_name="OpenSim_console" screen_session=opensim/${console_name} @@ -32,7 +25,7 @@ fi if [ "x$tgt" = "x" ]; then echo "usage:" - echo " $ start-sim-in-rest " + echo " $ $(basename $0) " echo "where is one of: " robust sim[0-9][0-9] exit 1 fi @@ -49,15 +42,10 @@ export MONO_PATH=${bindir} # Then we would not have to do this, and subsequently write all over the damn bin directory. cd ${bindir} -if [ "x$Screaming" = "xtrue" ] -then - if ($screen_check | grep -q ${console_name}); then - echo "INFO: Screen already running" - true - else - echo "DEBUG: Starting screen" - $SUDO screen -d -m -S ${console_name} - fi +if ($screen_check | grep -q ${console_name}); then + true +else + $SUDO screen -d -m -S ${console_name} fi if [ "x$tgt" = "xrobust" ]; then @@ -67,33 +55,42 @@ else fi inidir=/opt/opensim/config/${tgt} -cmd="/usr/bin/mono ${bindir}/${exe}.exe -inidirectory=${inidir} -logconfig=${inidir}/${exe}.exe.config $NeedARest" +# Grab the first line of the sim.ini file, it should be the sim name in square brackets. title=$(head -n 1 ${inidir}/Regions/sim.ini ) +# Strip off spaces at either end. +shopt -s extglob +title=${title##*( )} +title=${title%%*( )} +shopt -u extglob +# Strip off the square brackets at either end. +title=${title:1:$(( ${#title} - 2 ))} -# Check if it's already running. -if [ ! -e /var/run/opensim/${tgt}.pid ] -then - if [ "x$Screaming" = "xtrue" ] - then - echo "INFO: start process and connect to screen (opensim) $title" - $SUDO screen -r ${screen_session} -p "-" -X screen -t "${title}" ${cmd} - else - $cmd - fi -fi +case $(basename $0) in + "start-sim") + cmd="/usr/bin/mono ${bindir}/${exe}.exe -inidirectory=${inidir} -logconfig=${inidir}/${exe}.exe.config" -if [ "x$quiet" = "x" ] -then - # Either way, need to start up the console after. - if [ "x$Screaming" = "xtrue" ] - then - echo "Starting screen client." - screen -r ${screen_session} -A - elif [ "x$NeedARest" != "x" ] - then - echo "Starting rest client." - cd ${inidir} - /usr/bin/mono ${bindir}/OpenSim.ConsoleClient.exe -logconfig=${inidir}/${exe}.exe.config - fi -fi + # Check if it's already running. + if [ ! -e /var/run/opensim/${tgt}.pid ] + then + $SUDO screen -r ${screen_session} -p "-" -X screen -t "[${title}]" ${cmd} + fi + ;& + + "sim-console") + if [ "x$quiet" = "x" ] + then + screen -r ${screen_session} -p "[${title}]" -A + fi + ;; + + "backup-sim") + # Substitute underscores for spaces in the title, then add the full date and time to create the OAR file name. + cmd="save oar ${inidir}/../../backups/${title// /_}-$(date '+%F_%T').oar" + sudo -Hu opensim screen -r opensim/OpenSim_console -p "[${title}]" -X stuff "${cmd}$(/bin/echo -ne '\015')" + ;; + + "stop-sim") + sudo -Hu opensim screen -r opensim/OpenSim_console -p "[${title}]" -X stuff "shutdown$(/bin/echo -ne '\015')" + ;; +esac -- cgit v1.1