openhab / openhab-linuxpkg

Repo for Linux packages
Eclipse Public License 2.0
18 stars 33 forks source link

Add systemd target for openHAB REST service availibility #138

Open pfink opened 5 years ago

pfink commented 5 years ago

Some other processes may depend on the availability of openHAB's REST service. If they depend on openhab2.service, this won't work because even when openhab2.service is started, REST service needs some extra time to be available. It would be good to setup a systemd target that other services can depend on (similar to network-online.target). I'd suggest openhab2-rest.target. Anyhow, I have no clue how this can be done :/

BClark09 commented 5 years ago

We might be able to implement a shell script which has its own target unit file associated with it.

The script would poll http://localhost:$OPENHAB_HTTP_PORT/rest/ for a 200 response every 5 or so seconds?

pfink commented 5 years ago

Sounds reasonable! But we have to find a solution to prevent this from running in case no REST bundle is installed. Maybe it should first poll openhab-cli and only start to poll REST if the bundle is actually installed? I'm just not sure if bundle:list shows reliable results during startup phase... But maybe there is another possibility, e.g. check a config file?

pfink commented 5 years ago

Other idea, if no automatic detection is possible, would be to prepare this systemd service/target, but keep it disabled by default (so that the user just enable it if needed).

BClark09 commented 5 years ago

A service can be setup to retry a certain amount of times before stopping completely. Perhaps we can check to see if the bundle is active using:

openhab-cli console bundle:list | grep "REST Interface Bundle"
BClark09 commented 4 years ago

Note: that due to the problem described in https://github.com/openhab/openhabian/issues/792 the above commadn wont work without providing a password.