osgrid.org
https://forums.osgrid.org/

Periodic Reboot script
https://forums.osgrid.org/viewtopic.php?f=14&t=1171
Page 1 of 1

Author:  Richard Senior [ Mon May 04, 2009 8:23 am ]
Post subject:  Periodic Reboot script

I thought I would share the script I run as a cron job (every 24hours) on my OpenSim servers. I find that because of heavy use and a memory leak in mono that to keep the servers clean a period restart of mono (and therefore OpenSim) is very benifical.

This script makes certain assumptions.....
- Your only running mono for your OpenSim instance
- Your running OpenSim in a detached screen (the screen command)
- Your only running one OpenSim instance

The script will check to see if OpenSim is already running, if so it will start a 5 minute countdown with alerts logged on avatars every minute, then issue the shutdown command. It then checks again every 10 seconds until either the OpenSim instance shuts down successfuly or a 2 minute limit it reached. If the limit is reached then we assume OpenSim crashed on exit and force terminate the screen session.
At this point the script will then restart the OpenSim instance in a detached screen session (called OPENSIM)

If anyone can find ways to improve what Ihave done then please feel free, all input is welcome.

{L_CODE}:
#!/bin/bash
SERVICE='mono'
WAITTIME=10
DETECTED_OPENSIM="N"
EXCEED_TIME="N"

function start_opensim {
   echo "Starting OpenSim"
   screen -dm -S OPENSIM mono OpenSim.exe
}

function stop_opensim {
   echo "stopping opensim"
   echo "sending alert"
   screen -S OPENSIM -r -X stuff 'alert general This region will auto restart in approximatly 5 minutes, please ensure you logout or teleport to another region. Thanks PioneerX Estate Management
'
   sleep 60
   screen -S OPENSIM -r -X stuff 'alert general This region will auto restart in approximatly 4 minutes, please ensure you logout or teleport to another region. Thanks PioneerX Estate Management
'
   sleep 60
   screen -S OPENSIM -r -X stuff 'alert general This region will auto restart in approximatly 3 minutes, please ensure you logout or teleport to another region. Thanks PioneerX Estate Management
'
   sleep 60
   screen -S OPENSIM -r -X stuff 'alert general This region will auto restart in approximatly 2 minutes, please ensure you logout or teleport to another region. Thanks PioneerX Estate Management
'
   sleep 60
   screen -S OPENSIM -r -X stuff 'alert general This region will auto restart in approximatly 1 minutes, please ensure you logout or teleport to another region. Thanks PioneerX Estate Management
'
   sleep 60
   screen -S OPENSIM -r -X stuff 'shutdown
'
}

function stop_screen {
   echo "stopping screen"
   screen -S OPENSIM -r -X 'exit'
}

if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
       echo "OpenSim is running"
   DETECTED_OPENSIM="Y"
else
       echo "OpenSim is not running"
   DETECHED_OPENSIM="N"
fi

if [ "$DETECTED_OPENSIM" = "Y" ]; then
   echo "Deteched OpenSim"
   stop_opensim
   EXCEED_TIME="Y"
   for i in {1..12}; do
      sleep $WAITTIME
      if ps ax | grep -v grep | grep $SERVICE > /dev/null
      then
         echo "OpenSim still running, need to wait longer"
      else
         echo "OpenSim stopped lets restart it"
         EXCEED_TIME="N"
         break
      fi
   done
   if [ $EXCEED_TIME = "Y" ]; then
      echo "OpenSim didnt shutdown in time - assumed a crash"
      stop_screen
   fi
   start_opensim
else
   echo "No running OpenSim deteched"
   stop_screen
   start_opensim
fi

Author:  WhiteStar Magic [ Tue May 05, 2009 10:13 am ]
Post subject:  Re: Periodic Reboot script

!!! EXCELLENT !!!

I wish that was available for Windows Installs.... (Contemplating the mechanism)

I do have a suggestion in regards to the shutdown process. By enabling the the Timer Script function in the opensim.ini you could execute a series of "pre-shutdown" functions.
See http://osgrid.org/forums/viewtopic.php?f=14&t=1153 for information on Timer_Script.

The Timer runs every 20 minutes, so my idea would be to have the timer_script = TimedScript.txt modified 30 minutes prior to shutdown/restart. The reason I suggest 30 minutes, is because some of the processes can take a period of time to complete and this would depend on how "heavy" the region/sim is with objects etc....

Have the Script in your system, replace the TimedScript.txt by copying BackupScript.txt onto it. This script would then be executed at the 20 minute interval and be capable of making Backup Files such as OARS, XML etc.... in addition to running the internal backup command to make sure everything is dumped into the DataBase.
Further backup discussion in http://osgrid.org/forums/viewtopic.php?f=9&t=1143

NOTE: Once the Opensim.ini is read in it won't change the OpenSim Instance even if you edit it. So you have to set the timer_script = and copy over it, that script is read in every time it is executed, therefore it's contents can be changed between runs.

Once the backup files are generated and prior to the shutdown / restart, replace the TimedScript.txt by copying a "neutral" text file onto it, in order to prevent the 20 minute cycle from running the full backup.

An additional thought would be to transfer the opensim.log After Shutdown to an archive for that day, then as a "pre-start" clear the previous opensim.log and run a command-line dump of the MySql DB so you also have a current backup copy of it. This would give you a fresh clean log & a DB Backup from the start which makes it easier to see if something is going astray.

While operating under Mono is a bit different than what I am used to working with, I assume that there are open file handles and such running. Therefore applying the lessons learned experience, I strongly suggest making living backups of the data and having everything committed to the Database before the application is shutdown to maintain integrity and consistency.

Just some thoughts and suggestions

Author:  Ralf Haifisch [ Thu May 07, 2009 5:45 pm ]
Post subject:  Re: Periodic Reboot script

for more on linux scripting and screen, maybe have a look at

http://www.maxping.org/resources/how-to ... gions.aspx


cheers,
Ralf

Author:  Simpy Merryman [ Mon May 11, 2009 4:12 pm ]
Post subject:  Re: Periodic Reboot script

James Beejay {L_WROTE}:
I thought I would share the script I run as a cron job (every 24hours) on my OpenSim servers. I find that because of heavy use and a memory leak in mono that to keep the servers clean a period restart of mono (and therefore OpenSim) is very benifical.


I very interested in this, could you possibly explain a little about "run as a cron job" please - bearing in mind I know nothing about running scripts like this :)

Author:  RetroDan Dezno [ Tue May 12, 2009 3:02 am ]
Post subject:  Re: Periodic Reboot script

cron is an old unix utility that allows you to schedule tasks to run at certain times on certain days.

Its syntax is a little unusual, so I'd recommend that you Google or Wiki "unix cron" first and get a idea of what its all about.

Author:  Ralf Haifisch [ Tue May 12, 2009 3:50 am ]
Post subject:  Re: Periodic Reboot script

or - if you prefer some cofort in administration use webmin.

it comes for allmost all flavors of posix operating systems, so there will be no difference if you migrate form lenny to solaris on to suse...

http://www.webmin.com/

less fidelling with CLI commands...

cheers,
Ralf

Author:  Simpy Merryman [ Tue May 12, 2009 6:24 am ]
Post subject:  Re: Periodic Reboot script

RalfHaifisch {L_WROTE}:
or - if you prefer some cofort in administration use webmin.
it comes for allmost all flavors of posix operating systems, so there will be no difference if you migrate form lenny to solaris on to suse...
http://www.webmin.com/
less fidelling with CLI commands...
cheers,
Ralf


Thanks for the replies Retro and Ralf, much appreciated.... :)

I use webmin on my vps, but didn't know you could use it to automatically restart opensim....

Author:  Michelle Argus [ Tue May 12, 2009 6:56 am ]
Post subject:  Re: Periodic Reboot script

@ Simpy

Check under "System" in webmin, there you will find Cronjob ;)

Author:  AlexRJ String [ Wed Nov 07, 2018 10:58 am ]
Post subject:  Re: Periodic Reboot script

Is this script to be applied in opensim running with the windows server system?

I'm behind a script to reboot the islands from the above script form, but to be used in Windows, specifying each island and how long reboot, then would pick and drop the task scheduler in Windows to run, I do not know if it would be so or if I can put the code already inside each island that squeeze? can you help me?

I'm using opensim 0.9.0

My email is silvasuporte@gmail.com.

Author:  AlexRJ String [ Sat Nov 10, 2018 7:40 am ]
Post subject:  Re: Periodic Reboot script

Can someone help me by telling me how do I schedule the reboot of the region automatically? If possible put an example, because I'm starting now and I do not know much.

For Windows Server.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/