OH2.2.0 unable to start via LaunchDaemon on macOS

Anyone find a solution to this basic problem?

i made the start.sh executable and added it to the start items for my account.
it’s not beautiful because a terminal window is shown but it works.

i have the problem that oh constantly restarts when i configure the daemon.
maybe a launch agent is the way to go? i am not a developer so i don’t know exactly.

regards

jonas

maybe this helps

for me the problem was the karaf console. You can see it on this line

Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)

so I don’t use the start.sh script if I run it as a daemon

using the start.sh script works for me until version 2.1.0 but not after.

Hi Holger, you mention that you don’t use start.sh when starting openHAB as a daemon. How do you start it then? Can you share your plist file? I tried to start karaf directly but still get the same error with the dumb terminal and eventual shutdown.

Thanks!

Hi everyone, I think I found a solution to this problem by adding the parameter ‘server’ to the launchscript for karaf. I think this make sure karaf doesn’t try to launch a terminal:

#!/bin/sh

echo Launching the openHAB runtime…

DIRNAME=dirname "$0"
exec “${DIRNAME}/runtime/bin/karaf” server “${@}”

Hi @Berthold. My startscript works similar. The main problem was that the start.sh script is starting karaf with parameter “start”. (internally the start.sh script calls “…/karaf start”) This includes the startup of the karaf console which is the reason why the rest does not work.

I’m just surprised that there is a parameter “server”. I use the parameter “daemon”.

So what I call from my daemon script is “…/karaf daemon”. This disables the karaf console and everything works fine.

Now you have to options. Either modify start.sh to use the

I changed it to

can you please post your daemon here?
i am still stuck at this …
I managed to make an executable start.command that starts the karat like the start.sh does.
but this opens a terminal window.

I’m not sure if this helps you, because I’m using systemd

at the end you can use the start.sh script too. Just be sure that you call it with the parameter “daemon”

means something like “start.sh daemon” should work. If this is not enough you can also export the environment variable OPENHAB_STARTMODE=daemon. But I guess this variable was just a helper and is not really needed.

I found the solution at apache.org.
See this link: Karaf Wrapper

You simply login to the Karaf console and enter:

openhab> feature:install service-wrapper
openhab> wrapper:install

A *.plist file will be generated and you get instructions how to install and start as a LaunchDaemon.
Hth,
Manolo

hmmm did not work for me. I copied the plist (per drag and drop but that should not matter) into launch deamons and set the rights as described but OH does not start :frowning:

Sorry Jonas88

I had a check again and it seems that the karaf wrapper doesn’t work out of the box with openhab2.
There are some issues with the karaf config.

Nonetheless using the start.sh adding the server parameter should work. Did you test it?

i had to rename start.sh into start.command to be able to execute it at startup.
do you mean I just have to add the server parameter there or how did you execute the start.sh at launch? did you create the .plist linked In the article for OH1?

On which operating system are you using openhab? macOS?

jup mac os 10.13.5
edit: I’ll give it a try with the server parameter in the .command file. reporting back in a minute

ok further progress using the parameters.
server: the terminal window has to stay open or it will quit the server (makes sense).
daemon: I can quit the terminal window and openhab is still running. :slight_smile:
now I just need to quit the window after execution. :slight_smile: any advice?

Well it is suffice to create a start.sh file or use the existing one. It needs to be made executable

chmod 755 start.sh

my start.sh:

#!/bin/sh

echo Launching the openHAB runtime...

DIRNAME=`dirname "$0"`
exec "${DIRNAME}/runtime/bin/karaf" server "${@}"

My plist in LaunchDaemons looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
	<dict>
	    <key>StandardOutPath</key>
	    <string>/Users/macadmin/Desktop/openhab2/daemon.log</string>
	    <key>StandardErrorPath</key>
	    <string>/Users/macadmin/Desktop/openhab2/daemon.log</string>  
	    <key>KeepAlive</key>
	    <false/>
	    <key>Label</key>
	    <string>org.openhab.server</string>
	    <key>EnvironmentVariables</key>
	    <dict>
	      <key>OPENHAB_HTTP_PORT</key>
	      <string>9080</string>
	      <key>OPENHAB_HTTPS_PORT</key>
	      <string>9443</string>
	    </dict>
	    <key>ProgramArguments</key>
        <array>
                <string>/Users/macadmin/Desktop/openhab2/start.sh</string>
        </array>
	    <key>RunAtLoad</key>
	    <true/>    
	    <key>UserName</key>
		<string>macadmin</string>
	</dict>
</plist>

3 Likes

Thank you so much, this has sorted it for me. I’m using the same LaunchDaemon, and just added the server to the start.sh and it works. Now running 2.3 on MacOS.

You sir are a hero :slight_smile:
Thanks a lot!

Can someone include this daemon, start.sh-modification and an instruction on how to create a plist and own it to root on Mac OS to the openHAB Logs?

Just wanted to say thanks for all the folks in this thread, I ran across the issue and updating start.sh solved it for me.

This is great. Thank you so very much. I used this listed start.sh and the plist and my openhab now works on mac startup and without a terminal app open window.
I was able to log out or not even login after mac startup and was able to access my openhab both locally and remotely.
All one needs to do here is make sure the directory name is correct and the user name is correct.
In my case, I have my openhab on the root directory so it is not in usr specific directory.
Thanks again .
Great job