Start OpenHAB on startup
This information was taken from this site: https://mcuoneclipse.com/2015/12/24/autostarting-openhab-on-raspberry-pi/
In “Installing openHAB Home Automation on Raspberry Pi” I have set up openHAB on a Raspberry Pi 2. But when I reboot it, I need to start openHAB manually. This post is about how to start openHAB automatically after a reboot.
Download the following zip file:https://github.com/mepi0011/openhab.doc/raw/master/examples/autostart.zip. It has two file: openhab and openhab.conf which are shown below:
The script file openhab:
In case if I’m using GPIO ports with openHAB, I need to unexport them (seehttps://github.com/openhab/openhab/wiki/GPIO-Binding)
So I add
echo 4 > /sys/class/gpio/unexport
to release GPIO pin 4 before killing openHAB in the stop section.
Place the file openhab into the /etc/init.d/ directory.
The configuration file openhab.conf:
? You might need to change the OPENHABPATH to match your openHAB installation folder.
Place this file openhab.conf into /etc/default/ directory.
Next, I need to set the proper definition. Change current directory to the init.d folder:
Change the file attributes so it can be executed:
sudo chmod a+x openhab
Change the group and owner:
sudo chgrp root openhab sudo chown root openhab
ls -al openhab
if the permissions look like this:
-rwxr-xr-x 1 root root 1821 Sep 30 2014 openhab
Change to the directory where we have copied openhab.cfg:
Insert the script into the run level with:
sudo update-rc.d openhab defaults
This now starts openHAB at boot time. openHAB can be stopped anytime with
sudo /etc/init.d/openhab start
Stopping openHAB works with
sudo /etc/init.d/openhab stop
To reboot, use
If I ever want to undo this, openhab can be removed again from the autostart with
sudo update-rc.d -f openhab remove
I can check if openHAB is running checking if openhab.pid is present in /var/run with
In order to start openHAB automatically, it requires a configuration and a script file. With the proper permissions set and inserted into the autostart sequence, openHAB gets started automatically at boot time, so I don’t need to start it manually.