From d7342c78d49ac80c6a1464bbc9c1cdf188eeebe9 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 6 Nov 2009 22:45:19 +0000 Subject: [PATCH] * Support pre-stop scripts. These are needed to cleanly shutdown daemons such as Apache or PostgreSQL. svn path=/nixos/branches/upstart-0.6/; revision=18234 --- .../web-servers/apache-httpd/default.nix | 9 ++++++++- modules/system/upstart/upstart.nix | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/modules/services/web-servers/apache-httpd/default.nix b/modules/services/web-servers/apache-httpd/default.nix index c489393f889..107340c4586 100644 --- a/modules/services/web-servers/apache-httpd/default.nix +++ b/modules/services/web-servers/apache-httpd/default.nix @@ -480,7 +480,14 @@ in done ''; - exec = "${httpd}/bin/httpd -f ${httpdConf} -DNO_DETACH"; + daemonType = "fork"; + + exec = "${httpd}/bin/httpd -f ${httpdConf}"; + + preStop = + '' + ${httpd}/bin/httpd -f ${httpdConf} -k graceful-stop + ''; }; }; diff --git a/modules/system/upstart/upstart.nix b/modules/system/upstart/upstart.nix index 3d2af1b0382..f7c9eaaa6ef 100644 --- a/modules/system/upstart/upstart.nix +++ b/modules/system/upstart/upstart.nix @@ -72,6 +72,12 @@ let ${optionalString job.task "task"} ${optionalString job.respawn "respawn"} + ${optionalString (job.preStop != "") '' + pre-stop script + ${job.preStop} + end script + ''} + ${optionalString (job.postStop != "") '' post-stop script ${job.postStop} @@ -165,6 +171,16 @@ let ''; }; + preStop = mkOption { + type = types.string; + default = ""; + description = '' + Shell commands executed before the job is stopped + (i.e. before Upstart kills the job's main process). This can + be used to cleanly shut down a daemon. + ''; + }; + postStop = mkOption { type = types.string; default = "";