Adding a python daemon to the systemd
<p>The essence:</p>

<p>I have created a daemon to manage some tasks on a remote platform.
It is written in python and accepts start, stop and restart arguments.
While trying to add it to the systemd (so it would start on system startup and be stopped on shutdown, etc.) I encountered a problem:
It seems to see daemon running, but I am not sure if it actually works, because restarting or requesting status returns with an error:</p>

<pre><code>[user@centos ~]# systemctl restart mydaemon
Failed to restart mydaemon.service: Unit mydaemon.service failed to load: No such file or directory.

[user@centos ~]# systemctl status mydaemon
● mydaemon.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)
</code></pre>

<hr>

<p>The specifics:</p>

<p>The code itself follows the well-known <a href="http://web.archive.org/web/20131017130434/http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/" rel="nofollow noreferrer">example</a> by Sander Marechal with very few changes. By itself it works without any problems, and properly reacts to all accepted arguments.  The pid is saved in <code>/tmp/my-daemon.pid</code>.</p>

<p>The systemd service file is in the user daemons directory: <code>/usr/lib/systemd/user/mydaemon.service</code>, and the code is as follows:</p>

<pre><code>[Unit]
Description=The user daemon

[Service]
Type=forking
ExecStart=/usr/bin/python /home/frcr/mydaemon_v01.py start
ExecStop=/usr/bin/python /home/frcr/mydaemon_v01.py stop
RestartSec=5
TimeoutSec=60
RuntimeMaxSec=infinity
Restart=always
PIDFile=/tmp/my-daemon.pid


[Install]
WantedBy=multi-user.target
</code></pre>

<p><code>systemctl</code> returns the status of it as active, but only if provided the pid:</p>

<pre><code>[user@centos ~]# systemctl status 9177
● session-481.scope - Session 481 of user user
   Loaded: loaded
  Drop-In: /run/systemd/system/session-481.scope.d
           └─50-After-systemd-logind\x2eservice.conf, 50-After-systemd-user-sessions\x2eservice.conf, 50-Description.conf, 50-SendSIGHUP.conf, 50-Slice.conf
   Active: active (running) since Tue 2016-05-17 06:24:51 EDT; 1h 43min ago
   CGroup: /user.slice/user-0.slice/session-481.scope
           ├─8815 sshd: root@pts/0
           ├─8817 -bash
           ├─9177 python /home/user/mydaemon_v01.py start
           └─9357 systemctl status 9177
</code></pre>

<p>I have seen a <a href="https://stackoverflow.com/questions/13069634/python-daemon-and-systemd-service">similar question</a> here on stack overflow, but it doesn't seem to have the solution to my problem.</p>

<p>I assume I am missing something very obvious due to the sheer lack of experience with systemd, and I'd be extremely grateful if somebody could point it out for me or show me the right direction to move. Thanks in advance and please forgive my mad English skillz.</p>