Change font size
It is currently Sat Nov 17, 2018 12:33 pm

Forum rules


{L_IMAGE}
. please keep questions related to an OpenSimulator and OSgrid nature.



Post a new topicPost a reply Page 1 of 1   [ 10 posts ]
Author Message
 Post subject: Periodic Reboot script
PostPosted: Mon May 04, 2009 8:23 am 
Furious Typer

Joined: Wed Oct 29, 2008 11:30 am
Posts: 67
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

_________________
Thanks for listening

James Beejay
PioneerX Estate Management
http://www.sl-estates.co.uk/

For the very latest from PioneerX Estate Management please checkout our News Desk @ http://www.sl-estates.co.uk/newsdesk.php


Top
 Profile  
 
 Post subject: Re: Periodic Reboot script
PostPosted: Tue May 05, 2009 10:13 am 
OSG Elite
User avatar

Joined: Wed Mar 11, 2009 3:57 pm
Posts: 444
!!! 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

_________________
No further support of any kind, for any of my materials. Use as/is whereis.
PLEASE UNSTICKY Any Stickied Posting by myself.


Top
 Profile  
 
 Post subject: Re: Periodic Reboot script
PostPosted: Thu May 07, 2009 5:45 pm 
OSG Elite
User avatar

Joined: Wed Nov 19, 2008 6:22 pm
Posts: 592
for more on linux scripting and screen, maybe have a look at

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


cheers,
Ralf

_________________
visit me:

osgrid: Sharkland Tropical 1 SL: Great white shark

German opensim HowTo: http://www.ralf-haifisch.biz/Opensim%20HowTo.shtml
Mapxing - 3D web magazine devotet to opensource: http://opensim.maxping.org/


Top
 Profile  
 
 Post subject: Re: Periodic Reboot script
PostPosted: Mon May 11, 2009 4:12 pm 

Joined: Tue Apr 14, 2009 6:34 am
Posts: 39
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 :)


Top
 Profile  
 
 Post subject: Re: Periodic Reboot script
PostPosted: Tue May 12, 2009 3:02 am 
Furious Typer
User avatar

Joined: Sat Dec 27, 2008 7:57 am
Posts: 71
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.

_________________
OSG Home User Group: http://groups.google.com/group/OSGHUG


Top
 Profile  
 
 Post subject: Re: Periodic Reboot script
PostPosted: Tue May 12, 2009 3:50 am 
OSG Elite
User avatar

Joined: Wed Nov 19, 2008 6:22 pm
Posts: 592
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

_________________
visit me:

osgrid: Sharkland Tropical 1 SL: Great white shark

German opensim HowTo: http://www.ralf-haifisch.biz/Opensim%20HowTo.shtml
Mapxing - 3D web magazine devotet to opensource: http://opensim.maxping.org/


Top
 Profile  
 
 Post subject: Re: Periodic Reboot script
PostPosted: Tue May 12, 2009 6:24 am 

Joined: Tue Apr 14, 2009 6:34 am
Posts: 39
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....


Top
 Profile  
 
 Post subject: Re: Periodic Reboot script
PostPosted: Tue May 12, 2009 6:56 am 
Furious Typer

Joined: Fri Dec 12, 2008 9:47 am
Posts: 258
@ Simpy

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

_________________
{L_IMAGE}{L_IMAGE}{L_IMAGE}


Top
 Profile  
 
 Post subject: Re: Periodic Reboot script
PostPosted: Wed Nov 07, 2018 10:58 am 

Joined: Tue Dec 26, 2017 2:43 pm
Posts: 3
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.


Top
 Profile  
 
 Post subject: Re: Periodic Reboot script
PostPosted: Sat Nov 10, 2018 7:40 am 

Joined: Tue Dec 26, 2017 2:43 pm
Posts: 3
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 10 posts ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net