In my last post about the installation of Zulu JDK to Ubuntu 16.04 server, I covered how to do so and was required so that OpenHAB can run on my server. This post is in the line of my last post and is about the installation of OpenHAB to ubuntu 16.04 server. This post is all about installing OpenHAB to Ubuntu 16.04 using the manual method. I tried with apt-get, but that didn’t work for me.
Navigate to a folder where you can download files and use wget to fetch the latest build of OpenHAB runtime by using the following command,
The URL has to be changed as per the latest build available from,
unzip __downloaded_zip_file_name -d openhab2/
If unzip is not working, it’s not installed and to install use the following command,
sudo apt-get install unzip
The unzip command will extract all the files to openhab2 folder. Now remove the downloaded zip file if you want to free up the space,
sudo rm ___downloaded_file_name
Next step is to create an user for OpenHAB and that can be done using the following command, no home folder will be created for the user and will not have login access to the server,
sudo adduser --system --no-create-home --group --disabled-login openhab
Now make openhab as the owner of openhab2 folder where the runtime files are extracted,
sudo chown -hR openhab:openhab openhab2
Now everything is down and the OpenHAB runtime can be executed. But don’t forget to change the path to the .sh file.
sudo su -s /bin/bash -c '/home/pathto/openhab2/start.sh' openhab
After issue of the above command you can access the OpenHAB instance by navigating to your_ip:8080, on your browser.
Create a file openhab2.service inside /lib/systemd/system folder with the following contents,
sudo nano /lib/systemd/system/openhab2.service
[Unit] Description=My OpenHAB Installation Documentation=http://docs.openhab.org Wants=network-online.target After=network-online.target [Service] Type=simple User=openhab Group=openhab GuessMainPID=yes WorkingDirectory=/home/oksbwn/openhab2 ExecStart=/home/oksbwn/openhab2/start.sh server ExecStop=/bin/kill -SIGINT $MAINPID Restart=on-failure [Install] WantedBy=multi-user.target
Don’t forget to change the path to your .sh file.
After that run the following commands to run the service and will be executed automatically when the server boots up.
sudo systemctl daemon-reload sudo systemctl enable openhab2.service
Now you can interact with the service created, using the following commands for start, status and stop respectively,
sudo systemctl start openhab2.service sudo systemctl status openhab2.service sudo systemctl stop openhab2.service