Add "nosigterm" service setting to inhibit sending SIGTERM to service
authorDavin McCall <davmac@davmac.org>
Tue, 24 Nov 2015 00:03:10 +0000 (00:03 +0000)
committerDavin McCall <davmac@davmac.org>
Tue, 24 Nov 2015 00:03:10 +0000 (00:03 +0000)
process. (Unless an aleternative signal is specified using 'termsignal',
no termination signal will be sent).

README
load_service.cc
service.cc
service.h

diff --git a/README b/README
index cf1a03ad98368c82bdd9a7690753ce39a15980de..7f20163a6de028b3feb59e2eba6a233e129031e8 100644 (file)
--- a/README
+++ b/README
@@ -85,6 +85,7 @@ logfile = ...
 onstart = ...
 depends-on = (service name)
 waits-for = (service name)
+termsignal = HUP | INT | QUIT | USR1 | USR2
 
 command = (external script or executable and arguments)
    For a 'process' service, this is the process to run.
@@ -109,3 +110,15 @@ waits-for = (service name)
    starting (or to fail starting) before commencing the start procedure
    for this service. Starting this service will automatically start
    the named service.
+
+termsignal = (signal)
+   Specifies an additional signal to send to the process when requesting it
+   to terminate (applies to 'process' services only). SIGTERM is always
+   sent along with the specified signal, unless the 'nosigterm' setting is
+   set true.
+
+nosigterm = yes | true | no | false
+   If true, the TERM signal will not be sent to the process to kill it. (If
+   an alternate signal is specified using the "termsignal" setting, that
+   signal will be sent instead; otherwise, no signal will be sent, and the
+   process must be killed by external means).
index 87116ec92fec6940de37008f1dfb703007e615b6..49bd28f6d8ebe3d5026ca0ed8163e2c4dae6e9da 100644 (file)
@@ -310,6 +310,10 @@ ServiceRecord * ServiceSet::loadServiceRecord(const char * name)
                         term_signal = signo;
                     }
                 }
+                else if (setting == "nosigterm") {
+                    string sigtermsetting = read_setting_value(i, end);
+                    onstart_flags.no_sigterm = (sigtermsetting == "yes" || sigtermsetting == "true");
+                }
                 else {
                     throw ServiceDescriptionExc(name, "Unknown setting: " + setting);
                 }
index 71ec4fc8bb20f0f366f507e29e6c7dd72902c853..291ae22d26fe696e84ac8d53e1c3f6faa90500d1 100644 (file)
@@ -512,12 +512,14 @@ void ServiceRecord::allDepsStopped()
 {
     if (service_type == ServiceType::PROCESS) {
         if (pid != -1) {
-          // The process is still kicking on - must actually kill it.
-          kill(pid, SIGTERM);
-          if (term_signal != -1) {
-              kill(pid, term_signal);
-          }
-          // Now we wait; the rest is done in process_child_callback
+            // The process is still kicking on - must actually kill it.
+            if (! onstart_flags.no_sigterm) {
+                kill(pid, SIGTERM);
+            }
+            if (term_signal != -1) {
+                kill(pid, term_signal);
+            }
+            // Now we wait; the rest is done in process_child_callback
         }
         else {
             // The process is already dead.
index 7f4ae224e4d616f924c265ff8e28254445148434..2ad60ba44b708149a4f1fce93e1df3d7a595fbb4 100644 (file)
--- a/service.h
+++ b/service.h
@@ -50,7 +50,10 @@ struct OnstartFlags {
     bool release_console : 1;
     bool rw_ready : 1;
     
-    OnstartFlags() noexcept : release_console(false), rw_ready(false)
+    // Not actually "onstart" commands:
+    bool no_sigterm : 1;  // do not send SIGTERM
+    
+    OnstartFlags() noexcept : release_console(false), rw_ready(false), no_sigterm(false)
     {
     }
 };