First Last Prev Next    No search results available      Search page      Enter new bug
Bug#: 143951
Alias:
Product:
Component:
Status: RESOLVED
Resolution: FIXED
Assigned To: Gentoo's Team for Core System packages <base-system@gentoo.org>
Hardware:
OS:
Version:
Priority:
Severity:
Reporter: Dustin J. Mitchell <dustin@v.igoro.us>
Add CC:
CC:
Remove selected CCs
URL:
Summary:
Status Whiteboard:
Keywords:

Filename Description Type Creator Created Size Actions
rc-daemon.patch patch to /lib/rcscripts/sh/rc-daemon.sh to use ${name} as the manpage says it will patch Dustin J. Mitchell 2006-08-15 12:35 0000 3.27 KB Details | Diff
x smaller patch patch Roy Marples (RETIRED) 2006-08-15 13:38 0000 1.01 KB Details | Diff
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 143951 depends on: Show dependency tree
Bug 143951 blocks:
Votes: 0    Show votes for this bug    Vote for this bug

Additional Comments: (this is where you put emerge --info)


Not eligible to see or edit group visibility for this bug.






View Bug Activity   |   Format For Printing   |   XML   |   Clone This Bug


Description:   Opened: 2006-08-14 16:30 0000
I have an (in-house) daemon where my initscript does the following:

- uses start-stop-daemon to start a shell script which
- performs some initialization and
- exec's a python script which
- performs some initialization and
- changes its name from 'python /path/to/foo.py' to 'foo'

thus, the same PID will be '/bin/bash /path/to/wrapper', then 'python
/path/to/foo', then 'foo' at fairly unpredictable times.  This was fine with
the previous version of baselayout (in fact, we didn't do the last name-change
-- it was added to try to fix this), but produces a race condition with this
version.

Specifically, if I use "--name foo" in the s-s-d invocation, then *if* the
daemon gets to its name-changing within the one second allowed by
rc_start_daemon, things will work.  Otherwise, s-s-d kills the nascent daemon.

It seems that start-stop-daemon should be configurable to look *only* at the
PID of the daemon it's starting, for cases just like this one.  Other options
might be allowing the wait-for-name-stabilization timeout to be configurable (a
la RC_RETRY_TIMEOUT/RC_RETRY_COUNT).

I'd appreciate either an idea on how to fix this or a suggestion of a
future-portable way for me to fix my  app.

------- Comment #1 From Roy Marples (RETIRED) 2006-08-15 03:06:37 0000 -------
(In reply to comment #0)
> - uses start-stop-daemon to start a shell script which
> - performs some initialization and
> - exec's a python script which
> - performs some initialization and
> - changes its name from 'python /path/to/foo.py' to 'foo'

start-stop-daemon starts and stops daemons, not shell scripts. If you have a
shell script that does initialisation, and then called another script (ie
python) why even use start-stop-daemon?

> 
> thus, the same PID will be '/bin/bash /path/to/wrapper', then 'python
> /path/to/foo', then 'foo' at fairly unpredictable times.  This was fine with
> the previous version of baselayout (in fact, we didn't do the last name-change
> -- it was added to try to fix this), but produces a race condition with this
> version.

s-s-d now monitors daemons started and stopped so we know if a daemon exited
when it shouldn't have done.

------- Comment #2 From Dustin J. Mitchell 2006-08-15 12:34:27 0000 -------
s-s-d has the advantage of tight integration with the Gentoo initscripts, which
is helpful.  I took the time to rewrite the Python scripts as daemons (using
e.g., http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731).

The scripts are invoked as e.g., '/lib/daemons/bin/foobar', but run with the
following in /proc/*/cmdline:
 python /lib/daemons/bin/foobar --daemonize=TRUE
--daemon-log-file=/var/log/foobar_daemon.log --pid-file=/var/run/foobar.pid
/proc/*/stat contains 'python2.4'. 

It would seem from the manual page that s-s-d will use --name as the argument
to 'pidof':
       -n|--name process-name
              Check for processes with the name process-name (according to
/proc/ pid /stat ).
yet in /lib/rcscripts/sh/rc-daemon.sh, rc_start_daemon calls is_daemon_running
with ${cmd}, not ${name}, meaning that it runs 'pidof /lib/daemons/bin/foobar',
which it does not find.  I consider this latter circumstance a bug, though
admittedly not the bug I had originally reported.  I've attached a patch to fix
it.

With this patch in place, and with a change to my daemon such that it changes
its cmdline and stat to 'foo', I can effectively use

  start-stop-daemon ... --name foobar --startas /lib/daemons/bin/foobar

to control the daemon.  Without this patch, I must use:

  start-stop-daemon --startas python -- /lib/daemons/bin/foobar

which is obviously less than ideal if there are multiple python-based daemons.

I'm sorry this took me a while to get around to the central problem -- it's
rather new territory to me.

------- Comment #3 From Dustin J. Mitchell 2006-08-15 12:35:10 0000 -------
Created an attachment (id=94344) [edit]
patch to /lib/rcscripts/sh/rc-daemon.sh to use ${name} as the manpage says it
will

------- Comment #4 From Roy Marples (RETIRED) 2006-08-15 13:38:38 0000 -------
Created an attachment (id=94347) [edit]
smaller patch

I cannot fault your argument, and thanks for the patch :)

This patch is smaller and less intrusive but should achieve the same thing.
Please test that it works for you.

------- Comment #5 From Dustin J. Mitchell 2006-08-15 14:24:09 0000 -------
Looks great -- thanks!

------- Comment #6 From Roy Marples (RETIRED) 2006-08-15 14:45:58 0000 -------
Fixed in baselayout-1.12.4-r6 :)

------- Comment #7 From Erik Wasser 2006-09-06 04:01:08 0000 -------
Sorry I don't get the solution for this problem here. Since the upgrade s-s-d
failed to start my perl daemon. I use the following line:

start-stop-daemon --start --quiet --pidfile /var/run/xrd.pid \
--exec /usr/sbin/xrd.pl -- --daemonize

The '/usr/sbin/xrd.pl' is a perl daemon which changes its name to 'xrd' and
forks into the background.

'/etc/init.d/iqadm-xrd' fails to start the daemon but entering the above
command directly will work. Two thinks are worth mentioning:

a) Why the difference between the command in the startup script and the command
on the command line?

b) Why is the start of the service failing? An better explanation would be
useful here: 'Failed to start xrd' is a little bit (too) short. B-)

------- Comment #8 From Roy Marples (RETIRED) 2006-09-06 07:33:01 0000 -------
(In reply to comment #7)
> Sorry I don't get the solution for this problem here. Since the upgrade s-s-d
> failed to start my perl daemon. I use the following line:
> 
> start-stop-daemon --start --quiet --pidfile /var/run/xrd.pid \
> --exec /usr/sbin/xrd.pl -- --daemonize
> 
> The '/usr/sbin/xrd.pl' is a perl daemon which changes its name to 'xrd' and
> forks into the background.

So use the --name directive

> '/etc/init.d/iqadm-xrd' fails to start the daemon but entering the above
> command directly will work. Two thinks are worth mentioning:
> 
> a) Why the difference between the command in the startup script and the command
> on the command line?
> 
> b) Why is the start of the service failing? An better explanation would be
> useful here: 'Failed to start xrd' is a little bit (too) short. B-)

init scripts have a bash wrapper around s-s-d to check the daemon in question
really did start and not bail through a configuration issue. The downside is
that you now need to use the --name directive for some perl/python/bash
scripts.

First Last Prev Next    No search results available      Search page      Enter new bug