title: How systemd stop command actually works
body: <p>I am using a systemd service which calls a process when it's been &quot;started&quot; (e.g. <code>systemctl start test.service</code>). As per the design, the process stays for ever in a loop, we are able to see process existence using 'ps' command. We have also seen that the process is getting killed (as intended) for <code>systemctl stop</code> command.
  However our requirement is, we want to do some safe shutdown operations from within the process before it gets killed. But I am not sure how to detect a systemd stop operation from within the process.</p>
  <p>Does a <code>systemctl stop test.service</code> command send <code>SIGKILL</code> or <code>SIGTERM</code> signal to kill the process? How can I detect a <code>systemctl stop</code> operation from within a process?</p>