title: How to launch a process outside a systemd control group
body: <p>I have a server process (launched from systemd) which can launch an update process.  The update process self-daemonizes itself and then (in theory) kills the server with SIGTERM.  My problem is that the SIGTERM propagates to the update process <em>and it's children</em>.</p>
  
  <p>For debugging purposes, the update process just sleeps, and I send the kill by hand.</p>
  
  <p>Sample PS output before the kill:</p>
  
  <pre><code>    1  1869  1869  1869 ?           -1 Ss       0   0:00 /usr/local/bin/state_controller --start
   1869  1873  1869  1869 ?           -1 Sl       0   0:00  \_ ProcessWebController --start
   1869  1886  1869  1869 ?           -1 Z        0   0:00  \_ [UpdateSystem] &lt;defunct&gt;
      1  1900  1900  1900 ?           -1 Ss       0   0:00 /bin/bash /usr/local/bin/UpdateSystem refork /var/ttm/update.bin
   1900  1905  1900  1900 ?           -1 S        0   0:00  \_ sleep 10000
  </code></pre>
  
  <p>Note that UpdateSystem is in a separate PGID and TPGID.  (The <code>&lt;defunct&gt;</code> process is a result of the daemonization, and is not (I think) a problem.)</p>
  
  <p>UpdateSystem is a bash script (although I can easily make it a C program if that will help).  After the daemonization code taken from <a href="https://stackoverflow.com/a/29107686/771073">https://stackoverflow.com/a/29107686/771073</a>, the interesting bit is:</p>
  
  <pre><code>#############################################
  trap "echo Ignoring SIGTERM" SIGTERM
  sleep 10000
  echo Awoken from sleep - presumably by the SIGTERM
  exit 0
  </code></pre>
  
  <p>When I <code>kill 1869</code> (which sends SIGTERM to the <code>state_controller</code> server process, my logfile contains:</p>
  
  <pre><code>Terminating
  Ignoring SIGTERM
  Awoken from sleep - presumably by the SIGTERM
  </code></pre>
  
  <p>I really want to prevent SIGTERM being sent to the <code>sleep</code> process.  </p>
  
  <p><br />
  (Actually, I <em>really</em> want to stop it being sent to <code>apt-get upgrade</code> which is stopping the system via the moral equivalent of <code>systemctl stop ttm.service</code> and the <code>ExecStop</code> is specified as <code>/bin/kill $MAINPID</code> - just in case that changes anyone's answer.)</p>
  
  <p>This question is similar, but the accepted answer (use <code>KillMode=process</code>) doesn't work well for me - I want to kill some of the child processes, just not the update process: 
  <a href="https://stackoverflow.com/questions/32208782/cant-detach-child-process-when-main-process-is-started-from-systemd">Can&#39;t detach child process when main process is started from systemd</a></p>