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?
Don't do it. Always start it with
systemctl
. Shutdown the service and bring it up in such a way thesystemd
knows about it.This probably isn't the answer you want. It may even be possible to do what you're asking, but why bother?
Well, I checked
systemd
manual and haven't found any information how to informsystemd
about manually started process. I don't look deep, but i think there is could be possibility, to do it trough sending messages tosystemd
about process start, but it's to complicated for me.systemd can only track the process that it has started. If another instance of the same daemon is started via cmdline the systemd is not aware of it.
Now even if you invoke the service file through systemctl , the ExecStart will fail ( since you already launched the daemon via cmdline ) and systemd thinks that it didn't succeed in launching back your daemon.
To resolve this, first kill your daemon. Then invoke your service file via systemctl to restart your daemon, the status should be active