[systemd-devel] Difference between restart versus stop-start
Lennart Poettering
lennart at poettering.net
Fri Jan 15 05:39:11 PST 2016
On Fri, 15.01.16 03:41, Pathangi Janardhanan (path.jana at gmail.com) wrote:
> Hi,
>
> I am using sd_notify_pid_with_fds and subsequently sd_notify_fds to store
> and receive fds from systemd.
>
> Systemd differentiates between
>
> systemctl restart <service> -> Where it stops and starts the service, but
> maintains the fd stored above
>
> whereas if I do systemctl stop <service> and then start, the fds are
> cleaned out.
>
> This works well for me, but my question is that apart from the fds, the
> service also stores local state and tries to restore them on start, and i
> need the same logic for that data also. i.e. if the service is being
> restarted than it stores that data otherwise it deletes and flsuhes them
> out.
>
> So my question is, is there any way for the service to know when it is
> being stopped that it is done for a restart versus stop command?
>
> Without that it seems difficult for the service to make the determination
> to maintain/restore state or flush/init state?
Hmm, one option could be to serialize that data into a deleted
temporary file, and pass the fd of that deleted file to PID 1. Then,
if PID 1 closes the file the file will go on disk too, but if not,
then your process will get the fd back and cna read it.
Never tried this, but I think this should work. Could that work for you?
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list