[systemd-devel] How to run forking daemon with systemd in correct way, without errors?

Colin Guthrie gmane at colin.guthr.ie
Thu Nov 23 14:10:14 UTC 2017


Gena Makhomed wrote on 23/11/17 12:38:
> On 23.11.2017 12:53, Michael Chapman wrote:
> 
>> Many other deficiencies with the BSD daemon() function are documented
>> in systemd's daemon(7) manpage.
> 
> Michael, thank you for reference to daemon(7) manpage,
> this is exactly that I am looking for.
> 
> I will try to ask nginx developers for implementing
> changes required by systemd from SysV Daemons.
> 
>> I would suggest ignoring some other commenters suggestions that PID
>> files are unnecessary with systemd. Indeed, there's even a TODO item
>> for a Type=pid-file service that would, presumably, allow even
>> non-forking services to signal readiness by writing a PID file. I
>> would find something like that very useful.
> 
> From TODO file "ExecRestartPre=" feature will be very useful
> for protecting users which edit nginx or httpd configuration files
> and restarts nginx or httpd to apply changes. If someone make error
> in configuration file and restart service - nginx or httpd
> will not start after stop and service will be not working.
> 
> "ExecRestartPre=" feature will help to protect from such situations:
> 
> https://lists.freedesktop.org/archives/systemd-devel/2014-July/021642.html
> 
> Record in TODO file exists, even issue on github exists:
> 
> https://github.com/systemd/systemd/issues/2175
> 
> with comment from nginx.org packages maintainer Konstantin Pavlov:
> 
> https://github.com/systemd/systemd/issues/2175#issuecomment-343481962
> 
> But as I understand, feature "ExecRestartPre=" will not be included
> in the upcoming CentOS 8 / RHEL 8 system, because nobody
> of systemd developers have time to implement this feature.
> 
> Or anybody of systemd developers has time to implement this feature?
> 

I know this is somewhat tangential but in many of the cases you describe
here, a "reload" is more appropriate than a "restart". The config
parsing logic could either be specified in the systemd unit (just as one
of many ExecReload= entries) or could be handled internally in the
binary itself (presumably when the mainpid has received some signal).

That's not to take away from the usefulness of an ExecRestartPre=
directive of course, it's just that with nginx and httpd restarting is
not something you would ideally want to do in production unless you can
use full socket activation supported by systemd so as not to create a
small window when connections from clients are refused.

Col

-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited http://www.tribalogic.net/
Open Source:
  Mageia Contributor http://www.mageia.org/
  PulseAudio Hacker http://www.pulseaudio.org/
  Trac Hacker http://trac.edgewall.org/


More information about the systemd-devel mailing list