Autostart openhab server with osmc in raspberry pi 3

Hi,
I’m trying to start openhab parallely with OSMC at boot. I tried the following crontab, rc.local and with systemd. I dont know why its not auto starting, but I could start manually from SSH. Kindly Help me out.

The best way to do this is with a systemd script. Can you post the output of the following commands?

sudo systemctl start openhab
and
sudo systemctl status openhab

You’ll need to change openhab to whatever you have called your systemd service.

Thanks

In systemd the sevice file I have the following,
[Unit]
Description=openhab
After = mediacenter.service

[Service]
Type=simple
User=osmc
ExecStart=/opt/openhab/start.sh

[Install]
WantedBy=multi-user.target

when I try to enable the following comes up
sudo systemctl enable openhab

Synchronizing state for openhab.service with sysvinit using update-rc.d…
Executing /usr/sbin/update-rc.d openhab defaults
Executing /usr/sbin/update-rc.d openhab enable
Failed to execute operation: File exists

When I try to start the following pops,

sudo systemctl start openhab
Failed to start openhab.service: Unit openhab.service failed to load: Invalid argument. See system logs and ‘systemctl status openhab.service’ for details.

The status when
sudo systemctl status openhab

  • openhab.service - openhab
    Loaded: error (Reason: Invalid argument)
    Active: inactive (dead)

Sep 04 11:06:29 osmc systemd[1]: [/lib/systemd/system/openhab.service:10] E…sh
Sep 04 11:06:29 osmc systemd[1]: openhab.service lacks ExecStart setting. R…g.
Sep 04 11:10:00 osmc systemd[1]: [/lib/systemd/system/openhab.service:10] E…sh
Sep 04 11:10:00 osmc systemd[1]: openhab.service lacks ExecStart setting. R…g.
Sep 04 11:10:00 osmc systemd[1]: [/lib/systemd/system/openhab.service:10] E…sh
Sep 04 11:10:00 osmc systemd[1]: openhab.service lacks ExecStart setting. R…g.
Sep 04 11:16:21 osmc systemd[1]: [/lib/systemd/system/openhab.service:10] E…sh
Sep 04 11:16:21 osmc systemd[1]: openhab.service lacks ExecStart setting. R…g.
Sep 04 11:16:21 osmc systemd[1]: [/lib/systemd/system/openhab.service:10] E…sh
Sep 04 11:16:21 osmc systemd[1]: openhab.service lacks ExecStart setting. R…g.
Hint: Some lines were ellipsized, use -l to show in full.

I dont know how to configure the service file ExecStart= /path/

I want run openhab on port 8070 as osmc will run in 8080

I tried by adding www 8070 to the Execstart, But I dont know that is correct or not

sudo systemctl status openhab

  • openhab.service - openhab
    Loaded: loaded (/lib/systemd/system/openhab.service; enabled)
    Active: failed (Result: exit-code) since Sun 2016-09-04 12:13:57 IST; 5s ago
    Process: 1807 ExecStart=/opt/openhab/start.sh (code=exited, status=127)
    Main PID: 1807 (code=exited, status=127)

Sep 04 12:13:56 osmc start.sh[1807]: Launching the openHAB runtime…
Sep 04 12:13:56 osmc start.sh[1807]: /opt/openhab/start.sh: 16: /opt/openhab/start.sh: java: not found
Sep 04 12:13:57 osmc systemd[1]: openhab.service: main process exited, code=exited, status=127/n/a
Sep 04 12:13:57 osmc systemd[1]: Unit openhab.service entered failed state.

And there you have your answer right before you in bold text. Openhab requires java and java is not found.

As it works when started from the command line that would suggest that your java configuration is good so I’m going to ignore that particular area.

The most likely cause then is that Openhab is starting before java is ready. What you need to do is find out what “target” java is started for and then set your openhab.service file to depend on that target.

That said in my personal experience systemd leaves an awful lot to be desired in this regard and you may find it easier to create the following script.

sudo nano /usr/bin/openhab-restart.sh

containing the following:

#!/bin/bash
sleep 30
systemctl restart openhab

Ctrl+O and Ctrl+X to save and exit.

Then sudo nano /etc/rc.local

and insert the following on the line before exit 0:

/usr/bin/openhab-restart.sh

This is a bit of a nasty hack but what is does essentially is restart openhab 30 seconds after boot so that java will be ready. You can reduce the time until it won’t start and then add 5 seconds to it if you don’t want to wait the full half minute.

Also you seem to have both sysvinit scripts (those in /etc/init.d/ and systemd scripts. For the systemd ones to work you’ll need to disable and remove the init scripts.

Regarding how to set openhab to use a different port you will need to ask that on the openhab forums because it has nothing to do with OSMC, it is specific to openhab.