[systemd-devel] On writing a systemd service file
Lennart Poettering
lennart at poettering.net
Mon Jul 11 11:56:29 PDT 2011
On Mon, 11.07.11 13:12, W. Michael Petullo (mike at flyn.org) wrote:
> 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.
In general we prefer if people use Type=simple (or "notify" or "bus"),
but if your service only supports forking/exiting to tell us when it is
finished initializing, then Type=forking is the only setting you can
use, but you need to make sure that the daemon actually does fork. In
some daemons they have a switch for that, often call "-f" or "-F". Check
the man page.
Lennart
--
Lennart Poettering - Red Hat, Inc.
More information about the systemd-devel
mailing list