Start script for OH2

Here it is: https://github.com/openhab/openhab-distro/blob/master/docs/sources/getting-started.md#registering-openhab-as-a-system-service-in-the-os
Try it out and let me know if there are any issues with it!

Update: It seems that this functionality does not work on the Raspberry Pi, see https://github.com/openhab/openhab-distro/issues/63#issuecomment-171034610 :frowning:

@danielwalters86 Maybe you could add some information about a solution on the RaspPi to https://github.com/openhab/openhab-distro/blob/master/docs/sources/getting-started.md#registering-openhab-as-a-system-service-in-the-os?

I’ve been using my Win10 PC to test the new OH, I’ll try it on the RPi tonight hopefully and update the wiki if the above approach works.

ok, thanks. Would be nice if you could also try the Karaf-based auto-start scripts on Win10, so that we know that at least that works!

I did not have good luck with the auto start service, nor my Raspberry Pi today.

I loaded a fresh OH2 beta download on the Pi, copied my config over (from my existing OH2 alpha install) and the runtime works (generally - I get a few errors in the logs) but when I interact with the items through the widgets, I can see the commands firing but the physical object does not react i.e. lights don’t turn on/off, heating won’t go on/off.

When I go back to my last OH2 alpha nightly everything works again (using same config) so I need to try and figure out what’s going wrong with this new setup.

I tried to install the service on Win10 and I couldn’t not get the “openHAB-service.bat” to run with the install argument. Received the following message:

C:\Users\Daniel\Downloads\openhab-online-2.0.0-SNAPSHOT\runtime\karaf\bin>openHAB-service.bat install
wrapper  | Unable to set working directory to: /C:/Users/Daniel/Downloads/openhab-online-2.0.0-SNAPSHOT/userdata/ (The filename, directory name, or volume label syntax is incorrect. (0x7b))
Unable to get the current logfile size with stat: The filename, directory name, or volume label syntax is incorrect. (0x7b)

starting openhab2 via systemd works fine. so, in fact, there is no need for the karaf service wrapper, obsoleting https://github.com/openhab/openhab-distro/issues/63#issuecomment-171034610

I simply used @danielwalters86 unit file and everthing is fine. q clean solution for all systemd enabled systems.
Stopping works fine, too.

I used the dirty way and placed the unit file in /etc/systemd/system … packages (and their maintainer :smiley: ) should not use this location, but the result will be the same.

Maybe there is a way to get karaf to produce and enable the above file?

@Kai if you’re happy with this I’ll send the PR over.

Sure, please create a PR - thanks!

@danielwalters86 I had the same problem but I noticed the path looked wrong. Keep in mind I don’t really know what I’m doing…

/C:/Users/Daniel/Downloads/openhab-online-2.0.0-SNAPSHOT/userdata/

  1. I removed the extra “/” in from of the path in openHAB-wrapper.conf under wrapper properties where it defines a few paths.

  2. Then I had to allow write permissions on the karaf directory again.

  • Run the install with administrator privileges.

It now looks like it installed correctly but when I run "net start “openHAB” I receive an error:
“The service is not responding to the control function”

@danielwalters86: I tried your systemd script following your instruction (you also PRed, however, on my Raspi 2 with Raspbian Jessie the command
sudo systemctl enable openhab2
always returns
Failed to execute operation: No such file or directory
assuming I’ve put my unit into a file openhab2.

As @jtmoderate876 suggested, I had to put the file not anywhere on the disk but exactly in /lib/systemd/system/ and had to suffix it with .service.

I’ve updated the post and am in the process of updating the PR to reflect that the script needs to be in the /lib/systemd/system folder.

@SuperOok could you look over the PR again and see if you feel it’s accurate now?

looks good, thanks

I need to run openhab:install-service in an install script for a docker. At the minute you have to “docker exec blah blah blah bash” in, run /opt/openhab/start.sh, install-service, logout etc… and then everything will work, but I’d like it to do this in the install script.

Any ideas how to run that command without user input?
Thanks
Christian

Failed to get D-Bus connection: No connection to service manager.
pi@raspberrypi:~$ sudo systemctl start openhab.service
Failed to get D-Bus connection: No connection to service manager.
pi@raspberrypi:~$ sudo systemctl enable openhab
Operation failed: Invalid argument
pi@raspberrypi:~$
pi@raspberrypi:~$ sudo systemctl enable openhab.service
pi@raspberrypi:~$

The systemctl enable seams to work, no error. But the start and status gives this error " Failed to get D-Bus connection: No connection to service manager"

What to do ?

sudo systemctl start (stop)(restart) openhab

no (.service)

Yes same error msg

unfortunately i have no other answer, beyond my knowledge, sorry.

On my installation, I had to use the right spelling:
Systemctl enable (path to file)**openHAB.**service
And then I can do a systemctl start openHAB.

I’m running OH2 on Windows 10. When my system reboots, the system automatically runs the start.bat file.

However, I run into the issue described on (http://stackoverflow.com/questions/37671889/apache-karaf-root-instance-already-running) where Karaf can’t start up because the item.0.pid value in instances.properties is set to a non-zero value.

I’ve never played with .bat files. Is there an easy way to delete the instances.properties file before start karaf.bat? Will this break anything?