summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--doc/index.html7
-rw-r--r--doc/replaceinit.html93
-rwxr-xr-xetc/debian/313
-rw-r--r--runit-0.2.3.tar.gzbin13602 -> 14089 bytes
-rw-r--r--src/runit.c30
5 files changed, 136 insertions, 7 deletions
diff --git a/doc/index.html b/doc/index.html
index 4977c4f..f5b772b 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -24,8 +24,9 @@
 a replacement for
 <a href="ftp://ftp.cistron.nl/pub/people/miquels/sysvinit/">sysvinit</a>.
 <i>runit</i> currently runs on
-<a href="http://www.debian.org">Debian GNU/Linux</a> but may be easily
-adapted to other unix operating systems using glibc. If <i>runit</i> runs for
+<a href="http://www.debian.org">Debian GNU/Linux</a> and
+<a href="http://www.openbsd.org/">OpenBSD 2.9<a> but may be easily
+adapted to other unix operating systems. If <i>runit</i> runs for
 you on any other operating system or linux distribution, please let me know.
 <p>
 <b>Warning:</b> Replacing <i>sysvinit</i> can cause the system's boot to fail.
@@ -74,7 +75,7 @@ See <a href="install.html">How to install runit</a> for installing
 <i>runit</i> and <a href="replaceinit.html">How to replace init</a> for
 smoothly escaping from <i>sysvinit</i>.
 <hr>
-If <i>runit</i> is compiled and linked with
+If <i>runit</i> on linux is compiled and linked with
 <a href="http://www.fefe.de/dietlibc/">dietlibc</a> it yields in a statically
 linked <tt>runit</tt> binary of 14k size and this <tt>ps axuw</tt> output
 on my system:
diff --git a/doc/replaceinit.html b/doc/replaceinit.html
index 36ede99..3772937 100644
--- a/doc/replaceinit.html
+++ b/doc/replaceinit.html
@@ -9,6 +9,10 @@
 <hr>
 <h1>runit - replacing init</h1>
 <hr>
+<a href="#sysvinit">How to replace sysvinit on Linux</a><br>
+<a href="#bsdinit">How to replace init on OpenBSD</a>
+<hr>
+<a name="sysvinit"><h2>Replacing sysvinit (Linux)</h2></a>
 Follow these steps to migrate from <i>sysvinit</i> to <i>runit</i> on
 <a href="http://www.debian.org/releases/woody/">Debian GNU/Linux (woody)</a>.
 The <tt>/sbin/init</tt> binary is not replaced until step 6, <i>runit</i> is
@@ -106,6 +110,95 @@ To report success:
   # ( uname -a ; cat /etc/runit/[123] ) | mail pape-runit-0.2.3@smarden.org
 </pre>
 <hr>
+
+<a name="bsdinit"><h2>Replacing init (OpenBSD)</h2></a>
+Follow these steps to migrate from <i>init</i> to <i>runit</i> on
+<a href="http://www.openbsd.org/">OpenBSD 2.9</a>. The
+<tt>/sbin/init</tt> binary is not replaced until step 4.
+<h3>Step 1: The three stages</h3>
+<i>runit</i> looks for the three stages implementing the system's
+<i>booting</i>, <i>running</i> and <i>shutdown</i> in <tt>/etc/runit/1</tt>,
+<tt>/etc/runit/2</tt> and <tt>/etc/runit/3</tt>, create the files now:
+<pre>
+  # mkdir -p /etc/runit
+  # cp -p /package/admin/runit/etc/openbsd/[123] /etc/runit/
+</pre>
+Remove the <tt>svscanboot</tt> startup from <tt>/etc/rc.local</tt> by
+deleting the line <tt>csh -cf '/command/svscanboot &'</tt> (this normally
+is the last one); <i>runit</i> will start <tt>svscanboot</tt> in stage 2
+after running <tt>rc.local</tt> in stage 1.
+<pre>
+  # vi /etc/rc.local
+</pre>
+Create also a getty service directory:
+<pre>
+  # mkdir -p /etc/runit/getty-ttyC4
+  # cp -p /package/admin/runit/etc/openbsd/getty-ttyC4/run \
+      /etc/runit/getty-ttyC4
+</pre>
+<h3>Step 2: The runit programs</h3>
+The <i>runit</i> programs must reside on the root partition, install them
+into <tt>/sbin</tt>:
+<pre>
+  # install -m0500 /package/admin/runit/command/runit* /sbin/
+</pre>
+<h3>Step 3: The getties</h3>
+At least one getty must run in stage 2 so you are able to login, choose a
+local <tt>tty</tt>, say <tt>ttyC4</tt> and tell
+<a href="http://cr.yp.to/daemontools/svscan.html">svscan</a>
+about the <tt>getty-ttyC4</tt> <i>service</i>:
+<pre>
+  # ln -s /etc/runit/getty-ttyC4 /service/
+</pre>
+<h3>Step 4: Replace the <tt>/sbin/init</tt> binary</h3>
+Before replacing the <tt>init</tt> binary, make sure that you are able
+to boot your system alternatively, e.g. with a boot floppy, to restore the
+former <tt>/sbin/init</tt> if anything goes wrong.
+<p>
+Make a backup copy of the current <tt>/sbin/init</tt> program and replace
+it with <tt>/sbin/runit-init</tt>:
+<pre>
+  # cp -p /sbin/init /sbin/init.bsd
+  # install /sbin/runit-init /sbin/init
+</pre>
+Boot your system with <i>runit</i> for the first time:
+<pre>
+  # reboot
+</pre>
+Watch the console output while <i>runit</i> boots up the system. Switch
+to ttyC4 (CTRL-ALT-F5) when stage 2 is reached, a getty should run there,
+you are able to login.
+<p>
+Use <b>init 6</b> to reboot and <b>init 0</b> to halt a system that runs
+<i>runit</i>. This will cause <i>runit</i> to enter stage 3 which runs
+<tt>/sbin/reboot</tt> or <tt>/sbin/halt</tt> as last command.
+<p>
+To report success:
+<pre>
+  # ( uname -a ; cat /etc/runit/[123] ) | mail pape-runit-0.2.3@smarden.org
+</pre>
+<h3>Step 5: Service migration</h3>
+The goal is to migrate all services from <i>/etc/rc.*</i> scheme to the
+<a href="http://cr.yp.to/daemontools.html">daemontools</a> design; take a
+look at these <a href="runscripts.html">run scripts</a> for popular
+services. The migration can be done smoothly. By default <i>runit</i>
+runs the <tt>/etc/rc</tt> scripts in stage 1 as a one time task, so the
+services are started automatically:
+<pre>
+  #!/bin/sh
+  # system one time tasks
+  rm -f /etc/runit/stopit
+
+  /bin/sh /etc/rc autoboot
+
+  exit 0
+</pre>
+To migrate a service, create a service directory, disable the service if
+it is running, remove the service startup from the <tt>/etc/rc.*</tt>
+script and tell <tt>svscan</tt> about the new service.
+
+
+<hr>
 <address><a href="mailto:pape@smarden.org">
 Gerrit Pape &lt;pape@smarden.org&gt;
 </a></address>
diff --git a/etc/debian/3 b/etc/debian/3
index ce96dc7..83512a2 100755
--- a/etc/debian/3
+++ b/etc/debian/3
@@ -3,14 +3,21 @@
 LAST=0
 test -r /etc/runit/reboot && LAST=6
 
+echo 'Stopping getties...'
+/command/svc -d /service/getty-*
+/command/svwaitdown -t14 /service/getty-* || \
+  ( echo 'Killing getties...' ; /command/svc -k /service/getty-* )
+
 echo 'Stopping services...'
 /command/svc -d /service/*
-/command/svwaitdown /service/* || ( echo 'Killing services...' ; \
-				    /command/svc -k /service/* )
+/command/svwaitdown -t350 /service/* || \
+  ( echo 'Killing services...' ; /command/svc -k /service/* )
+
 echo 'Stopping log services...'
 /command/svc -d /service/*/log
-/bin/sleep 5
+/command/svwaitdown -t35 /service/*/log
 
+echo 'Shutdown...'
 /etc/init.d/rc $LAST
 
 exit 0
diff --git a/runit-0.2.3.tar.gz b/runit-0.2.3.tar.gz
index f46e6ab..97d5bac 100644
--- a/runit-0.2.3.tar.gz
+++ b/runit-0.2.3.tar.gz
Binary files differdiff --git a/src/runit.c b/src/runit.c
index 4278fd5..d734de7 100644
--- a/src/runit.c
+++ b/src/runit.c
@@ -3,6 +3,7 @@
 
 #include <sys/types.h>
 #include <sys/reboot.h>
+#include <sys/ioctl.h>
 #include <signal.h>
 #include <unistd.h>
 
@@ -54,6 +55,7 @@ int main (int argc, const char * const *argv, const char * const *envp) {
   int st;
   iopause_fd x;
   char ch;
+  int ttyfd;
 
   if (getpid() != 1) {
     strerr_die2x(111, FATAL, "must be run as process no 1.");
@@ -72,6 +74,15 @@ int main (int argc, const char * const *argv, const char * const *envp) {
   sig_block(sig_pipe);
   sig_block(sig_term);
 
+  /* console */
+  if ((ttyfd =open_write("/dev/console")) != -1) {
+    if (ioctl(ttyfd, TIOCSCTTY, (char *)NULL) != -1) {
+      dup2(ttyfd, 0); dup2(ttyfd, 1); dup2(ttyfd, 2);
+      if (ttyfd > 2)
+	close(ttyfd);
+    }
+  }
+
   /* create selfpipe */
   while (pipe(selfpipe) == -1) {
     strerr_warn2(FATAL, "unable to create selfpipe, pausing: ", &strerr_sys);
@@ -82,14 +93,20 @@ int main (int argc, const char * const *argv, const char * const *envp) {
   ndelay_on(selfpipe[0]);
   ndelay_on(selfpipe[1]);
 
+#ifdef RB_DISABLE_CAD
   /* activate ctrlaltdel handling */
-  reboot(0);
+  if (RB_DISABLE_CAD == 0)
+    reboot(0);
+#endif
 
   strerr_warn3(INFO, "$Id$",
 	       ": booting.", 0);
 
   /* runit */
   for (st =0; st < 3; st++) {
+    /*
+      if (st == 2) logwtmp("~", "reboot", "");
+    */
     while ((pid =fork()) == -1) {
       strerr_warn4(FATAL, "unable to fork for \"", stage[st], "\" pausing: ",
 		   &strerr_sys);
@@ -164,6 +181,14 @@ int main (int argc, const char * const *argv, const char * const *envp) {
 #endif
 	continue;
       }
+      /* console */
+      if ((ttyfd =open_write("/dev/console")) != -1) {
+	if (ioctl(ttyfd, TIOCSCTTY, (char *)NULL) != -1) {
+	  dup2(ttyfd, 0); dup2(ttyfd, 1); dup2(ttyfd, 2);
+	  if (ttyfd > 2)
+	    close(ttyfd);
+	}
+      }
       if (st != 1) {
 	strerr_warn2(WARNING, "signals only work in stage 2.", 0);
 	sigc =sigi =0;
@@ -250,6 +275,9 @@ int main (int argc, const char * const *argv, const char * const *envp) {
     }
   }
 
+  for (;;) {
+    sig_pause();
+  }
   /* not reached */
   strerr_die2x(0, INFO, "exit.");
   return(0);