openHAB 2 startup and shutdown

I have been migrating to openHAB 2 and noticed a few things about starting and stopping openhab 2. I have been starting with ./, this works fine and opens the console, but causes issues if that terminal window dies. When I try nohup ./ it never fully starts.

Also whats the best way to shutdown, with openHab 1.8.x I just did a kill on the pid and it would shutdown cleanly unless it was messed up and then I had to do a kill -9. With openHab 2.x I have tried shutdown then yes in the console and it does indeed shut some things down, but no matter how long I wait it does not fully shutdown unless I kill -9 the pid.

1 Like

The common way to start/stop openHAB would be a script, either init, or (more common these days) systemd (belongs to your linux distribution).

You would start openHAB as a service, e.g. with sudo systemctl start openhab2.service.
You could look for the status of openHAB using systemctl status openhab2.service (yes, without sudo).
And you could stop openHAB using sudo systemctl stop openhab2.service, that’s pretty simple.

To be honest, you wouldn’t have the log output, but this would make no sense in 99% of time anyway :slight_smile:
You can get the whole log the same way as in openHAB1 through openhab.log and events.log file, or - much more convenient - through karaf console.

Right, but I am running the default zips and not a distribution build. So I don’t have systemd / init scripts.

Any ideas on why I can’t shutdown?

Me too and
sudo systemctl stop openhab2.service
works fine for me (Raspbian Jessie). All I did was following the official instructions:

Create the file /lib/systemd/system/openhab2.service with the following content:

Description=The openHAB 2 Home Automation Bus Solution

ExecStart=/opt/openhab2/ server
ExecStop=/bin/kill -SIGINT $MAINPID


Next, enable the service to be executed on system startup, start the service and retrieve status information:

# initialize the new service (execute only once)
sudo systemctl daemon-reload
sudo systemctl enable openhab2.service

#start and retrieve status
sudo systemctl start openhab2.service
sudo systemctl status openhab2.service
1 Like

I’m also seeing openhab2 fail to shutdown cleanly - I eventually have to kill -9 the process.

I’m running the openhab2- rpm under Fedora 25 x86_64 and using systemctl stop openhab2.

How long have you waited? I found it is shutting down, but takes a LONG time.

I’ve waited several minutes. How long did your OH2 instance take to shut down?

Tue May 23 12:47:21 EDT 2017
Redirecting to /bin/systemctl stop openhab2.service
Tue May 23 12:49:23 EDT 2017

However I have seen it take a lot longer. This is also on a dual Intel® Xeon® CPU E5-2690 0 @ 2.90GHz box, so I know cpu is not the issue.