How to autostart openHAB on a DiskStation

Image source: Andreas Hermsdorf /

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/

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 „Running“
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/

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:

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:

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/

Command to run in task (image source:

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 1,076 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 He is also frequently tweeting. View René's full profile...

1 Trackback / Pingback

  1. Installing openHAB in only 2 Steps on a DiskStation -

Leave a Reply

Your email address will not be published.


× 5 = thirty five