How to autostart openHAB on a DiskStation

Image source: Andreas Hermsdorf / pixelio.de

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

Internet-of-Things.blog

  • sudo su –

Now you switch to the Debian environment of the DiskStation:

Internet-of-Things.blog

  • /var/packages/debian-chroot/scripts/start-stop-status chroot

Create the script by opening an editor

Internet-of-Things.blog

  • vi /root/check_if_openHAB_is_running.sh

Hit i to switch into insert mode and copy the following script into the editor

Internet-of-Things.blog

#!/bin/bash
# Check if openHAB is running
if /usr/sbin/service openhab2 status > /dev/null
then
echo „Running“
else
echo „Stopped, starting openHAB…“
/usr/sbin/service openhab2 start
fi

Then press <Esc> to exit insert mode. Next type :wq (write quit) to save and exit the editor. Now make the script executable

Internet-of-Things.blog

  • 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 .

General task settings (image source: Internet-of-Things.blog)

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:

Task scheduling settings (image source: Internet-of-Things.blog)

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

Command to run in task (image source: Internet-of-Things.blog)

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.

(Visited 581 times, 1 visits today)

Don't want to miss anything?

Newsletter Subscribe Content

* This field is required

About René Auberger 12 Articles
René is an IT Architect for Internet of Things, Industry 4.0, Analytics and Cognitive Computing. In his spare time he makes his house smarter step by step. In 2017 René founded the Internet-of-Things.blog. He is also frequently tweeting. View René's full profile...

1 Trackback / Pingback

  1. Installing openHAB in only 2 Steps on a DiskStation - Internet-of-Things.blog

Leave a Reply

Your email address will not be published.


*


one × = 2