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