* 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