notes/systems
← index

Why your systemd unit starts twice

Three causes cover nearly every case.

1. A leftover init script

An old /etc/init.d/foo sitting next to foo.service. systemd generates a compatibility unit from the script and now there are two units with the same job.

systemctl list-unit-files | grep foo
ls -l /etc/init.d/ | grep foo

2. Type mismatch

Type=simple on a daemon that forks. systemd tracks the process it started; that process forks and exits; systemd concludes the service died and starts it again — while the forked child is still running and holding the port. The second copy then fails to bind, which is usually the first symptom anyone notices.

Fix it with Type=forking and a PIDFile=, or better, find whatever --foreground flag the daemon has and use Type=simple honestly.

3. Socket activation plus an enabled service

Both foo.socket and foo.service enabled at boot. Pick one.

Finding out which

systemctl status foo | grep -A5 CGroup

The cgroup listing is the fastest answer available. It shows every process systemd considers part of the unit — including the ones you did not know were there.