Now that you have installed openHAB successfully on the DiskStation , you can find out how to start it automatically. This is useful, for example, when the DiskStation is rebooted or openHAB has terminated unintentionally.
Checking openHAB status using a script
First we create a small script, which checks whether openHAB is running. The script can also start openHAB if necessary. Log into the DiskStation using ssh as user admin with your administrator password. Then switch into the root user account with the following command
- sudo su –
Now you switch to the Debian environment of the DiskStation:
- /var/packages/debian-chroot/scripts/start-stop-status chroot
Create the script by opening an editor
- vi /root/check_if_openHAB_is_running.sh
Hit i to switch into insert mode and copy the following script into the editor
# Check if openHAB is running
if /usr/sbin/service openhab2 status > /dev/null
echo „Stopped, starting openHAB…“
/usr/sbin/service openhab2 start
Then press <Esc> to exit insert mode. Next type :wq (write quit) to save and exit the editor. Now make the script executable
- chmod a+x /root/check_if_openHAB_is_running.sh
Schedule a Task in DSM
We are leaving the command line now and move on to the DiskStation's web interface. Open Control Panel and click the Task Scheduler. Then choose Create> Scheduled Task> User-defined Script. Give the new task a name such as "check openHAB" and verify that it will be executed as root user .
On the Schedule tab, specify the frequency at which the task should be executed. I selected to run it every 5 minutes, the whole day, every day:
Last but not least tell DSM which task should be executed by copying the following command into the field User-defined script:
chroot /var/packages/debian-chroot/target/var/chroottarget/ /root/check_if_openHAB_is_running.sh
After saving the new task by clicking Ok you will see the new task in the task list. DSM will now execute it as defined, so that it is regularly checked whether openHAB is (still) running and started if necessary. If you restart the DiskStation now, openHAB will be started within no more than 5 minutes.
Don't want to miss anything?
Newsletter Subscribe Content