Hi Team, Sorry for taking soooo long.... On 11/01/2010 10:57 PM, Adam D. Barratt wrote: > 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 > Debdiff attached. I've modified the init script to use --startas and seems it works as expected. Please, let me know if is possible to upload this s-p-u. Regards, -- Dario Minnucci <midget@debian.org> Phone: +34 902021030 | Fax: +34 902024417 Key fingerprint = BAA1 7AAF B21D 6567 D457 D67D A82F BB83 F3D5 7033
diff -u mon-0.99.2/debian/mon.init.d mon-0.99.2/debian/mon.init.d --- mon-0.99.2/debian/mon.init.d +++ mon-0.99.2/debian/mon.init.d @@ -44,16 +44,30 @@ set -e -case "$1" in - start) + +function start_deamon { echo -n "Starting $DESC: " - start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $USER --group $GROUP --exec $DAEMON -- $DAEMON_OPTS + start-stop-daemon --start --oknodo --pidfile $PIDFILE --chuid $USER --group $GROUP --startas $DAEMON -- $DAEMON_OPTS echo "$NAME." - ;; - stop) +} +function stop_daemon { echo -n "Stopping $DESC: " - start-stop-daemon --stop --quiet --pidfile $PIDFILE + start-stop-daemon --stop --oknodo --pidfile $PIDFILE echo "$NAME." +} + + + +case "$1" in + start) + if [ -f $PIDFILE ] ; then + echo "$NAME daemon is already running." + else + start_deamon + fi + ;; + stop) + stop_daemon ;; #reload) # @@ -75,16 +89,14 @@ # daemon isn't already running. # check wether $DAEMON is running. If so, restart start-stop-daemon --stop --test --quiet --pidfile \ - $PIDFILE --exec $DAEMON \ + $PIDFILE --startas $DAEMON \ && $0 restart \ || exit 0 ;; restart) - echo -n "Restarting $DESC: " - start-stop-daemon --stop --quiet --pidfile $PIDFILE - sleep 1 - start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $USER --group $GROUP --exec $DAEMON -- $DAEMON_OPTS - echo "$NAME." + stop_daemon + sleep 1 + start_deamon ;; *) N=/etc/init.d/$NAME diff -u mon-0.99.2/debian/changelog mon-0.99.2/debian/changelog --- mon-0.99.2/debian/changelog +++ mon-0.99.2/debian/changelog @@ -1,3 +1,10 @@ +mon (0.99.2-13+lenny1) stable-proposed-updates; urgency=low + + * debian/mon.init.d: Script fixes to return success when daemon + is restarted but is already running. (Closes: #538133) + + -- Dario Minnucci <midget@debian.org> Sun, 18 Jul 2010 17:09:04 +0200 + mon (0.99.2-13) unstable; urgency=low * debian/control: Conforms with latest Standards Version 3.8.0
Attachment:
signature.asc
Description: OpenPGP digital signature