On Mon, Sep 10, 2018 at 9:44 AM prashantkumar dhotre <prashantkumardhotre@xxxxxxxxx> wrote:
Hi,
Is there is dbus API for systemd to restart unit by sending sigkill /sighup ?
https://www.freedesktop.org/wiki/Software/systemd/dbus/
RestartUnit(in s name, in s mode, out o job);
My requirement is to have a way to restart unit by sending sigkill or sighup (user can specify ) also along with sigterm.
Most programs use SIGHUP for live reloads, not restarts. If your service does the same, you can specify
ExecReload=/bin/kill -HUP $MAINPID
in your service, and use ReloadUnit().
Since that dbus APi does not seem to exists, to achieve same effect ,
I can use KillUnit() API to send custom signal and then use StartUnit().KillUnit(in s name, in s who, in i signal);
StartUnit(in s name, in s mode, out o job);
If you want an *immediate* SIGKILL, then yes, use KillUnit(). But is that really what you need?
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=.
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.
Is that correct understanding ?
One issue with this is how to know when to do StartUnit() after KillUnit() since KillUnit() may not have completed stopping unit yet.
KillUnit's purpose isn't stopping the unit; that only happens as a side effect due to the process exiting.
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.
Mantas Mikulėnas
_______________________________________________ systemd-devel mailing list systemd-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/systemd-devel