summaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2022-04-06 22:37:33 +0200
committerLudovic Courtès <ludo@gnu.org>2022-04-14 14:48:20 +0200
commitb9233cb9a82690f81446443e016e07e01c123910 (patch)
tree7ae9c3f2b806255db1dbafd0992dedaac5784114 /guix
parent17c6d00b575bd6d6f3d29a0774f92a05e7792b41 (diff)
downloadguix-patches-b9233cb9a82690f81446443e016e07e01c123910.tar
guix-patches-b9233cb9a82690f81446443e016e07e01c123910.tar.gz
publish: Support systemd-style socket activation.
* guix/scripts/publish.scm (systemd-socket): New procedure. (guix-publish): Add 'style' variable. Adjust startup message depending on whether STYLE is 'systemd. * doc/guix.texi (Invoking guix publish): Mention socket activation.
Diffstat (limited to 'guix')
-rw-r--r--guix/scripts/publish.scm34
1 files changed, 29 insertions, 5 deletions
diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm
index d6eb65d912..e8197eb47a 100644
--- a/guix/scripts/publish.scm
+++ b/guix/scripts/publish.scm
@@ -1235,6 +1235,23 @@ headers."
(bind sock address)
sock))
+(define (systemd-socket)
+ "If this program is being spawned through systemd-style \"socket
+activation\", whereby the listening socket is passed as file descriptor 3,
+return the corresponding socket. Otherwise return #f."
+ (and (equal? (and=> (getenv "LISTEN_PID") string->number)
+ (getpid))
+ (match (getenv "LISTEN_FDS")
+ ((= string->number 1)
+ (let ((sock (fdopen 3 "r+0")))
+ (configure-socket sock)
+ sock))
+ ((= string->number (? integer? n))
+ (leave (G_ "~a: unexpected number of startup file descriptors")
+ n))
+ (_
+ #f))))
+
(define (gather-user-privileges user)
"Switch to the identity of USER, a user name."
(catch 'misc-error
@@ -1280,7 +1297,12 @@ headers."
(make-socket-address (sockaddr:fam addr)
(sockaddr:addr addr)
port)))
- (socket (open-server-socket address))
+ (socket style (match (systemd-socket)
+ (#f
+ (values (open-server-socket address)
+ 'normal))
+ (socket
+ (values socket 'systemd))))
(nar-path (assoc-ref opts 'nar-path))
(repl-port (assoc-ref opts 'repl))
(cache (assoc-ref opts 'cache))
@@ -1305,10 +1327,12 @@ consider using the '--user' option!~%")))
(cache-bypass-threshold
(or (assoc-ref opts 'cache-bypass-threshold)
(cache-bypass-threshold))))
- (info (G_ "publishing ~a on ~a, port ~d~%")
- %store-directory
- (inet-ntop (sockaddr:fam address) (sockaddr:addr address))
- (sockaddr:port address))
+ (if (eq? style 'systemd)
+ (info (G_ "publishing (started via socket activation)~%"))
+ (info (G_ "publishing ~a on ~a, port ~d~%")
+ %store-directory
+ (inet-ntop (sockaddr:fam address) (sockaddr:addr address))
+ (sockaddr:port address)))
(for-each (lambda (compression)
(info (G_ "using '~a' compression method, level ~a~%")