There is a daemon that can be started from command line and from systemctl.
/etc/systemd/system/mydaemon.service contains ExecStart= and PIDFile= so Systemd can surely detect that service is running or not:
[Unit] After=network-online.target [Service] Type=simple ExecStart=/usr/local/bin/mydaemon --no-fork PIDFile=/var/run/mydaemon-%i.pid [Install] WantedBy=multi-user.target Why "systemctl status mydaemon" says that daemon is stopped even if it's running?
How to teach systemd that daemon can be running not only via "systemctl start" but also directly?
PIDFileis so the service know the PID that it started, not so that it will poll it. Add a script that exits if it's already running.