[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: LSB-ize daemon without pidfile handling

On Thu, Nov 08, 2007 at 09:36:24PM +0100, Marc Haber wrote:
> Hi,
> ser2net, a small daemon in a package maintained by me, cannot write
> its own pidfile. Since it forks and detaches by default,
> start-stop-daemon's --make-pidfile option is of no use as well, since
> the daemon that ends up running has a different pid than s-s-d's
> child.
> Before, I started that daemon with
> s-s-d --background --make-pidfile --exec $DAEMON -- -n,
> with -n being its option for "do not fork and background yourself".
> While I do not find this particularly elegant (is there any better
> way?),

As Hamish said: patch the source. Writing a PID file is not particularly
hard. From nbd-server:

	pidf=fopen(pidfname, "w");
	if(pidf) {
		fprintf(pidf, "%d\n", (int)getpid());
	} else {
		/* error handling; if not running as root, probably a
		 * permission issue or so */

and that's really it. Of course, you should add this after the daemon()
or fork() call in your program, otherwise it won't really help ;-)

> it precludes me from using /lib/lsb/init-function's
> start_daemon function as start_daemon is not able to pass arbitrary
> options to s-s-d, and there is no option to invoke --background
> --make-pidfile.
> How am I supposed to properly lsb-ize ser2net's init script? Is it ok
> to directly call s-s-d from the init script or do I need other
> workarounds?

Reading through init-functions:

log_daemon_msg "Starting Foo Daemon" "foo"
start-stop-daemon --whatever --you --want --here
log_end_msg 0

<Lo-lan-do> Home is where you have to wash the dishes.
  -- #debian-devel, Freenode, 2004-09-22

Reply to: