title: systemd kill my processes before ExecStop completed
body: <p>I'm trying to update my application to use it with systemd.
  When I have used Upstart, I've just create a <em>/etc/init.d/myService</em> script:</p>
  
  <pre><code>#!/bin/bash
  #chkconfig: 2345 90 10
  #description: myDescription
  
  ### BEGIN INIT INFO
  # Provides: myService
  # Required-Start: sshd
  # Required-Stop: sshd
  # Default-Start: 2 3 4 5
  # Default-Stop: 0 1 6
  # Short-Description: start myService
  # Description:
  ### END INIT INFO
  
  SCRIPT=$(readlink -f $0)
  lockfile="/var/lock/subsys/myService"
  
  do_start() {
      if [ -d "/var/lock/subsys" ]; then
          touch $lockfile
      fi
      ...
  }
  
  do_stop() {
      ...
      if [ -d "/var/lock/subsys" ]; then
          if [ -f "$lockfile" ]; then
              rm -f $lockfile
          fi
      fi
  }
  
  do_status() {
      ...
  }
  
  
  case "$1" in
    start)
      do_start
      exit 0
      ;;
    stop)
      do_stop
      exit 0
      ;;
    status)
      do_status
      exit 0
      ;;
    restart)
      do_stop
      do_start
      exit 0
      ;;
    *)
      echo "Usage: $SCRIPTNAME {start|stop|status|restart}" &gt;&amp;2
      exit 3
      ;;
  esac
  </code></pre>
  
  <p>And all were fine.</p>
  
  <p><strong>Notice</strong>, this script generate some subprocesses which will executing in background.
  To use it with systemd, I made the follow service file (<em>myService.service</em>):</p>
  
  <pre><code>[Unit]
  Description=My Description
  Requires=sshd.service
  After=sshd.service
  Before=shutdown.target reboot.target halt.target
  
  [Service]
  Type=oneshot
  ExecStart=/etc/init.d/myService start
  ExecStop=/etc/init.d/myService stop
  RemainAfterExit=yes
  KillMode=none
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <p>If I run</p>
  
  <pre><code>systemctl stop myService.service
  </code></pre>
  
  <p>All work fine. My application stop successfully by <em>/etc/init.d/myService stop</em> command.</p>
  
  <p>But I've got the follow issue:
  When I reboot the system, and <em>/etc/init.d/myService stop</em> is executing, process which I should stop by <em>myService</em> script already killed. There are many processes which I should control ( around 7 processes ), and system should not terminated it itself.</p>
  
  <p>I've tried to use Type=forking and specify the PIDFile as a pidfile of process, which has the longest life-time ( it should started first end stopped last ), however all my process were terminated again.</p>
  
  <p>Is any simple way to avoid killing my subprocess?</p>