Runlevel testing in init scripts

Richard Lightman richard at nezumi.plus.com
Tue Sep 10 12:40:25 PDT 2002


* DJ Lucas <dj_me at swbell.net> [2002-09-10 18:28]:
> 
> The testing is to simply make the init script more inteligent and not
> display anything in the start/stop cases if it is not supposed to be run.

There are a lot of things I do not like about sysvint. I tried
simpleinit, which in my opinion is a step in the right direction. MSB
fixed the bugs in depinit, but we have different ideas about what
an ideal init should do, so I made depinit:

http://www.nezumi.plus.com/depinit/

I think it does what you are after, but does things very differently
to the way normal inits work. Decide for you self if it is what you
want:


depinit reads a config file which contains start and stop commands
for various services and daemons, along with a dependancy list
for each service. Depinit starts by trying to start service 'default'.
On my system, default is:

default depend  login daemons extras


So depinit tries to start services 'login', 'daemons' and 'extras'.
login is:

login   depend  home utmp
login   daemon  agetty vc/3 38400 linux

As you might guess, depinit tries to start 'home' and 'utmp'.
'home' is:

home    start   mount  /home

So depinit runs "mount /home". If this completes without error, service
'home' is considered working. While this has been going on, depinit
has been working on service 'utmp', which involves mounting /var,
/var/run (a tmpfs), and creating an empty /var/run/utmp file. If
all that worked, depinit knows 'login' is ready to go, and runs
"agetty vc/3 38400 linux". If this runs for a while, depinit assumes
it is working. If the process dies, depinit will restart it (after
a short delay so that broken daemons to not eat up CPU time respawning
all the time).

You can control what is going on with things like:
depctl -k gpm    # Stop anything that relies on gpm, then stop gpm
                 # and do not restart it.
depctl -s gpm    # Start anything gpm depends on, and start gpm
depctl -TERM gpm # Send sigterm to gpm (it will probably die, then
                 # depinit will restart it)

gpm is:

gpm     depend  devfsd usr
gpm     daemon  gpm -D -m /dev/misc/psaux -t imps2 -a 3 -d 4 -3 -S "sync:depctl -H:depctl -Q"


Here is a more complicated one:

mail    depend  qmail   smtpd
qmail   depend  qmaill
smtpd   depend  smtpdl
qmaill  depend  ro rw network
smtpdl  depend  ro rw network
qmail   source  qmail-start ./Maildir/
qmaill  dest    setuidgid qmaill multilog t /var/log/multi/qmail
smtpd   source  tcpserver -p -v -u 11 -g 15 0 smtp qmail-smtpd
smtpdl  dest    setuidgid smtpdl multilog t /var/log/multi/smtpd


qmail is my mail delivery agent, and depinit starts it with a pipe
from stdout and stderr to stdin of qmaill, which creates timestamped
rotated logs of qmail's activity. The same sort of thing goes on
with my mail transport agent smtpd. Both can be stopped and started
with 'depctl -r mail' and 'depctl -s mail'. As depinit keeps the pipe
open,  the source or dest daemon can be killed and restarted and the
none of the log data will be lost (This idea is a blatant ripoff from
DJB's daemontools).

Depinit has timeouts for start commands and stop commands (thanks
to MSB for that idea). Depinit does not need to wait set amount
of time for kills to take effect (It keeps track of what needs to
die (by scanning /proc), and what has died (by catching SIGCHLD).
At present there is no 'shutdown later' command. 'depctl -Q', stops
everything, umounts (and detaches loops) (or remounts ro) everything
and turns the machine off (-q is similar but does a reset, and -H
halt).

You can find out what is going on:
# depctl -S default
default: state=0, target=0
        login: state=1, target=1
        daemons: state=0, target=0
        extras: state=1, target=1
# depctl -s default
# depctl -S default
default: state=1, target=1
        login: state=1, target=1
        daemons: state=1, target=1
        extras: state=1, target=1
#

Here is some of the output from depinit:

depinit: Started daemon 'syslogd'.
depinit: Started service 'secrets'.
depinit: Started service 'backup'.
depinit: Started service 'lfs'.
depinit: Started 'odd_fs'.
depinit: Started 'extras'.
depinit: Started service 'wall'.
depinit: Started service 'eth0'.
depinit: Started service 'e0conf'.
depinit: Started 'network'.
depinit: Started daemon 'dnscl'.
depinit: Started daemon 'tinylog'.
depinit: Started daemon 'qmaill'.
depinit: Started daemon 'smtpdl'.
depinit: Started daemon 'dnsc'.
depinit: Started daemon 'tinydns'.
depinit: Started 'dns'.
depinit: Started daemon 'qmail'.
depinit: Started daemon 'smtpd'.
depinit: Started 'mail'.
depinit: Started 'daemons'.
depinit: Started 'default'.
depinit: Stopped 'default'.
depinit: Stopped 'daemons'.
depinit: Stopped 'mail'.
depinit: Stopped daemon 'smtpd'.
depinit: Stopped daemon 'qmail'.
depinit: Started daemon 'qmail'.
depinit: Started daemon 'smtpd'.
depinit: Started 'mail'.
depinit: Started 'daemons'.
depinit: Started 'default'.

There are also messages when a service's start or stop command returns
an error, or takes too long, when processes not started by depinit
are killed (during shutdown), and when devices are un/re-mounted
(during shutdown).

I am currently looking at ways to make the timeouts configurable, and
handle daemons that do not detach from the terminal.

Richard
-- 
Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe lfs-chat' in the subject header of the message



More information about the lfs-chat mailing list