Changes

Jump to navigation Jump to search
m
Line 1: Line 1:  
<div class="CHAPTER">
 
<div class="CHAPTER">
=Process startup, supervision and shutdown=
+
==Process startup, supervision and shutdown==
    
<div class="SECT1">
 
<div class="SECT1">
   −
==Process startup==
+
===Process startup===
    
In typical Linux systems, services (processes) are started at boot time through a mechanism such as <span class="emphasis">''System V init''</span>. When the system administrator needs to change the settings, they modify the configuration files and then restart the service or notify the process that it needs to re-read the configuration.
 
In typical Linux systems, services (processes) are started at boot time through a mechanism such as <span class="emphasis">''System V init''</span>. When the system administrator needs to change the settings, they modify the configuration files and then restart the service or notify the process that it needs to re-read the configuration.
Line 17: Line 17:  
----
 
----
   −
==Process supervision: runit (and supervise)==
+
===Process supervision: runit (and supervise)===
    
The SME Server addresses these issues by running processes under the '''runit''' process supervision environment, which:
 
The SME Server addresses these issues by running processes under the '''runit''' process supervision environment, which:
Line 25: Line 25:  
* restarts the process if it fails
 
* restarts the process if it fails
 
* provides a consistent mechanism for controlling the underlying process
 
* provides a consistent mechanism for controlling the underlying process
 
+
{{Note box|msg=Gerrit Pape's '''runit''' came from previous work by Dan Bernstein on the '''supervise''' supervision environment. '''runit''' provides additional features, and has been released under a free software license.}}
<div class="NOTE"><blockquote class="NOTE">
+
<div class="SECT2">
 
  −
'''Note: '''Gerrit Pape's '''runit''' came from previous work by Dan Bernstein on the '''supervise''' supervision environment. '''runit''' provides additional features, and has been released under a free software license.
  −
 
  −
</blockquote></div><div class="SECT2">
   
----
 
----
   −
===The runit process tree===
+
====The runit process tree====
    
When a Linux system boots, it starts the '''init''' process, which then starts all other processes. When '''init''' enters "run-level 7", it starts '''/etc/runit/2''' from an entry in <tt class="FILENAME">/etc/inittab</tt>.
 
When a Linux system boots, it starts the '''init''' process, which then starts all other processes. When '''init''' enters "run-level 7", it starts '''/etc/runit/2''' from an entry in <tt class="FILENAME">/etc/inittab</tt>.
Line 74: Line 70:     
This looks like a complex process tree, but is a critical part of the SME Server's design for reliability. Each process is independent, has a consistent management interface, has process limits imposed on it, and will restart if it happens to fail.
 
This looks like a complex process tree, but is a critical part of the SME Server's design for reliability. Each process is independent, has a consistent management interface, has process limits imposed on it, and will restart if it happens to fail.
 
+
{{Note box|msg=For the curious, if init fails, the system reboots.}}
<div class="NOTE"><blockquote class="NOTE">
  −
 
  −
'''Note: '''For the curious, if init fails, the system reboots.
  −
 
  −
</blockquote></div>
      
For further documentation on runit, refer to the runit manual page.
 
For further documentation on runit, refer to the runit manual page.
Line 86: Line 77:  
----
 
----
   −
===Run-level 7 and the e-smith-service wrapper===
+
====Run-level 7 and the e-smith-service wrapper====
    
The SME Server runs in the normally unused run-level 7. This ensures that the only software running on the SME Server is software that we have chosen to run, and it is started and stopped in a consistent way. If we need to replace a standard startup script with one which runs the process under supervise, we can do so <span class="emphasis">''without modifying the original package''</span>.
 
The SME Server runs in the normally unused run-level 7. This ensures that the only software running on the SME Server is software that we have chosen to run, and it is started and stopped in a consistent way. If we need to replace a standard startup script with one which runs the process under supervise, we can do so <span class="emphasis">''without modifying the original package''</span>.
Line 110: Line 101:  
* If so, it runs the <tt class="FILENAME">/etc/init.d/syslog</tt> script with the argument <var class="LITERAL">start</var>.
 
* If so, it runs the <tt class="FILENAME">/etc/init.d/syslog</tt> script with the argument <var class="LITERAL">start</var>.
 
* If the service is not enabled, it exits without starting the service.
 
* If the service is not enabled, it exits without starting the service.
 +
{{Note box|msg=If a script exists in the <tt class="FILENAME">/etc/init.d/supervise/</tt> directory, <tt class="FILENAME">e-smith-service</tt> will use that in preference to the one in the <tt class="FILENAME">/etc/init.d/</tt> directory. This allows us to install our own supervised startup scripts <span class="emphasis">''without modifying the original package''</span>.}}
 +
 +
===Adding a supervised service===
 +
See http://cr.yp.to/daemontools.html
 +
 +
Check your application has a -d option or similar which means that it stays in the foreground, and logs to standard output rather than syslog. That makes it suitable for running as a supervised service.
 +
 +
Create a /var/service/XXX directory, containing an executable 'run' script something like:
 +
 +
#! /bin/sh
 +
exec 2>&1
 +
exec /var/service/XXX -d
 +
 +
and a /var/service/XXX/log directory, containing an executable 'run' script something like:
 +
 +
#! /bin/sh
 +
exec  setuidgid smelog  \
 +
    /usr/local/bin/multilog t s500000  \
 +
    /var/log/XXX
   −
<div class="NOTE"><blockquote class="NOTE">
+
You would then do:
   −
'''Note: '''If a script exists in the <tt class="FILENAME">/etc/init.d/supervise/</tt> directory, <tt class="FILENAME">e-smith-service</tt> will use that in preference to the one in the <tt class="FILENAME">/etc/init.d/</tt> directory. This allows us to install our own supervised startup scripts <span class="emphasis">''without modifying the original package''</span>.
+
mkdir /var/log/XXX
 +
chown smelog.smelog /var/log/XXX
 +
ln -s /var/service/XXX /service
 +
touch /var/service/XXX/down
   −
</blockquote></div></div></div></div>
+
</div></div></div>

Navigation menu