[PATCH] gnu: Fix memcached service startup.

  • Done
  • quality assurance status badge
Details
One participant
  • Christopher Baines
Owner
unassigned
Submitted by
Christopher Baines
Severity
normal

Debbugs page

Christopher Baines wrote 8 years ago
(address . guix-patches@gnu.org)
20170808204839.23723-1-mail@cbaines.net
Memcached changes to the memcached user from root before writing the PID
file. This means that it must be able to write the PID file as the memcached
user.

To make this work, create the /var/run/memcached directory when the service
starts, make it owned by memcached, and change memcached to write the PID file
to /var/run/memcached/pid.

This wasn't picked up by the system test as the "service running" part was too
permissive, and only failed on an error. Instead, test the response from
calling start-service and check that the PID is a number.

* gnu/services/databases.scm (memcached-activation): New variable.
(memcached-shepherd-service): Change PID file location.
(memcached-service-type): Extend the activation-service-type.
* gnu/tests/databases.scm (run-memcached-test)[test]: Change the "service
running" test to check the response from the shepherd.
---
gnu/services/databases.scm | 17 +++++++++++++++--
gnu/tests/databases.scm | 10 ++++++----
2 files changed, 21 insertions(+), 6 deletions(-)

Toggle diff (71 lines)
diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
index 3b64d0e07..de1f6b841 100644
--- a/gnu/services/databases.scm
+++ b/gnu/services/databases.scm
@@ -216,6 +216,14 @@ and stores the database cluster in @var{data-directory}."
(home-directory "/var/empty")
(shell (file-append shadow "/sbin/nologin")))))
+(define memcached-activation
+ #~(begin
+ (use-modules (guix build utils))
+ (let ((user (getpwnam "memcached")))
+ (mkdir-p "/var/run/memcached")
+ (chown "/var/run/memcached"
+ (passwd:uid user) (passwd:gid user)))))
+
(define memcached-shepherd-service
(match-lambda
(($ <memcached-configuration> memcached interfaces tcp-port udp-port
@@ -233,11 +241,14 @@ and stores the database cluster in @var{data-directory}."
"-p" #$(number->string tcp-port)
"-U" #$(number->string udp-port)
"--daemon"
- "-P" "/var/run/memcached.pid"
+ ;; Memcached changes to the memcached user prior to
+ ;; writing the pid file, so write it to a directory
+ ;; that memcached owns.
+ "-P" "/var/run/memcached/pid"
"-u" "memcached"
,#$@additional-options)
#:log-file "/var/log/memcached"
- #:pid-file "/var/run/memcached.pid"))
+ #:pid-file "/var/run/memcached/pid"))
(stop #~(make-kill-destructor))))))))
(define memcached-service-type
@@ -245,6 +256,8 @@ and stores the database cluster in @var{data-directory}."
(extensions
(list (service-extension shepherd-root-service-type
memcached-shepherd-service)
+ (service-extension activation-service-type
+ (const memcached-activation))
(service-extension account-service-type
(const %memcached-accounts))))
(default-value (memcached-configuration))))
diff --git a/gnu/tests/databases.scm b/gnu/tests/databases.scm
index 310210c36..9d9a75374 100644
--- a/gnu/tests/databases.scm
+++ b/gnu/tests/databases.scm
@@ -63,13 +63,15 @@
(test-begin "memcached")
;; Wait for memcached to be up and running.
- (test-eq "service running"
- 'running!
+ (test-assert "service running"
(marionette-eval
'(begin
(use-modules (gnu services herd))
- (start-service 'memcached)
- 'running!)
+ (match (start-service 'memcached)
+ (#f #f)
+ (('service response-parts ...)
+ (match (assq-ref response-parts 'running)
+ ((pid) (number? pid))))))
marionette))
(let* ((ai (car (getaddrinfo "localhost"
--
2.14.0
Christopher Baines wrote 8 years ago
(address . 28021-done@debbugs.gnu.org)
20170815222610.1f24c7df@cbaines.net
On Tue, 8 Aug 2017 21:48:39 +0100
Christopher Baines <mail@cbaines.net> wrote:

Toggle quote (19 lines)
> Memcached changes to the memcached user from root before writing the
> PID file. This means that it must be able to write the PID file as
> the memcached user.
>
> To make this work, create the /var/run/memcached directory when the
> service starts, make it owned by memcached, and change memcached to
> write the PID file to /var/run/memcached/pid.
>
> This wasn't picked up by the system test as the "service running"
> part was too permissive, and only failed on an error. Instead, test
> the response from calling start-service and check that the PID is a
> number.
>
> * gnu/services/databases.scm (memcached-activation): New variable.
> (memcached-shepherd-service): Change PID file location.
> (memcached-service-type): Extend the activation-service-type.
> * gnu/tests/databases.scm (run-memcached-test)[test]: Change the
> "service running" test to check the response from the shepherd.

This was reviewed by lfam and rekado on IRC, and I've now pushed :)
-----BEGIN PGP SIGNATURE-----

iQKTBAEBCgB9FiEEPonu50WOcg2XVOCyXiijOwuE9XcFAlmTZvJfFIAAAAAALgAo
aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF
ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcACgkQXiijOwuE
9XcZXRAApfrh5lLTUJdWRXNitbgIWC3kWJ1+qG82XEYC/e9PCVVj3oMBqtwUt5Ck
ZGZgH712jjsBHkMkZNfRAWV9874t1bOs2HqpThvTaSEhqsGLp6/qEqGSH2lA2Qbi
rmZnx55zK0Pn9MfWN5mUHsw3DYujXXcZ/lFqokvsx9tCLOi4VeEOmDxePexkkcI5
Ivd3TXpw24g6tSS7e/Z1pbZDdiWN8phiQHbSykCPeohh6whuSXbn9LVU1wHeWA2f
D4ldG18B4GFv21UMwQcE7y85AGAuS/CV8Hq3KilnitINyP4Br8FDORmJstRFkn+a
F0vDyt01KmXXGNniclhC8MOBLI9jdnhnJsf7RHezNtyuTTDlX1U8Bve0pepJaH5P
CMUMJoYFZnw18YFiEoa3XbEZLACt6ehWV8K/g7E7uSEyKCWOs3BsprhLwNmxYmmj
3Rnh8DuVlwV4Iq/ciP7x5eRC9tT7HypoyJpW0WgcrtdIoaIqcm6g2rOFL8ZUyRfS
Bz4KWfLsUIhTuluPzJbuPrQFt7G09w2lz+mwaG2oPyWwNot4k4SHstQegjQAlCry
T8MtftyLzykZwfPR+kCmBE8iyvVZColuYlqYlScnI0BHIl76vhb3IAwsiB2B97aF
hHajCmpJoPHyFtd9qKrbyQbLC0vJX03lNKQ58/qzB2Pj2U30t5M=
=h6zY
-----END PGP SIGNATURE-----


Closed
?
Your comment

This issue is archived.

To comment on this conversation send an email to 28021@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 28021
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help