[systemd-devel] On writing a systemd service file

W. Michael Petullo mike at flyn.org
Mon Jul 11 21:25:28 PDT 2011


>> I am trying to migrate a service from a SysV-style initialization script
>> to systemd on Fedora.
>> 
>> After referencing the documentation I could find, I have written the
>> following service description:
>> 
>> [Unit]
>> Description=DMAP Service
>> After=avahi-daemon.service
>> 
>> [Service]
>> Type=forking
>> PIDFile=/var/run/dmapd/dmapd.pid
>> ExecStart=/usr/sbin/dmapd
>> 
>> [Install]
>> WantedBy=multi-user.target
>> 
>> But, when I try to start the service, I get:
>> 
>> $ sudo systemctl start dmapd.service
>> Job failed. See system logs and 'systemctl status' for details.
>> 
>> and in the logs:
>> 
>> Jul 11 12:55:38 imp systemd[1]: dmapd.service operation timed out. Terminating.
>> Jul 11 12:57:09 imp systemd[1]: Unit dmapd.service entered failed state.
>> 
>> I don't know what operation is timing out. I can see that dmapd is running
>> fine (and /var/run/dmapd/dmapd.pid exists) until this operation times
>> out. Then systemd/systemctl seems to kill dmapd and systemctl exits with
>> an error.
> 
> If you use Type=forking, then dmapd must daemonize (i.e. fork()) and
> return (i.e. exit) in the parent. If it doesn't exit, then systemd will
> time this out, and the service will fail.

Well, I am the author of dmapd and I think I just realized what was
wrong. Dmapd contained a daemonize function that did this:

	if (getppid () == 1)
		return; /* Already a daemon. */

It seems that this check is not compatible with systemd, because systemd
runs with PID 1. Is this correct? Has anyone else seen this problem
before? I don't think that I am the first to do this:

	http://www.itp.uzh.ch/~dpotter/howto/daemonize

-- 
Mike

:wq


More information about the systemd-devel mailing list