Subject: [PATCH] gnu: web: fcgiwrap: remove UNIX socket when service stopped.

From: Dale Mellor <[email-masked]>
Date: Mon, 19 Feb 2024 10:53:24 +0000

The generic kill destructor is used to terminate the process, but if it was
configured to use a UNIX socket, that socket gets left behind.  Subsequent
attempts to re-start the service then fail with a 'socket in use' error.  So
we perform extra duty in the stop action to clean up if necessary.

* gnu/services/web.scm: new logic in fcgiwrap-shepherd-service.
---
 gnu/services/web.scm | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/gnu/services/web.scm b/gnu/services/web.scm
index 05fd71f9949..877e15342b0 100644
--- a/gnu/services/web.scm
+++ b/gnu/services/web.scm
@@ -907,7 +907,14 @@ (define fcgiwrap-shepherd-service
                         "-s" #$socket)
                       #:user #$user #:group #$group
                       #:log-file "/var/log/fcgiwrap.log"))
-            (stop #~(make-kill-destructor)))))))
+            (stop #~(let ((mkd (make-kill-destructor)))
+                      (lambda x
+                        (apply mkd x)
+                        (when (string-prefix? "unix:" #$socket)
+                          (let ((socket (substring #$socket 5)))
+                            (when (access? socket F_OK)
+                              (delete-file socket))))
+                        #f))))))))
 
 (define fcgiwrap-activation
   (match-lambda
-- 
2.41.0