runit

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 0f0e3ba5fdc471d2489780e902ae1af90cfc5c8c
parent a08a964f58c0b144cfdde687a6c3845cbf0ccfa5
Author: Gerrit Pape <pape@smarden.org>
Date:   Sat, 22 Dec 2001 19:40:20 +0000

runit: checks for pid == 1
new: svwaitdown, svwaitup
stage3: uses svwaitdown
0.2.2
debian package

Diffstat:
MMakefile | 2+-
Mdebian/changelog | 6++++++
Mdebian/postinst | 2+-
Mdebian/rules | 44++++++++++++++++++++++----------------------
Mdoc/install.html | 10+++++-----
Mdoc/replaceinit.html | 2+-
Metc/debian/3 | 3++-
Mpackage/CHANGES | 6++++++
Mpackage/upgrade | 4++--
Msrc/Makefile | 10+++++++++-
Msrc/TARGETS | 4++++
Msrc/runit.c | 4++++
Asrc/svwaitdown.c | 131+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/svwaitup.c | 131+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14 files changed, 325 insertions(+), 34 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,6 +1,6 @@ DESTDIR= -PACKAGE=runit-0.2.0 +PACKAGE=runit-0.2.2 DIRS=doc man etc package src MANPAGES=man/runit.8 man/runit-init.8 DAEMONTOOLS_PD=daemontools-pd-0.76 diff --git a/debian/changelog b/debian/changelog @@ -1,3 +1,9 @@ +runit (0.2.2-1) woody; urgency=low + + * See /package/admin/runit/package/CHANGES. + + -- Gerrit Pape <pape@smarden.org> Sat, 22 Dec 2001 20:37:03 +0100 + runit (0.1.1-1) woody; urgency=low * Initial Release. diff --git a/debian/postinst b/debian/postinst @@ -25,7 +25,7 @@ set -e case "$1" in configure) ( \ - cd /package/admin/runit-0.2.0 + cd /package/admin/runit-0.2.2 package/upgrade ) ;; diff --git a/debian/rules b/debian/rules @@ -24,18 +24,18 @@ build-stamp: # $(MAKE) #/usr/bin/docbook-to-man debian/runit.sgml > runit.1 - tar xfzvp runit-0.2.0.tar.gz - mkdir -p admin/runit-0.2.0/compile + tar xfzvp runit-0.2.2.tar.gz + mkdir -p admin/runit-0.2.2/compile tar xfzvp daemontools-pd-0.76.tar.gz \ - -C admin/runit-0.2.0/compile - ( cd admin/runit-0.2.0/compile ; \ + -C admin/runit-0.2.2/compile + ( cd admin/runit-0.2.2/compile ; \ ln -s daemontools-pd-0.76 support ) ( \ - cd admin/runit-0.2.0 ; \ + cd admin/runit-0.2.2 ; \ package/compile ; \ - echo "/package/admin/runit-0.2.0" > compile/home ; \ + echo "/package/admin/runit-0.2.2" > compile/home ; \ rm -f compile/src ; \ - ln -s /package/admin/runit-0.2.0/src compile/src ; \ + ln -s /package/admin/runit-0.2.2/src compile/src ; \ ) touch build-stamp @@ -62,40 +62,40 @@ install: build chmod 1755 debian/runit/package cp -a admin debian/runit/package/ - rm -rf debian/runit/package/admin/runit-0.2.0/compile - cp -a debian/runit/package/admin/runit-0.2.0/man . - rm -rf debian/runit/package/admin/runit-0.2.0/man - cp -a debian/runit/package/admin/runit-0.2.0/doc . - rm -rf debian/runit/package/admin/runit-0.2.0/doc - cp -a debian/runit/package/admin/runit-0.2.0/etc . - rm -rf debian/runit/package/admin/runit-0.2.0/etc - cp -a debian/runit/package/admin/runit-0.2.0/package . + rm -rf debian/runit/package/admin/runit-0.2.2/compile + cp -a debian/runit/package/admin/runit-0.2.2/man . + rm -rf debian/runit/package/admin/runit-0.2.2/man + cp -a debian/runit/package/admin/runit-0.2.2/doc . + rm -rf debian/runit/package/admin/runit-0.2.2/doc + cp -a debian/runit/package/admin/runit-0.2.2/etc . + rm -rf debian/runit/package/admin/runit-0.2.2/etc + cp -a debian/runit/package/admin/runit-0.2.2/package . # /etc/runit - cp -p admin/runit-0.2.0/etc/debian/[123] \ + cp -p admin/runit-0.2.2/etc/debian/[123] \ debian/runit/etc/runit/ - cp -p admin/runit-0.2.0/etc/debian/ctrlaltdel \ + cp -p admin/runit-0.2.2/etc/debian/ctrlaltdel \ debian/runit/etc/runit/ - cp -p admin/runit-0.2.0/etc/debian/getty-tty5/run \ + cp -p admin/runit-0.2.2/etc/debian/getty-tty5/run \ debian/runit/etc/runit/getty-tty5 # runit programs - cp -p debian/runit/package/admin/runit-0.2.0/command/runit* \ + cp -p debian/runit/package/admin/runit-0.2.2/command/runit* \ debian/runit/sbin/ # cleanup - rm -rf debian/runit/package/admin/runit-0.2.0/compile + rm -rf debian/runit/package/admin/runit-0.2.2/compile # create debian/links rm -f debian/links for i in \ - `cat debian/runit/package/admin/runit-0.2.0/package/commands` ; \ + `cat debian/runit/package/admin/runit-0.2.2/package/commands` ; \ do \ echo "/package/admin/runit/command/$$i /command/$$i" \ >> debian/links ; \ done # for i in \ -# `cat debian/runit/package/admin/runit-0.2.0/package/commands` ; \ +# `cat debian/runit/package/admin/runit-0.2.2/package/commands` ; \ # do \ # echo "/command/$$i /usr/local/bin/$$i" \ # >> debian/links ; \ diff --git a/doc/install.html b/doc/install.html @@ -13,14 +13,14 @@ Check that you have the recent version of <a href="http://cr.yp.to/daemontools.html">daemontools</a> installed. <p> Download -<a href="runit-0.2.0.tar.gz">runit-0.2.0.tar.gz</a> into <tt>/package</tt> +<a href="runit-0.2.2.tar.gz">runit-0.2.2.tar.gz</a> into <tt>/package</tt> and unpack the archive <pre> # cd /package - # gunzip runit-0.2.0.tar - # tar -xpf runit-0.2.0.tar - # rm runit-0.2.0.tar - # cd admin/runit-0.2.0 + # gunzip runit-0.2.2.tar + # tar -xpf runit-0.2.2.tar + # rm runit-0.2.2.tar + # cd admin/runit-0.2.2 </pre> Compile and install the <i>runit</i> programs <pre> diff --git a/doc/replaceinit.html b/doc/replaceinit.html @@ -102,7 +102,7 @@ default Unix process no 1 <i>runit</i>. </pre> To report success: <pre> - # ( uname -a ; cat /etc/runit/[123] ) | mail pape-runit-0.2.0@smarden.org + # ( uname -a ; cat /etc/runit/[123] ) | mail pape-runit-0.2.2@smarden.org </pre> <hr> <address><a href="mailto:pape@smarden.org"> diff --git a/etc/debian/3 b/etc/debian/3 @@ -5,7 +5,8 @@ test -r /etc/runit/reboot && LAST=6 echo 'Stopping services...' /command/svc -d /service/* -/bin/sleep 5 +/command/svwaitdown /service/* || ( echo 'Killing services...' ; \ + /command/svc -k /service/* ) echo 'Stopping log services...' /command/svc -d /service/*/log /bin/sleep 5 diff --git a/package/CHANGES b/package/CHANGES @@ -1,3 +1,9 @@ +runit 0.2.2 +Sat, 22 Dec 2001 20:37:03 +0100 + * runit: checks for pid == 1 + * new: svwaitdown, svwaitup + * stage3: uses svwaitdown + runit 0.2.0 Mon, 26 Nov 2001 12:29:44 +0100 * runit-halt, runit-reboot removed, integrated into runit-init diff --git a/package/upgrade b/package/upgrade @@ -7,9 +7,9 @@ test -d src || ( echo 'Wrong working directory.'; exit 1 ) here=`env - PATH=$PATH pwd` parent=`dirname $here` -echo 'Creating symlink runit -> runit-0.2.0...' +echo 'Creating symlink runit -> runit-0.2.2...' rm -f runit -ln -s runit-0.2.0 runit +ln -s runit-0.2.2 runit mv -f runit .. echo 'Making command links in /command...' diff --git a/src/Makefile b/src/Makefile @@ -5,7 +5,7 @@ CC=gcc CFLAGS=-Wall -O3 -Isupport LDFLAGS=-Wall -O3 -s -all: runit runit-init +all: runit runit-init svwaitup svwaitdown set-tcp-env: djb-publicdomain set-tcp-env.o $(CC) $(LDFLAGS) -o set-tcp-env \ @@ -19,6 +19,14 @@ runit-init: djb-publicdomain init.o $(CC) $(LDFLAGS) -o runit-init \ init.o support/unix.a support/byte.a +svwaitup: djb-publicdomain svwaitup.o + $(CC) $(LDFLAGS) -o svwaitup \ + svwaitup.o support/unix.a support/byte.a support/time.a + +svwaitdown: djb-publicdomain svwaitdown.o + $(CC) $(LDFLAGS) -o svwaitdown \ + svwaitdown.o support/unix.a support/byte.a support/time.a + djb-publicdomain: ( cd support ; make ) diff --git a/src/TARGETS b/src/TARGETS @@ -2,3 +2,7 @@ runit runit.o runit-init init.o +svwaitdown +svwaitdown.o +svwaitup +svwaitup.o diff --git a/src/runit.c b/src/runit.c @@ -55,6 +55,10 @@ int main (int argc, const char * const *argv, const char * const *envp) { iopause_fd x; char ch; + if (getpid() != 1) { + strerr_die2x(111, FATAL, "must be run as process no 1."); + } + setsid(); sig_block(sig_alarm); diff --git a/src/svwaitdown.c b/src/svwaitdown.c @@ -0,0 +1,131 @@ +/* + in /package/admin/daemontools/compile/ : + gcc -Wall -c svwaitdown.c && \ + gcc -o svwaitdown svwaitdown.o unix.a byte.a time.a + + Gerrit Pape <pape@smarden.org> +*/ + +#include <unistd.h> +#include "strerr.h" +#include "error.h" +#include "sgetopt.h" +#include "scan.h" +#include "open.h" +#include "tai.h" +#include "buffer.h" + +#define FATAL "svwaitdown: fatal: " +#define WARNING "svwaitdown: warning: " +#define INFO "svwaitdown: info: " +#define USAGE " [ -v ] [ -t 2..6000 ] service ..." + +const char *progname; +const char * const *dir; +unsigned int rc; + +void usage () { + strerr_die4x(1, "usage: ", progname, USAGE, "\n"); +} + +void warn (const char *s1, const char *s2, struct strerr *e) { + dir++; + rc++; + strerr_warn3(WARNING, s1, s2, e); +} + +int main (int argc, const char * const *argv) { + int opt; + unsigned long sec =600; + int verbose =0; + int fd; + char status[18]; + int r; + unsigned long pid; + struct tai start; + struct tai now; + + progname =*argv; + + while ((opt =getopt(argc, argv, "t:vV")) != opteof) { + switch(opt) { + case 't': + scan_ulong(optarg, &sec); + if ((sec < 2) || (sec > 600)) { + usage(); + } + break; + case 'v': + verbose =1; + break; + case 'V': + strerr_warn1("$Id", 0); + case '?': + usage(); + } + } + argv +=optind; + if (! argv || ! *argv) { + usage(); + } + + dir =argv; + tai_now(&start); + + while (*dir) { + if (chdir(*dir) == -1) { + warn(*dir, ": unable to change directory: ", &strerr_sys); + continue; + } + + fd = open_write("supervise/ok"); + if (fd == -1) { + if (errno == error_nodevice) { + if (verbose) strerr_warn3(INFO, *dir, ": supervise not running.", 0); + dir++; + } + else + warn(*dir, ": unable to open supervise/ok: ", &strerr_sys); + continue; + } + close(fd); + + fd = open_read("supervise/status"); + if (fd == -1) { + warn(*dir, "unable to open supervise/status: ", &strerr_sys); + continue; + } + r = buffer_unixread(fd, status, sizeof status); + close(fd); + if (r < sizeof status) { + if (r == -1) + warn(*dir, "unable to read supervise/status: ", &strerr_sys); + else + warn(*dir, ": unable to read supervise/status: bad format.", 0); + continue; + } + + pid = (unsigned char) status[15]; + pid <<= 8; pid += (unsigned char) status[14]; + pid <<= 8; pid += (unsigned char) status[13]; + pid <<= 8; pid += (unsigned char) status[12]; + if (! pid) { + /* ok, service is down */ + if (verbose) strerr_warn3(INFO, *dir, ": down.", 0); + dir++; + continue; + } + + tai_now(&now); + tai_sub(&now, &now, &start); + if (tai_approx(&now) >= sec) { + /* timeout */ + if (verbose) strerr_warn2(INFO, "timeout.", 0); + exit(111); + } + + sleep(1); + } + if (rc > 100) rc =100; + exit(rc); +} diff --git a/src/svwaitup.c b/src/svwaitup.c @@ -0,0 +1,131 @@ +/* + in /package/admin/daemontools/compile/ : + gcc -Wall -c svwaitup.c && gcc -o svwaitup svwaitup.o unix.a byte.a time.a + + Gerrit Pape <pape@smarden.org> +*/ + +#include <unistd.h> +#include "strerr.h" +#include "error.h" +#include "sgetopt.h" +#include "scan.h" +#include "open.h" +#include "tai.h" +#include "buffer.h" + +#define FATAL "svwaitup: fatal: " +#define WARNING "svwaitup: warning: " +#define INFO "svwaitup: info: " +#define USAGE " [ -s 2..600 ] service ..." + +const char *progname; +unsigned long sec; +unsigned int rc =0; +const char * const *dir; + +void usage () { + strerr_die4x(1, "usage: ", progname, USAGE, "\n"); +} + +void warn (const char *s1, const char *s2, struct strerr *e) { + dir++; + rc++; + strerr_warn3(WARNING, s1, s2, e); +} + +int main (int argc, const char * const *argv) { + int opt; + unsigned long sec =2; + int verbose =0; + char status[18]; + int fd; + int is; + int r; + unsigned long pid; + struct tai when; + struct tai now; + + progname =*argv; + + while ((opt =getopt(argc, argv, "s:vV")) != opteof) { + switch(opt) { + case 's': + scan_ulong(optarg, &sec); + if ((sec < 2) || (sec > 600)) { + usage(); + } + break; + case 'v': + verbose =1; + break; + case 'V': + strerr_warn1("$Id", 0); + case '?': + usage(); + } + } + argv +=optind; + if (! argv || ! *argv) { + usage(); + } + + dir =argv; + + while (*dir) { + if (chdir(*dir) == -1) { + warn(*dir, ": unable to change directory: ", &strerr_sys); + continue; + } + + fd = open_write("supervise/ok"); + if (fd == -1) { + if (errno == error_nodevice) + warn(*dir, ": supervise not running.", 0); + else + warn(*dir, ": unable to open supervise/ok: ", &strerr_sys); + continue; + } + close(fd); + + fd = open_read("supervise/status"); + if (fd == -1) { + warn(*dir, "unable to open supervise/status: ", &strerr_sys); + continue; + } + r = buffer_unixread(fd, status, sizeof status); + close(fd); + if (r < sizeof status) { + if (r == -1) + warn(*dir, "unable to read supervise/status: ", &strerr_sys); + else + warn(*dir, ": unable to read supervise/status: bad format.", 0); + continue; + } + + pid = (unsigned char) status[15]; + pid <<= 8; pid += (unsigned char) status[14]; + pid <<= 8; pid += (unsigned char) status[13]; + pid <<= 8; pid += (unsigned char) status[12]; + if (! pid) { + warn(*dir, ": is down.", 0); + continue; + } + + tai_unpack(status, &when); + tai_now(&now); + if (tai_less(&now, &when)) when =now; + tai_sub(&when, &now, &when); + is =tai_approx(&when); + + if (is >= sec) { + /* ok */ + if (verbose) strerr_warn3(INFO, *dir, ": is up.", 0); + dir++; + continue; + } + sleep(sec -is); + } + if (rc > 100) rc =100; + exit(rc); +}