<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Mon, Sep 10, 2018 at 9:44 AM prashantkumar dhotre <<a href="mailto:prashantkumardhotre@gmail.com">prashantkumardhotre@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<br>Is there is dbus API for systemd to restart unit by sending sigkill /sighup ?<br><a href="https://www.freedesktop.org/wiki/Software/systemd/dbus/" target="_blank">https://www.freedesktop.org/wiki/Software/systemd/dbus/</a><br>RestartUnit(in  s name, in  s mode, out o job);<br>My requirement is to have a way to restart unit by sending sigkill or sighup (user can specify ) also along with sigterm.<br></div></blockquote><div><br></div><div>Most programs use SIGHUP for live reloads, not restarts. If your service does the same, you can specify</div><div>    ExecReload=/bin/kill -HUP $MAINPID</div><div>in your service, and use ReloadUnit().</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Since that dbus APi does not seem to exists, to achieve same effect ,<br>I can use KillUnit() API to send custom signal and then use  StartUnit().<div>KillUnit(in  s name, in  s who,   in  i signal);<br>StartUnit(in  s name, in  s mode,  out o job);</div></div></blockquote><div><br></div><div>If you want an *immediate* SIGKILL, then yes, use KillUnit(). But is that really what you need?<br></div><div><br></div><div>Note that the default StopUnit will first send a SIGTERM first, wait a few seconds, and send a SIGKILL afterwards. So if the service takes a long time to stop normally, it will get killed after a timeout. You can reduce this timeout using TimeoutStopSec=.<br></div><div><br></div><div>But if the service *always* needs an immediate SIGKILL, you can configure that as the KillSignal= in the .service file, and that will make StopUnit go straight for the kill.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div> <br>Is that correct understanding ?<br>One issue with this is how to know when to do  StartUnit() after KillUnit() since KillUnit() may not have completed stopping unit yet.</div></div></blockquote><div><br></div><div>KillUnit's purpose isn't stopping the unit; that only happens as a side effect due to the process exiting.</div><div><br></div><div>I would call Subscribe(), then probably KillUnit(), then explicitly use StopUnit() (which creates a job), then wait for a dbus signal informing that the stop job has finished.</div></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Mantas Mikulėnas</div></div></div>