Domoticz starting as root, so no scripts run!

Please use template to report bugs and problems. Post here your questions when not sure where else to post
Only for bugs in the Domoticz application! other problems go in different subforums!
Forum rules
Before posting here, make sure you are on the latest Beta or Stable version.
If you have problems related to the web gui, clear your browser cache + appcache first.

Use the following template when posting here:

Version: xxxx
Platform: xxxx
Plugin/Hardware: xxxx
Description:
.....

If you are having problems with scripts/blockly, always post the script (in a spoiler or code tag) or screenshots of your blockly

If you are replying, please do not quote images/code from the first post

Please mark your topic as Solved when the problem is solved.
Post Reply
doh
Posts: 85
Joined: Monday 01 December 2014 14:28
Target OS: Linux
Domoticz version:
Contact:

Domoticz starting as root, so no scripts run!

Post by doh » Monday 25 June 2018 18:02

I'm running Domoticz (v4) on a Raspberry Pi - "Raspbian GNU/Linux 9 (stretch)"

Scripts are not firing, and I've managed to debug this down to the fact that the domoticz.sh service is starting as root - despite the fact that domoticz.sh says to do otherwise:

Code: Select all

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
DESC="Domoticz Home Automation System"
NAME=domoticz
USERNAME=pi
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

DAEMON=/home/pi/domoticz/$NAME
DAEMON_ARGS="-daemon"
#DAEMON_ARGS="$DAEMON_ARGS -daemonname $NAME -pidfile $PIDFILE"
DAEMON_ARGS="$DAEMON_ARGS -www 8080"
#DAEMON_ARGS="$DAEMON_ARGS -sslwww 443"
#DAEMON_ARGS="$DAEMON_ARGS -log /tmp/domoticz.txt"
DAEMON_ARGS="$DAEMON_ARGS -loglevel 1 -syslog local1"

Code: Select all

root@domoticz:/etc/init.d# service domoticz.sh status
● domoticz.service - LSB: Home Automation System
   Loaded: loaded (/etc/init.d/domoticz.sh; generated; vendor preset: enabled)
   Active: active (running) since Mon 2018-06-25 16:57:07 BST; 4min 28s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 10650 ExecStop=/etc/init.d/domoticz.sh stop (code=exited, status=0/SUCCESS)
  Process: 10708 ExecStart=/etc/init.d/domoticz.sh start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/domoticz.service
           └─10715 /home/pi/domoticz/domoticz -daemon -www 8080 -loglevel 1 -syslog local1

Code: Select all

root@domoticz:/etc/init.d# ps -ef | grep domo
avahi      321     1  0 16:14 ?        00:00:00 avahi-daemon: running [domoticz.local]
root     10715     1  2 16:57 ?        00:00:06 /home/pi/domoticz/domoticz -daemon -www 8080 -loglevel 1 -syslog local1
root     11851  6023  0 17:02 pts/0    00:00:00 grep domo

Why won't it start as Pi instead of root, and how can I fix this so my scripts start working again?

Thanks

SweetPants
Posts: 2256
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10007
Location: The Netherlands
Contact:

Re: Domoticz starting as root, so no scripts run!

Post by SweetPants » Monday 25 June 2018 18:28

As far as I know domoticz always has run as root. Try changing your script permissions like chmod 755 <your script>
Ubuntu 16.04.3 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

doh
Posts: 85
Joined: Monday 01 December 2014 14:28
Target OS: Linux
Domoticz version:
Contact:

Re: Domoticz starting as root, so no scripts run!

Post by doh » Monday 25 June 2018 18:53

Tried that and it makes no difference.

If I login as "pi" interactively and run /home/pi/domoticz/domoticz from the command prompt it starts fine and all the LUA scripts execute.

If I run it using the service, where it starts as root, it doesn't.

I've seen another post on here mention that when running as root it doesn't know where to find the LUA scripts, but that was on Ubuntu using service definitions rather than the domoticz.sh scripts. I can't figure out how to get this working properly on the Pi though.

It does look, to me, like it's changed recently - perhaps as part of the upgrade to v4?

dgilbert2
Posts: 53
Joined: Wednesday 16 August 2017 8:08
Target OS: Raspberry Pi
Domoticz version: 4.9728
Location: UK
Contact:

Re: Domoticz starting as root, so no scripts run!

Post by dgilbert2 » Monday 25 June 2018 21:16

Just a thought, when you upgraded to version 4, did you copy the scripts from a backup? They may have lost the execute flag?

doh
Posts: 85
Joined: Monday 01 December 2014 14:28
Target OS: Linux
Domoticz version:
Contact:

Re: Domoticz starting as root, so no scripts run!

Post by doh » Monday 25 June 2018 21:38

No - they were still there from before the upgrade.

And, anyway, if I run domoticz interactively under the Pi user then everything works ok...

doh
Posts: 85
Joined: Monday 01 December 2014 14:28
Target OS: Linux
Domoticz version:
Contact:

Re: Domoticz starting as root, so no scripts run!

Post by doh » Tuesday 26 June 2018 9:31

Anyone running Domoticz on a Pi, preferably as the Pi user, that could share how their service definition with me?

Sipowitz
Posts: 6
Joined: Wednesday 06 June 2018 19:00
Target OS: Linux
Domoticz version:
Contact:

Re: Domoticz starting as root, so no scripts run!

Post by Sipowitz » Saturday 30 June 2018 16:18

Hi

I posted a topic a while back viewtopic.php?f=6&t=23753 because I could not get my scripts to run. I have tried starting domoticz manually as user 'pi' and my scripts now run so I am experiencing the same problem as you. Does anyone know how to run Domoticz as user 'pi'?

Thanks

jaisonshetty
Posts: 1
Joined: Friday 13 July 2018 16:36
Target OS: Windows
Domoticz version:
Contact:

Re: Domoticz starting as root, so no scripts run!

Post by jaisonshetty » Friday 13 July 2018 16:39

hello,
If you add a third slash you must specify the full path:
CODE: SELECT ALL

script:///home/pi/domoticz/scripts/skyhd_pause.sh
Add a simple logline to your script, something like:
CODE: SELECT ALL

#!/bin/bash
NOW=$(date +"%Y-%m-%d")
LOGFILE=/home/pi/sky-remote.$NOW.log
echo $(date +"%Y-%m-%d %H:%M:%S") sky-remote pause | tee -a $LOGFILE
sky-remote-cli 192.168.0.109 pause &
That should create a logfile (every day a new file) and add the timestamp of execution to it.

Personnaly I would set the command as an option in the command line:
CODE: SELECT ALL

#!/bin/bash
NOW=$(date +"%Y-%m-%d")
LOGFILE=/home/pi/sky-remote.$NOW.log
COMMAND="$1"
echo $(date +"%Y-%m-%d %H:%M:%S") sky-remote $COMMAND | tee -a $LOGFILE
sky-remote-cli 192.168.0.109 $COMMAND &
And then use this in domoticz:
CODE: SELECT ALL

script:///home/pi/domoticz/scripts/skyhd_pause.sh pause
That way you can use one script for other commands to, I assume you have other commands to sent as well?

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests