Install custom services with systemd on the Raspberry 2 using OSMC

Hello,

With the power of the new rpi2 I would like to use it a single box for my home automation and home cinema of course :slight_smile:

I’m using Domoticz for home automation. I try to compile it everythgin works. I can lauch it from the cli and use it with browers. Unfortunately, I am new to systemd. I try to write my own script .service to automatically launch domoticz at startup… but it fails.

Here is the file /etc/systemd/system/domoticz.service :

[Unit]
Description=Domoticz

[Service]
Type=forking
User=root
ExecStart=/dev-domoticz/domoticz -daemon -www 8080 -sslwww 443 
PIDFile=/var/run/domoticz.pid

[Install]
WantedBy=default.target

Then :

systemctl daemon-reload

And :

systemctl start domoticz.service

Here are the output :

root@osmc ~ # systemctl status domoticz.service
* domoticz.service - Domoticz
   Loaded: loaded (/etc/systemd/system/domoticz.service; disabled)
   Active: failed (Result: timeout) since Wed 2015-04-15 04:54:33 CEST; 1min 10s ago
  Process: 10018 ExecStart=/dev-domoticz/domoticz -daemon -www 8080 -sslwww 443 (code=killed, signal=TERM)

Apr 15 04:53:03 osmc domoticz[10018]: 2015-04-15 04:53:03.769  Domoticz V2.2361 (c)2012-2015 GizMoCuz
Apr 15 04:53:03 osmc domoticz[10018]: Domoticz is starting up....
Apr 15 04:53:03 osmc domoticz[10018]: Domoticz running...
Apr 15 04:53:03 osmc domoticz[10018]: 2015-04-15 04:53:03.769  System: Raspberry Pi
Apr 15 04:53:03 osmc domoticz[10018]: 2015-04-15 04:53:03.770  Startup Path: /dev-domoticz/
Apr 15 04:53:03 osmc domoticz[10018]: domoticz: Domoticz is starting up....
Apr 15 04:53:03 osmc domoticz[10018]: domoticz: Domoticz running...
Apr 15 04:54:33 osmc systemd[1]: domoticz.service start operation timed out. Terminating.
Apr 15 04:54:33 osmc systemd[1]: Failed to start Domoticz.
Apr 15 04:54:33 osmc systemd[1]: Unit domoticz.service entered failed state.

Maybe am I missing something in the config file ? I look several website and documentation about systemd and custom .service files but I can’t find any solution :frowning:

Anyone knows ?

It looks to me that Domoticz is starting up ok but is not creating the PIDFile /var/run/domoticz.pid as the service is expecting, therefore after a timeout with no pidfile appearing systemd will terminate the process.

Check that Domoticz is creating the pid file correctly, if not you need to find why, OR simply remove the PIDFile option in the Unit - for a forking daemon which only forks one process systemd can normally identify the correct PID for the daemon without help of a PIDFile. Only if it forks multiple processes (such as apache) do you need to use the PIDFile option.

Hi,

Thanks for your reply.

You were rigjt abot the PID file. I launch manually domoticz and I find his PID file in /run (domoticz.pid).

So I try what you advise : delete the line

PIDFile=/var/run/domoticz.pid

from /etc/systemd/system/domoticz.service

Unfortunately same issue remains.
SO I tried with the “good” path:

[Unit]
Description=Domoticz

[Service]
Type=forking
User=root
ExecStart=/dev-domoticz/domoticz -daemon -www 8080 -sslwww 443
PIDFile=/run/domoticz.pid

[Install]
WantedBy=multi-user.target

Same thing :frowning:
Any idea ?

Perhaps port 8080 is already in use on osmc for a different service…
try another more obscure port like 8888

This thread is 1.5 years old. I think they’ve probably solved their problem by now.