I believe this patch could resolve issues linked to bugs #446793, #484022 and #448524 . Patched init script seems to be able to handle missing or wrong PIDFILE and also already started/stopped daemon.
I'm not completly confident in the LSB log functions order/usage but the script behaves well for all the issue found in the three bugs mentionned above. Patch: --- thttpd.orig 2009-06-13 01:04:03.000000000 +0200 +++ thttpd 2009-06-13 01:06:13.000000000 +0200 @@ -12,57 +12,105 @@ # Description: thttpd is a small, fast secure webserver. ### END INIT INFO -PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin -DAEMON=/usr/sbin/thttpd -DESC="web server" -NAME=thttpd +set -e + +DAEMON='/usr/sbin/thttpd' +DESC='web server' +NAME=`basename "$DAEMON"` -CONFFILE=/etc/thttpd/thttpd.conf -PIDFILE=/var/run/thttpd.pid +CONFFILE='/etc/thttpd/thttpd.conf' +PIDFILE='/var/run/thttpd.pid' OPTIONS="-C $CONFFILE -i $PIDFILE" -test -x $DAEMON || exit 0 -test -f $CONFFILE || exit 1 +test -x "$DAEMON" || exit 0 +test -f "$CONFFILE" || exit 1 -set -e +. /lib/lsb/init-functions + +daemon_present() { + PID="$1" + if [ "$PID" ]; then + start-stop-daemon -K -q -p "$PID" -x "$DAEMON" -s 0 -- $OPTIONS + else + start-stop-daemon -K -q -x "$DAEMON" -s 0 -- $OPTIONS + fi +} + +do_start() { + PID_REMOVED=0 + if [ -f "$PIDFILE" ]; then + if daemon_present "$PIDFILE" ; then + log_progress_msg "already running" + log_end_msg 0 + return 0 + fi + rm -f "$PIDFILE" + PID_REMOVED=1 + fi + if daemon_present ; then + log_progress_msg "already running" + log_end_msg 0 + else + set +e + start-stop-daemon -S -q -p "$PIDFILE" -x "$DAEMON" -- $OPTIONS + set -e + log_end_msg $? || true + fi + [ $PID_REMOVED -eq 1 ] && log_warning_msg "removed stale PID file" +} + +do_stop() { + SIGNAL=$1 + SIGNAL=${SIGNAL:-'USR1'} + if [ -f "$PIDFILE" ]; then + if daemon_present "$PIDFILE" ; then + set +e + start-stop-daemon -K -q -p "$PIDFILE" -x "$DAEMON" --signal "$SIGNAL" + set -e + log_end_msg $? || true + rm -f "$PIDFILE" + return 0 + fi + fi + if daemon_present; then + set +e + start-stop-daemon -K -q -x "$DAEMON" --signal "$SIGNAL" + set -e + log_end_msg $? || true + else + log_progress_msg "already stopped" + log_end_msg 0 + fi + if [ -f "$PIDFILE" ]; then + rm -f "$PIDFILE" + log_warning_msg "removed stale PID file" + fi +} case "$1" in start) - echo -n "Starting $DESC: " - start-stop-daemon -S -q -p $PIDFILE -x $DAEMON -- $OPTIONS - echo "$NAME." + log_daemon_msg "Starting" "$NAME" + do_start ;; stop) - echo -n "Stopping $DESC: " - - if ps ax | grep "$(cat $PIDFILE)" | grep -qv grep - then - start-stop-daemon -K -q -p $PIDFILE -x $DAEMON --signal 10 - fi - - echo "$NAME." + log_daemon_msg "Stopping" "$NAME" + do_stop ;; force-stop) - echo -n "Stopping $DESC: " - start-stop-daemon -K -q -p $PIDFILE -x $DAEMON - echo "$NAME." + log_daemon_msg "Stopping (forced)" "$NAME" + do_stop TERM ;; force-reload) - if start-stop-daemon -K -q -p $PIDFILE -x $DAEMON --test - then - $0 restart - fi + $0 restart ;; restart) - echo -n "Restarting $DESC: " - start-stop-daemon -K -q -p $PIDFILE -x $DAEMON --signal 10 + $0 stop sleep 1 - start-stop-daemon -S -q -p $PIDFILE -x $DAEMON -- $OPTIONS - echo "$NAME." + $0 start ;; *) Regards, -- Rémi Laurent GPG Key ID/Fingerprint: 1024D/0FA00601 27F4 6810 2B0E 1AA0 CDAE 7C7B 3DC9 085A 0FA0 0601
signature.asc
Description: Digital signature