From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Sassmannshausen Subject: [PATCH 2/2] dmd: Add dmd action 'reload': unload all; load. Date: Mon, 10 Mar 2014 18:39:21 +0100 Message-ID: <1394473161-14356-2-git-send-email-alex.sassmannshausen@gmail.com> References: <87a9dcrzsh.fsf@gnu.org> <1394473161-14356-1-git-send-email-alex.sassmannshausen@gmail.com> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WN4BV-0004mk-Fl for guix-devel@gnu.org; Mon, 10 Mar 2014 13:40:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WN4BO-00081W-Kk for guix-devel@gnu.org; Mon, 10 Mar 2014 13:40:17 -0400 Received: from mail-wg0-x22a.google.com ([2a00:1450:400c:c00::22a]:47408) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WN4BO-00081Q-9q for guix-devel@gnu.org; Mon, 10 Mar 2014 13:40:10 -0400 Received: by mail-wg0-f42.google.com with SMTP id y10so8950441wgg.1 for ; Mon, 10 Mar 2014 10:40:09 -0700 (PDT) In-Reply-To: <1394473161-14356-1-git-send-email-alex.sassmannshausen@gmail.com> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: guix-devel@gnu.org * 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 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