[systemd-devel] making a python daemon both systemd and el5 compatible

Amit Saha asaha at redhat.com
Mon Jan 27 16:46:50 PST 2014



----- Original Message -----
> From: "Greg Swift" <gregswift at gmail.com>
> To: systemd-devel at lists.freedesktop.org
> Sent: Tuesday, January 28, 2014 3:20:46 AM
> Subject: [systemd-devel] making a python daemon both systemd and el5	compatible
> 
> I'm working on a small daemon[1] that doesn't do a whole lot, but we need
> it to work on RHEL5+.  Going out of the gate I want to ensure it also works
> with systemd, since i want it to be usable on fedora and el7.
> 
> This stackoverflow[2] has a method, but then mentions some compatibility
> problems with the library it recommends that seem like it will not make it
> to friendly back to el5.
> 
> In the interm I was going to try leveraging cherrypy's bits (PIDFile and
> Daemonize), but they aren't backwards compatible to EL5, so we have to fix
> that.
> 
> I tried to find some place where this was mentioned or recommended but my
> google-fu failed me.
> 
> Do you have any recommendations or a existing python daemon that you could
> point me at that has similar needs?

The Beaker project's daemons (beakerd, beaker-proxy, beaker-watchdog and beaker-provision) 
adopts a policy that if it is on a distro which doesn't have
systemd, it uses the SysV init files and vice-versa. The spec file here [1] 
should give you some idea about what we are doing. 

Specifically, w.r.t python-daemon, on the SO thread you mention, I had replied
with my experience here [2] and I wrote further on this here [3].

Specifically, this may be helpful for you:

"In the [Service] section, the Type is set to Forking. This is because, beakerd 
uses python-daemon which forks itself (detaches itself) during the daemonization.
 However, you must ensure that when creating a DaemonContext() object, you should
 specify detach_process=True. This is because, if python-daemon detects that it 
is running under a init manager, it doesn’t detach itself unless the keyword is 
explicitly set to True, as above (you can see the code in daemon.py). 
Hence, although not setting the above keyword would work under SysV Init, it doesn’t 
work under systemd (with Type=Forking), since the daemon doesn’t fork at all and 
systemd expects it to fork (and finally kills it). The PIDFile specifies where the 
process ID is dumped by beakerd and is setup while creating the DaemonContext object
as follows and ExecStart specifies the location to the binary that is to be started."


[1] http://git.beaker-project.org/cgit/beaker/plain/beaker.spec?h=develop
[2] http://stackoverflow.com/a/17848250
[3] http://echorand.me/2013/08/02/notes-on-writing-systemd-unit-files-for-beakers-daemon-processes/

Hope those give you some ideas and point you towards the right direction.

Best,
Amit.

-- 
Amit Saha <http://echorand.me>



More information about the systemd-devel mailing list