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

[PATCH] save-logs: avoid running more than one



I think the patch below will safely stop a running httpd server without
the risk of races from nc restarting at every hit.

Please review before I commit.

Cheers,
Frans


Index: debian/save-logs.postinst
===================================================================
--- debian/save-logs.postinst   (revision 28046)
+++ debian/save-logs.postinst   (working copy)
@@ -48,9 +48,19 @@
        ln -sf /etc/lsb-release /var/log
        ln -sf /var/lib/dpkg/status /var/log
        ln -sf /usr/share/save-logs/install-report.template /var/log
-       # TODO: avoid running more than one
+
+       # Kill existing server if one is already running
+       touch /var/lib/httpd_stop # Block new listener processes from starting
+       sleep 1
+       for PID in $(pidof nc); do
+               if grep -q "httpd" /proc/$PID/cmdline ; then
+                       # The server may already have gone if hit
+                       kill $PID 2>/dev/null || true
+               fi
+       done
+       rm /var/lib/httpd_stop
        httpd
-
+
        db_progress STEP 1
        db_progress STOP
        IPADDR=$(ifconfig | grep 'inet addr:' | head -1 | \
Index: httpd
===================================================================
--- httpd       (revision 28045)
+++ httpd       (working copy)
@@ -18,6 +18,7 @@
 }

 if [ -z "$HTTPD_STARTED" ]; then
+       [ -f /var/lib/httpd_stop ] && exit
        HTTPD_STARTED=1
        export HTTPD_STARTED
        # daemonize
@@ -25,7 +26,7 @@
        exit
 else
        # start up the next listener process
-       run_nc $0
+       [ ! -f /var/lib/httpd_stop ] && run_nc $0
 fi

 read GET page x y z

Attachment: pgppA_tF_t8DF.pgp
Description: PGP signature


Reply to: