Linux

From Domoticz
Jump to navigation Jump to search

This page describes how to compile/build the latest beta snapshot of Domoticz for Debian-based Linux operating systems.

There's no need for all this if you're just installing a pre-built binary (see the downloads page for that).


Use pre-built installation

If no source code changes or special compile actions/environments are needed just install a pre-built binary (see the downloads page for that). Minimum supported Ubuntu version for pre-built: 20.04 LTS

Ubuntu installation in terminal:

sudo bash -c "$(curl -sSfL https://install.domoticz.com)"


You will get an install dialog and some questions will be asked about HTTP/HTTPS enablement for WebUI and related ports.

Just point your browser to the IP address of your Linux system, and use the port specified during the installation script.
For example: http://192.168.0.10:8080.
From 2023.1 Stable: By default Domoticz is protected by a username (admin) and password (domoticz).

Now you can go on and visit the Getting started documentation area for more information.


Use Docker container

You can also install Domoticz as a Docker container. Go to wiki page Docker for the instructions

Compiling the source code

If you made source code changes or your environment is not compatible with the pre-built images you can compile and install Domoticz yourself.

Follow the steps provided here:

Build_Domoticz_from_source


Allow non-root user to access ttyUSB* ports

If you don't plan on interfacing Domoticz with USB and/or serial devices, you can skip this step.

By default (at least on Ubuntu) a non-root user has no permission to access the ttyUSB* ports. So if you have Domoticz running under a separate user (which is always a good idea to make the system more secure), Domoticz isn't allowed access to your RFXCOM for example. Here are two methods of doing it. For most people the first one by adding the user to the dialout goup is enough and by far the easiest.

Adding the user to the dialout group

This can be done by running the command below:

sudo usermod -a -G dialout YOURUSERNAME

(Where you replace YOURUSERNAME with the user that runs Domoticz.)

Setting up a udev rule

Alternatively you can setup (as root) a udev rule that matches the RFXCOM device. To find which attributes match your device use the command:

udevadm info -a -p $(udevadm info -q path /dev/ttyUSB1) | less

Where /dev/ttyUSB1 is the device. If you wish to run Domoticz under the YOURUSERNAME credentials, who is member of the YOURGROUPNAME group and your device has serial YOURSERIAL a suitable udev rule would be:

SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ATTRS{serial}=="YOURSERIAL", ATTRS{idProduct}=="6001", SYMLINK+="ttyUSB21", OWNER="YOURUSERNAME", GROUP="YOURGROUPNAME"

Save it to a file under /etc/udev/rules.d/ with the .rules extention and run:

service udev reload

Unplug and replug the device and execute:

ls -l /dev/ttyUSB*

You should see something like

crw-rw---- 1 domoticz domoticz 188, 1 Nov 10 15:27 /dev/ttyUSB1
lrwxrwxrwx 1 root     root          7 Nov 10 15:27 /dev/ttyUSB21 -> ttyUSB1

The added SYMLINK+= creates an additional link to the device node. This is a static name that is useful when you have multiple usb-serial devices that go into your box. Use the static link in Domoticz. For more information on udev rules have a look here: http://www.reactivated.net/writing_udev_rules.html

Starting Domoticz automatically when the system boots

There are basically two ways to do this - via init.d (which starts things serially) or via systemd (which starts things up in parallel and therefore leads to faster booting). On modern systems the systemd method is generally preferred.

Note: The "pre-built" install method already creates a service that starts Domoticz after reboot or restart of your system.

Option 1: Init.d Method (not preferred)

To let Domoticz start automatically when the system boots (which is probably the case, as most people run it on a headless server), run the commands below, (You want to end up in /home/YOURUSERNAME/domoticz/)

cd domoticz
sudo cp domoticz.sh /etc/init.d
sudo chmod +x /etc/init.d/domoticz.sh
sudo update-rc.d domoticz.sh defaults

Edit the startup script.

sudo nano /etc/init.d/domoticz.sh

The lines you usually need to change are USERNAME, DAEMON and DAEMON_ARGS

USERNAME=yourusername
DAEMON=/home/$USERNAME/domoticz/$NAME
DAEMON_ARGS="-daemon -www 8080"
  • Change the USERNAME variable to the user you want domoticz to be run as. It's recommended to run domoticz as its own user and not as root, due to security reasons.
  • If you installed Domoticz in the USERNAME home directory /home/yourusername/domoticz you don't need to change the DAEMON variable. If you installed it in an alternate location for example /usr/local/domoticz/ you should change DAEMON to /usr/local/domoticz/$NAME
  • If you want to use another web interface port change the '8080' in: DAEMON_ARGS="-daemon www 8080" to your own port.

Note: To be able to use ports below 1024, for example the standard port for webbrowsing, 80, you need to run domoticz as the root user.

If you want to see more arguments for DAEMON_ARGS run this in the domoticz directory (or check page Command line parameters). This is usually not needed.

./domoticz -h

Domoticz will now start automatically when you reboot your machine.

Manually controlling the Domoticz service

This only works if you followed the above steps.

You can now start/stop/restart and check the status of domoticz with:

sudo /etc/init.d/domoticz.sh start
sudo /etc/init.d/domoticz.sh stop
sudo /etc/init.d/domoticz.sh restart
sudo /etc/init.d/domoticz.sh status

If your system supports it you can instead use:

sudo service domoticz.sh start
sudo service domoticz.sh stop
sudo service domoticz.sh restart
sudo service domoticz.sh status

Option 2: Systemd Alternative (Preferred)

Open the systemd configuration file, here you can change the port number you wish to use. To use a port below 1024 you can run as root (not reccomended) or you can un-comment one of the marked lines in the file - you should only un-comment one of the lines depending on your Ubuntu version :

vi /etc/systemd/system/domoticz.service
[Unit]
       Description=domoticz_service
[Service]
       User=domoticz
       Group=domoticz
       EnvironmentFile=/home/pi/domoticz.env
       ExecStart=/home/domoticz/domoticz/domoticz -www 8080 -sslwww 443
       WorkingDirectory=/home/domoticz
       #        
       # Give the right to open priviliged ports. This allows you to run on a port <1024 without root permissions (user/group setting above)
       #
       # The following line is for pre-16.04 systems.
       # ExecStartPre=setcap 'cap_net_bind_service=+ep' /home/domoticz/domoticz/domoticz
       #
       # The below works on Ubuntu 16.04 LTS
       # CapabilityBoundingSet=CAP_NET_BIND_SERVICE
       #
       # The following works on Ubuntu 18.04
       # AmbientCapabilities=CAP_NET_BIND_SERVICE
       #
       Restart=on-failure
       RestartSec=1m
       #StandardOutput=null
[Install]
       WantedBy=multi-user.target

or on Raspberry Pi Stretch as root (remove '#' on User and Group lines to run as 'Pi' user):

[Unit]
      Description=domoticz_service
[Service]
      #User=pi
      #Group=users
      ExecStart=/home/pi/domoticz/domoticz -www 8080 -sslwww 443
      EnvironmentFile=/home/pi/domoticz.env
      WorkingDirectory=/home/pi/domoticz
      ExecStartPre=setcap 'cap_net_bind_service=+ep' /home/pi/domoticz/domoticz
      Restart=on-failure
      RestartSec=1m
      #StandardOutput=null
[Install]
      WantedBy=multi-user.target

on Raspbian Linux 10 (buster), I had to add this just before ExecStartPre=setcap now it works. I don't know about security implications!!
The service file must add the directive "PermissionsStartOnly=true", in order to be able to execute the "ExecStartPre=/sbin/setcap 'cap_net_bind_service=+ep' ..." one!
For extra command line parameters in line ExecStart= check page Command line parameters


If you want to set some specific environment variable for the execution of the domoticz daemon, you can use the filename specified in the EnvironmentFile clause to do so. Here for example, we are setting the PYTHONPATH to use a local python environment .

vi /home/pi/domoticz.env
PYTHONPATH="/home/domoticz/Domoticz_Python_Environment/:$PYTHONPATH"


Enable the service

systemctl daemon-reload
systemctl enable domoticz.service

Start the service

systemctl start domoticz.service

Note: Use only one of these two alternatives (init.d method or systemd method) for auto-start.

Updating Domoticz

Once in a while, a new Domoticz version is released, and of course you want to update.

Use the Web Interface to update Domoticz (Menu Setup->Check for Updates)

If this fails for any reason (e.g. partial download giving segmentation fault) then you should manually update by:

  1. Navigate to the directory where Domoticz is installed: cd domoticz (You want to end up in /home/YOURUSERNAME/domoticz/)
  2. Update to the latest Beta with: sudo ./updatebeta
  3. Update to the latest Release with: sudo ./updaterelease

If all went correctly, Domoticz should be updated to the latest version and should be running again automatically.

Revert to backup after incorrect update

For updates (beta and stable) an automatic backup of the complete domoticz environment including scripts and plugins is created in domoticz/backups/domoticz_backup_yyyymmdd_hhmmss.tar.gz by the update script.

To extract that backup:

  • enter domoticz backup directory (where domoticz store a backup before upgrading)

cd ~<USER>/domoticz/backups

  • run tar command to extract the backup (specify the right filename and correct domoticz folder)

tar xvzf domoticz_backup_yyyymmdd_hhmms.tar.gz -C /home/<USER>/domoticz

  • restart domoticz

service domoticz restart



Attention: when you use Monit, be sure to disable it before doing the update process, otherwise after you have stopped Domoticz by hand yourself, it will get restarted automatically by Monit within a few minutes (because that is what is Monit should do normally).
Stopping Monit can be done by sudo /etc/init.d/monit stop and after updating it can be started again with sudo /etc/init.d/monit start.
You could also use this command: make && sudo /etc/init.d/domoticz.sh start && sudo /etc/init.d/monit start to update, start Domoticz & start Monit when updating is done.

Script to update almost automatically

For updating almost automatically, i made this script

#! /bin/sh
cd /home/YOURUSERNAME/domoticz/ \
&& sudo /etc/init.d/monit stop \
&& sudo /etc/init.d/domoticz.sh stop \
&& git pull \
&& make \
&& sudo /etc/init.d/domoticz.sh start\
&& sudo /etc/init.d/monit start

Save it as domoupdater.sh, give it executable rights (chmod +x domoupdater.sh) and call it by sh /home/YOURUSERNAME/domoupdater.sh
It will change the current path to the Domoticz folder, stop Monit, stop Domoticz, pull binaries, compile, start Domoticz, start Monit again.
Very handy to run & go do something else.

In theory it can work automatically (weekly cronjob for example), however when running as a non-root user (which is the case in my situation), it will ask for the password of the user. But after you have provided the password (almost immediately after the script has started), it will continue without needing any further user input.
In theory it is possible to let it run fully automated, but i myself prefer a bit of feedback (watching afterwards if all went well). If you want to work around this sudo password asking, look here.

when compiling the main Domoticz binary. For more information read this thread on the forum: Link

Problems locating Python

Some users, particularly those on old operating systems see the following message when starting Domoticz:

 2016-12-20 09:44:32.251 Failed dynamic library load, install the latest libpython3.x library that is available for your platform. 

this shows that, even though python3 may be on the system, the python library can not be located. This error will not stop Domoticz from starting but will mean that hardware supported by the Python Plugin Framework will not be available. To fix this, install the newest version of libpython3 for the platform. For example, RaspberryPi Jessie has python 3.4 on it but the library is not included. Executing:

 sudo apt-get install libpython3.4

should solve the issue. Note that python 3.4 is the earliest support version of python, where available later versions should always be used.
If you are building from source and python 3 is installed but Make is not able to progress, try to add

 set(Python_ADDITIONAL_VERSIONS 3.4)

just before find_package(PythonLibs 3.4) in the CMakeLists.txt

If your platform does not have a compatible version, for example RaspberryPi Wheezy, then one can be built from source using:

 wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tar.xz
 tar -xvf Python-3.5.2.tar.xz
 cd Python-3.5.2
 ./configure --enable-shared
 make
 sudo make install

Don't miss the enabled-shared flag otherwise libpython will not be built.

Note: Only peform this step if you are building from source and are having issues, it should not be required.
After building Python 3.5.x change CMakeLists.txt

 option(USE_PYTHON_PLUGINS "Use Python Plugins" YES)
 IF(USE_PYTHON_PLUGINS)
   set(Python_ADDITIONAL_VERSIONS 3.5)      <---- add this line
   find_package(PythonLibs 3.5)   <---- change version into 3.5
   IF(PYTHONLIBS_FOUND)

Monitoring Domoticz

Software crashes, it's a fact of life. Luckily there are a number of ways to keep an eye on Domoticz, and automaticallty restart it if it crashes. The following page gives instructions Monitoring domoticz

Add support for Tellstick

If you need support for Tellstick or Tellstic Duo you need to install telldus-core before compiling Domoticz. On Debian-based systems (For example Ubuntu and Raspbian) telldus-core can be installed by doing the following:

echo "deb http://download.telldus.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/telldus.list
wget -q http://download.telldus.se/debian/telldus-public.key -O- | sudo apt-key add -
sudo apt-get update
sudo apt-get install libtelldus-core-dev
  

How to set up a virtual machine to run Domoticz

How to set up a virtual machine to run Domoticz