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

Re: Your mon / s-p-u upload



Hi,

Many apologies for letting this keep slipping down my to-do list.

On Thu, 2010-09-02 at 14:24 +0200, Dario Minnucci wrote:
> Hi again,
> 
> On 08/25/2010 08:53 PM, Adam D. Barratt wrote:
> > On Sun, 2010-07-18 at 17:33 +0200, Dario Minnucci wrote:
[...]
> >> +case "$1" in
> >> +  start)
> >> +       if [ -f $PIDFILE ] ; then
> >> +               echo "$NAME daemon is already running." 
> >> +       else
> >> +               start_deamon
> >> +       fi
> > 
> > The short-circuit case should be removed here; the existence of the
> > pidfile does not imply that the daemon is (still) running and your
> > start-stop-daemon call in start_daemon() already handles exiting
> > successfully if the daemon is in fact running.
> > 
> I've tried what you suggest here but if I don't check for the
> existence of the PID file and the
> daemon is already running, starting it again fails.
> 
> root@host:~# /etc/init.d/mon start ; echo $?
> Starting monitor daemon: 1

A little debugging this evening suggests that this is a side-effect of
mon being a perl script.

On the first call to the init script, s-s-d checks that the PID file
does not exist, and that there are no processes called "/usr/sbin/mon"
running and duly starts one.  On the second time around, it finds the
PID file and continues to check whether any instances of /usr/sbin/mon
exist; they don't, as what's actually running is
"/usr/bin/perl /usr/sbin/mon ...".  So it tries starting a second mon
instance, which itself "exit 1"s as it's unable to bind to the port,
which is occupied by the first instance.

Changing --exec to --startas avoids this problem, although it doesn't
rule out the possibility that the daemon has crashed and another process
is then using the PID mentioned in the PID file.  Then again,
stop_daemon() isn't using --exec anyway, so the script is already happy
to stop whatever process happens to be on that PID.

Regards,

Adam


Reply to: