Uptime Guarantee: Restart Script for Linux

Still being in development, OpenSimulator crashes once in a while. Especially when you’re testing new functionalities, running it on a barely adequate machine (such as your home desktop or even laptop) or if you’re simply overloading your Sim with scripts, complex objects and visitors. Were this to happen in the middle of the night, when you’re not home or simply when you’re not paying attention, your simulator could be down for hours or even days. When you only use your simulator for personal things, that’s not such a big deal. But when it’s a public -grid connected- simulator with actual frequent visitors, this could mean losing your coordinates on the grid and losing visitors.

It’s advisable to set up some form of monitoring, because even the script described here can crash. For my simulator I use Nagios to monitor the simulator port (usually 9000). This way you get email notification of when your simulator goes down and up again. Don’t set the frequency too high, otherwise it will trigger even when the restart script is working.

Then, the restart script. I wrote and tested this script in Debian 5 (Lenny) and 6 (Squeeze) but I’m sure it’ll work in any Linux environment.

Create a file in the bin directory of your Simulator (if you followed my install guide this is /opt/opensimulator/bin/)

#su -
#touch restartopensim.sh
#nano restartopensim.sh

Paste the following into the contents of the script and save:

#!/bin/bash
cd /opt/opensim/bin/
while true ; do mono OpenSim.exe ; echo "done, sleep"; sleep 10; done

This will start a loop that starts OpenSimulator, echoes “done, sleep” whenever the process terminates and then sleeps for 10 seconds before it starts over again. I built in the 10 seconds of sleep to give the simulator the chance to terminate properly, you don’t want it starting up again too soon, especially when it crashed because of a memory issue, but also for a very practical reason. If you do want to *really* shut down your simulator, for example for updating it or maintenance, you can kill the script in those 10 seconds. Never kill your simulator while it’s running, even if it’s starting up or shutting down. This could seriously corrupt your database.

To start OpenSimulator do the following:

#screen
#./restartopensim.sh

To detach the screen, press [ctrl]|+[a]+[d]. To kill it (only during the 10 seconds of sleep!) [ctrl]+[a]+[k]. To resume the screen, simply execute screen -r.

If you’re connecting through ssh, don’t forget to use sudo.

This entry was posted in Running OpenSimulator and tagged , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *