[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 01/02: service: Add #:pid-file-timeout parameter to 'make-for
From: |
Ludovic Courtès |
Subject: |
[shepherd] 01/02: service: Add #:pid-file-timeout parameter to 'make-forkexec-constructor'. |
Date: |
Sat, 26 Nov 2016 18:31:50 +0000 (UTC) |
civodul pushed a commit to branch master
in repository shepherd.
commit 65df517e2874c401ee44df2346f1c4e03c8066ee
Author: Ludovic Courtès <address@hidden>
Date: Sat Nov 26 19:05:25 2016 +0100
service: Add #:pid-file-timeout parameter to 'make-forkexec-constructor'.
* modules/shepherd/service.scm (%pid-file-timeout): New variable.
(make-forkexec-constructor): Add #:pid-file-timeout parameter and pass
it to 'read-pid-file'.
---
doc/shepherd.texi | 6 ++++--
modules/shepherd/service.scm | 13 ++++++++++---
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/doc/shepherd.texi b/doc/shepherd.texi
index d7ce3fe..70c13b8 100644
--- a/doc/shepherd.texi
+++ b/doc/shepherd.texi
@@ -834,7 +834,7 @@ execution of the @var{command} was successful, @code{#t} if
not.
@deffn {procedure} make-forkexec-constructor @var{command} @
[#:user #f] @
[#:group #f] @
- [#:pid-file #f] @
+ [#:pid-file #f] [#:pid-file-timeout %pid-file-timeout] @
[#:log-file #f] @
[#:directory (default-service-directory)] @
[#:environment-variables (default-environment-variables)]
@@ -848,7 +848,9 @@ the procedure will be the PID of the child process.
When @var{pid-file} is true, it must be the name of a PID file
associated with the process being launched; the return value is the PID
-read from that file, once that file has been created.
+once that file has been created. If @var{pid-file} does not show up in less
+than @var{pid-file-timeout} seconds, the service is considered as failing to
+start.
When @var{log-file} is true, it must be the name of a file. The file will
be removed if it exists and the services stdout and stderr will be
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 3890675..1ef6272 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -797,6 +797,10 @@ its PID."
#:environment-variables environment-variables)
pid)))
+(define %pid-file-timeout
+ ;; Maximum number of seconds we wait for a PID file to show up.
+ 5)
+
(define make-forkexec-constructor
(let ((warn-deprecated-form
;; Until 0.1, this procedure took a rest list.
@@ -815,13 +819,16 @@ the procedure will be the PID of the child process.
When @var{pid-file} is true, it must be the name of a PID file associated with
the process being launched; the return value is the PID read from that file,
-once that file has been created."
+once that file has been created. If @var{pid-file} does not show up in less
+than @var{pid-file-timeout} seconds, the service is considered as failing to
+start."
((command #:key
(user #f)
(group #f)
(directory (default-service-directory))
(environment-variables (default-environment-variables))
(pid-file #f)
+ (pid-file-timeout %pid-file-timeout)
(log-file #f))
(let ((command (if (string? command)
(begin
@@ -842,7 +849,6 @@ once that file has been created."
(clean-up log-file)
(let ((pid (fork+exec-command command
-
#:user user
#:group group
#:log-file log-file
@@ -850,7 +856,8 @@ once that file has been created."
#:environment-variables
environment-variables)))
(if pid-file
- (read-pid-file pid-file)
+ (read-pid-file pid-file
+ #:max-delay pid-file-timeout)
pid)))))
((program . program-args)
;; The old form, documented until 0.1 included.