Autorestart With Upstart

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(Updating and expanding)
(Monitoring/restarting OpenSimulator with upstart)
 
(2 intermediate revisions by one user not shown)
Line 13: Line 13:
 
== Monitoring/restarting OpenSimulator with upstart ==
 
== 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.
+
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]
Line 25: Line 25:
 
  end script
 
  end script
 
   
 
   
  exec /bin/su - opensim -c '/usr/bin/screen -h 0 -D -m -U -S OpenSim -c /var/run/opensim/opensim.screenrc'
+
  exec /bin/su - opensim -c "/usr/bin/screen -h 0 -D -m -U -S OpenSim -c /var/run/opensim/opensim.screenrc"
 
  respawn
 
  respawn
 
   
 
   
Line 42: Line 42:
 
  aclchg <controlusers> +rwx "#?"
 
  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
  
where <controlusers> is a comma-separated list of users you want to give control of the OpenSim 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.
+
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 OpenSim, just use:
+
Then, to start or stop OpenSimulator, just use:
  
 
  # start opensim
 
  # start opensim
Line 55: Line 55:
  
 
If OpenSimulator dies on its own, upstart will automatically restart it unless it dies three times within 60 seconds.
 
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 19: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