3
5
Fork 0
mirror of git://git.savannah.gnu.org/guix.git synced 2023-12-14 03:33:07 +01:00

gnu: Fix memcached service startup.

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 commit is contained in:
Christopher Baines 2017-08-05 22:32:24 +01:00
parent 2434f5cedf
commit 6230e155af
No known key found for this signature in database
GPG key ID: 5E28A33B0B84F577
2 changed files with 21 additions and 6 deletions

View file

@ -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))))

View file

@ -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"