From: Alex Sassmannshausen <alex.sassmannshausen@gmail.com>
To: guix-devel@gnu.org
Subject: [PATCH 2/2] dmd: Add dmd action 'reload': unload all; load.
Date: Mon, 10 Mar 2014 18:39:21 +0100 [thread overview]
Message-ID: <1394473161-14356-2-git-send-email-alex.sassmannshausen@gmail.com> (raw)
In-Reply-To: <1394473161-14356-1-git-send-email-alex.sassmannshausen@gmail.com>
* modules/dmd/service.scm (runtime-load): New procedure.
(dmd-service): Re-factor 'load', add new action: 'reload'.
* dmd.texi (The 'dmd' and 'unknown' services): Document 'reload'.
* tests/basic.sh: Add 'reload' test.
---
dmd.texi | 8 ++++++++
modules/dmd/service.scm | 35 ++++++++++++++++++++++-------------
tests/basic.sh | 6 +++++-
3 files changed, 35 insertions(+), 14 deletions(-)
diff --git a/dmd.texi b/dmd.texi
index e31b230..573d7ea 100644
--- a/dmd.texi
+++ b/dmd.texi
@@ -867,6 +867,14 @@ might be provided by both @code{apache} and @code{nginx}. If
@var{service-name} is the special string and @code{all}, attempt to
remove all services except for dmd itself.
+@item reload @var{file-name}
+Unload all known optional services using unload's @code{all} option,
+then load @var{file-name} using @code{load} functionality. If
+file-name does not exist or @code{load}hits an error, you may end up
+with no defined services. Considering these can be reloaded at a
+later stage this is not considered a problem. If the @code{unload}
+stage fails, @code{reload} will not attempt to load @var{file-name}.
+
@item daemonize
Fork and go into the background. This should be called before
respawnable services are started, as otherwise we would not get the
diff --git a/modules/dmd/service.scm b/modules/dmd/service.scm
index 20a3f52..76c28a7 100644
--- a/modules/dmd/service.scm
+++ b/modules/dmd/service.scm
@@ -833,6 +833,18 @@ requested to be removed."
"Not unloading: '~a' names several services: '~a'."
name (map canonical-name services))))))))
+(define (runtime-load file-name)
+ (local-output "Loading ~a." file-name)
+ ;; Every action is protected anyway, so no need for a `catch'
+ ;; here. FIXME: What about `quit'?
+ (catch 'system-error
+ (lambda ()
+ (load-in-user-module file-name))
+ (lambda args
+ (local-output "Failed to load from '~a': ~a."
+ file-name (strerror (system-error-errno args)))
+ #f)))
+
;;; Tests for validity of the slots of <service> objects.
;; Test if OBJ is a list that only contains symbols.
@@ -929,16 +941,7 @@ which ones are not."
"Load the Scheme code from FILE into dmd. This is potentially
dangerous. You have been warned."
(lambda (running file-name)
- (local-output "Loading ~a." file-name)
- ;; Every action is protected anyway, so no need for a `catch'
- ;; here. FIXME: What about `quit'?
- (catch 'system-error
- (lambda ()
- (load-in-user-module file-name))
- (lambda args
- (local-output "Failed to load from '~a': ~a."
- file-name (strerror (system-error-errno args)))
- #f))))
+ (runtime-load file-name)))
;; Unload a service
(unload
"Unload the service identified by SERVICE-NAME or all services
@@ -946,6 +949,12 @@ except for dmd if SERVICE-NAME is 'all'. Stop services before
removing them if needed."
(lambda (running service-name)
(deregister-service service-name)))
+ (reload
+ "Unload all services, then load from FILE-NAME into dmd. This
+is potentialy dangerous. You have been warned."
+ (lambda (running file-name)
+ (and (deregister-service "all") ; unload all services
+ (runtime-load file-name)))) ; reload from FILE-NAME
;; Go into the background.
(daemonize
"Go into the background. Be careful, this means that a new
@@ -963,9 +972,9 @@ This status gets written into a file on termination, so that we can
restore the status on next startup. Optionally, you can pass a file
name as argument that will be used to store the status."
(lambda* (running #:optional (file #f))
- (set! persistency #t)
- (when file
- (set! persistency-state-file file))))
+ (set! persistency #t)
+ (when file
+ (set! persistency-state-file file))))
(no-persistency
"Don't safe state in a file on exit."
(lambda (running)
diff --git a/tests/basic.sh b/tests/basic.sh
index 5f53fe3..294ce80 100644
--- a/tests/basic.sh
+++ b/tests/basic.sh
@@ -64,7 +64,8 @@ dmd_pid="`cat $pid`"
kill -0 $dmd_pid
test -S "$socket"
-$deco status dmd | grep -E '(Start.*dmd|Stop.*test)'
+pristineStatus=$($deco status dmd) # Prep for 'reload' test.
+echo $pristineStatus | grep -E '(Start.*dmd|Stop.*test)'
$deco start test
test -f "$stamp"
@@ -83,6 +84,9 @@ $deco unload dmd test
$deco status dmd | grep "Stopped: (test-2)"
+$deco reload dmd "$conf"
+[ "$($deco status dmd)" == "$pristineStatus" ]
+
$deco unload dmd all
$deco status dmd | grep "Stopped: ()"
--
1.7.9.5
next prev parent reply other threads:[~2014-03-10 17:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-25 8:22 dmd: Unload one or all services at runtime Alex Sassmannshausen
2014-02-27 21:50 ` Ludovic Courtès
2014-03-10 17:39 ` [PATCH 1/2] dmd: Add dmd action unload: unload known services Alex Sassmannshausen
2014-03-10 17:39 ` Alex Sassmannshausen [this message]
2014-03-12 17:49 ` [PATCH 2/2] dmd: Add dmd action 'reload': unload all; load Ludovic Courtès
2014-03-19 14:25 ` dmd: Unload one or all services at runtime Alex Sassmannshausen
2014-03-19 14:25 ` [PATCH] dmd: Add dmd action 'reload': unload all; load Alex Sassmannshausen
2014-03-25 20:33 ` Ludovic Courtès
2014-03-25 20:30 ` dmd: Unload one or all services at runtime Ludovic Courtès
2014-03-12 17:45 ` [PATCH 1/2] dmd: Add dmd action unload: unload known services Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1394473161-14356-2-git-send-email-alex.sassmannshausen@gmail.com \
--to=alex.sassmannshausen@gmail.com \
--cc=guix-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).