<div dir="ltr">I've just tested the way I described it and everything worked perfectly.<br>Definitely the issue is this short period of time, I'm almost sure<br>(didn't check the source, though) that systemd re-reads pidfile<br>
the moment the main process terminates.<br><br>What's wrong with writing the new pid from the old proccess before<br>releasing the lock?<br></div><div class="gmail_extra"><br clear="all"><div><div dir="ltr"><div><br>
</div>
--<br>Кирилл Елагин</div></div>
<br><br><div class="gmail_quote">On Mon, May 5, 2014 at 12:00 PM, Gerd v. Egidy <span dir="ltr"><<a href="mailto:lists@egidy.de" target="_blank">lists@egidy.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Кирилл,<br>
<div class=""><br>
> OK, I've just re-read your message and it looks like all you need is add<br>
> `PIDFile` to your unit.<br>
<br>
</div>This was the first thing I tried when writing the service file. Unfortunately it<br>
does not work, the service is declared dead and the new daemon is killed<br>
(unless I switch off killing, but then the state is still wrong and I can't<br>
stop the process in a sane way).<br>
<div class=""><br>
> systemd will behave as expected: once your main process terminates it will<br>
> re-read PID<br>
> from this file (assuming that before dying your old process writes its<br>
> child's PID) and set it as MAINPID for your service.<br>
<br>
</div>Hmm. Currently it is done like this: the old daemon releases the lock on the<br>
pidfile and terminates itself. The new daemon detects this and then writes it's<br>
own pid to the pidfile and locks it.<br>
<br>
So there is a short time where the old daemon is already dead and the new one<br>
hasn't written it's pid yet. Probably this is the problem. But I have to think<br>
about a way to get the locking stuff right as I can't easily transfer the lock<br>
over an exec.<br>
<div class=""><br>
> But again, if your daemon is not writing a pidfile now, this way is not<br>
> “without changing the daemon itself first”.<br>
<br>
</div>The current daemon already writes a pidfile. And to be more precise, it is not<br>
a problem to change the daemon, but I'd prefer not to introduce systemd-<br>
specific code or dependencies (like sd_notify) in the first step.<br>
<br>
Kind regards,<br>
<br>
Gerd<br>
<br>
</blockquote></div><br></div>