Forking in a systemd script

systemd

I want systemd service to handle forking (my file doesn't handle forking by itself. So I'm relying on systemd for handling that)

My .service file:

[Unit]
Description=swamp services management service
After=syslog.target

[Service]
Type=forking
ExecStart=/usr/bin/swamp

[Install]
WantedBy=multi-user.target

Question

Is specifying Type=forking enough for what I'm trying to achieve? Or is it similar to expect forking in upstart which actually tells upstart (if I understand correctly, not sure I do, I'm new at writing initscripts) that my service would handle forking/daemonizing.

Best Answer

systemd has excellent documentation. See the page on service files:

If set to forking, it is expected that the process configured with ExecStart= will call fork() as part of its start-up. The parent process is expected to exit when start-up is complete and all communication channels are set up. The child continues to run as the main daemon process. This is the behavior of traditional UNIX daemons. If this setting is used, it is recommended to also use the PIDFile= option, so that systemd can identify the main process of the daemon. systemd will proceed with starting follow-up units as soon as the parent process exits.

So, using that type will just tell systemd to wait until swamp returns and then consider it to be still running: making that happen remains your responsibility...