start-stop daemon

Gerard Beekmans gerard at linuxfromscratch.org
Mon Apr 21 10:42:05 PDT 2003


On April 20, 2003 04:33 am, Michael A. Peters wrote:
> I'm curious as to the reason it no longer does.

One less package to use. pidof is installed in most cases anyways and it can 
be told to work properly, read on...

> reinstall it) and then you try to manually restart it. The problem is
> that getpids() sees the init script itself and reports that it is
> already running.

In the LFS bootscripts, pidof is run like this:
	pidof -o $$ -o $$PID

The -o options ignore certain PID's. As you may be aware $$ is the PID of the 
process itself (the bash shell in which the init.d/functions script runs in 
this case) and $PPID ignores the parent PID of the functions script, which is 
init.d/scriptname (init.d/sshd init.d/myservice, and so on).

Allow me to back this up with some proof. Plain vanilla LFS bootscripts:

SSHD is not running:

	root at lorien/etc/rc.d/init.d# ps ax|grep ssh
	root at lorien/etc/rc.d/init.d# 

Now trying to start it:

	root at lorien/etc/rc.d/init.d# ./sshd start
	Starting SSHD...                                                     [  OK  ]

And let's try again:

	root at lorien/etc/rc.d/init.d# ./sshd start
	Starting SSHD...                                 Already running     [ ATTN ]


I'm editing the "getpids()" function in the "functions" script. Originally it 
contained:
	pidlist=$(pidof -o $$ -o $PPID -x $base)

After editing:
	pidlist=$(pidof -x $base)

SSHD is not running:

	root at lorien/etc/rc.d/init.d# ps ax|grep ssh
	root at lorien/etc/rc.d/init.d# 

Trying to start it:

	root at lorien/etc/rc.d/init.d# ./sshd start 
	Starting SSHD...                                 Already running     [ ATTN ]

So as you can see, when the "-o $$" and "-o $PPID" options aren't used, pidof 
will include the PID of the calling script itself and tell you it's already 
running. When those two -o options are used, the calling script and its 
parent are ignored, so it will only look at the remaining PIDs you want it to 
look at.

Is it possible you aren't used the pidof program from the sysvinit package? If 
not, that might explain the problem you are having. Matthias did a lot of 
research on the different pidof and init implementations. IIRC he arived at 
the conclusion that sysvinit's pidof is better (and thus he includes 
sysvinit's tools in this own simpleinit-msb package for that reason). There 
are test cases by Matthias in the archives of this mailinglist, somewhere.

> I though that perhaps using the full path with loadproc() would solve
> the issue. It doesn't. So - I'm curious as to what the reason is that

It doesn't. The functions script use 'basename' to strip this path. The full 
path is not always preserved in /proc/<pid>/cmdline (I believe it's the 
cmdline file at any rate, I can be wrong of course) so it's not very useful.

> the (imho better) debian start-stop daemon is no longer used. Especially
> when the man page for pidof recommends against it use in init scripts.

The reason is that we honestly don't believe it's necessary.

-- 
Gerard Beekmans
www.linuxfromscratch.org

-*- If Linux doesn't have the solution, you have the wrong problem -*-
-- 
Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe lfs-dev' in the subject header of the message



More information about the lfs-dev mailing list