Autorestart With Upstart

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
m (Robot: Cosmetic changes)
(Monitoring/restarting OpenSimulator with upstart)
 
(4 intermediate revisions by 2 users not shown)
Line 11: Line 11:
  
  
== Monitoring/restarting OpenSim with upstart ==
+
== Monitoring/restarting OpenSimulator with upstart ==
  
The following assumes you're running OpenSim within GNU screen, so one can detach and reattach to the console. But that's not required to use upstart.
+
The following assumes you're running OpenSimulator within GNU screen, so one can detach and reattach to the console. But that's not required to use upstart. It also assumes Ubuntu 12.04 LTS (or derivatives, like Linux Mint 13).
  
Create a file, <tt>/etc/event.d/opensim</tt> , containing the following:
+
Create a file, <tt>/etc/init/opensim.conf</tt> , containing the following:
  
  start on runlevel [!06]
+
start on runlevel [!06]
  stop on runlevel [06]
+
stop on runlevel [06]
 
   
 
   
  exec /bin/su - opensim -c '/usr/bin/screen -h 0 -D -m -c /var/run/opensim/opensim.screenrc'
+
post-stop script
  respawn
+
  OSPID=`ps -ef | grep opensim | grep 'mono OpenSim.exe' | awk '{ print $2 }'`
 +
  kill $OSPID
 +
end script
 
   
 
   
  # give up if I respawn 3 times in 60 seconds...
+
exec /bin/su - opensim -c "/usr/bin/screen -h 0 -D -m -U -S OpenSim -c /var/run/opensim/opensim.screenrc"
  respawn limit 3 60
+
respawn
 +
 +
# give up if I respawn 3 times in 60 seconds...
 +
respawn limit 3 60
 +
 
 +
If you are running MySQL, you can cause OpenSim to start after MySQL starts successfully by replacing the first two lines with:
 +
 
 +
start on started mysql
 +
stop on stopping mysql
  
 
Create a file, <tt>/var/run/opensim/opensim.screenrc</tt> , containing the following:
 
Create a file, <tt>/var/run/opensim/opensim.screenrc</tt> , containing the following:
  
 +
multiuser on
 +
acladd <controlusers>
 +
aclchg <controlusers> +rwx "#?"
 
  chdir /usr/lib/opensim/bin
 
  chdir /usr/lib/opensim/bin
  screen -h 500 -t opensim mono OpenSim.exe -gui=true
+
  screen -h 500 -t opensim mono OpenSim.exe -console=basic
  
Then, to start or stop OpenSim, just use:
+
where <controlusers> is a comma-separated list of users you want to give control of the OpenSimulator console to. This is needed if you run OpenSim as a service user account you never actually log in to. Note that that account must be created with a real shell.
 +
 
 +
Then, to start or stop OpenSimulator, just use:
  
 
  # start opensim
 
  # start opensim
Line 39: Line 54:
 
  # stop opensim
 
  # stop opensim
  
If OpenSim dies on its own, upstart will automatically restart it.
+
If OpenSimulator dies on its own, upstart will automatically restart it unless it dies three times within 60 seconds.
 +
 
 +
To connect to OpenSimulator with screen, use:
 +
 
 +
# screen -r opensim/
 +
 
 +
(or use <tt>sudo</tt>, if desired). Note that this will only work from the Unix userids you've specified in <controlusers> above.

Latest revision as of 20:02, 26 January 2013

[edit] What is upstart?

From the official description:

Upstart is an event-based replacement for the /sbin/init daemon which handles starting of tasks and services during boot, stopping them during shutdown and supervising them while the system is running.
It was originally developed for the Ubuntu distribution, but is intended to be suitable for deployment in all Linux distributions as a replacement for the venerable System-V init.


[edit] Monitoring/restarting OpenSimulator with upstart

The following assumes you're running OpenSimulator within GNU screen, so one can detach and reattach to the console. But that's not required to use upstart. It also assumes Ubuntu 12.04 LTS (or derivatives, like Linux Mint 13).

Create a file, /etc/init/opensim.conf , containing the following:

start on runlevel [!06]
stop on runlevel [06]

post-stop script
  OSPID=`ps -ef | grep opensim | grep 'mono OpenSim.exe' | awk '{ print $2 }'`
  kill $OSPID
end script

exec /bin/su - opensim -c "/usr/bin/screen -h 0 -D -m -U -S OpenSim -c /var/run/opensim/opensim.screenrc"
respawn

# give up if I respawn 3 times in 60 seconds...
respawn limit 3 60

If you are running MySQL, you can cause OpenSim to start after MySQL starts successfully by replacing the first two lines with:

start on started mysql
stop on stopping mysql

Create a file, /var/run/opensim/opensim.screenrc , containing the following:

multiuser on
acladd <controlusers>
aclchg <controlusers> +rwx "#?"
chdir /usr/lib/opensim/bin
screen -h 500 -t opensim mono OpenSim.exe -console=basic

where <controlusers> is a comma-separated list of users you want to give control of the OpenSimulator console to. This is needed if you run OpenSim as a service user account you never actually log in to. Note that that account must be created with a real shell.

Then, to start or stop OpenSimulator, just use:

# start opensim

or:

# stop opensim

If OpenSimulator dies on its own, upstart will automatically restart it unless it dies three times within 60 seconds.

To connect to OpenSimulator with screen, use:

# screen -r opensim/

(or use sudo, if desired). Note that this will only work from the Unix userids you've specified in <controlusers> above.

Personal tools
General
About This Wiki