Check if OpenHAB is running - Invalid command '' received

Hi,

I have installed OpenHAB2 (Snapshot) using apt-get.
It is running fine.
I wanted to set up a bash-script in Linux that checks regularly if OpenHAB2 is running, and (if not) start it.
I use this script:

if /usr/sbin/service openhab2 status > /dev/null
	then
		echo "Running"
	else
		echo "Stopped, starting openHAB…"
		/usr/sbin/service openhab2 start
fi

The script is running fine. However, every time “/usr/sbin/service openhab2 status” I see an entry in openhab.log:

2017-06-17 13:18:13.460 [WARN ] [ache.karaf.main.ShutdownSocketThread] - Karaf shutdown socket:  Invalid command '' received

It is just a warning, and it seems safe to ignore. But this means my script will pollute my openhab.log. Is there anything wrong with my OH installation? How to solve this warning message?

that’s strange… the service status request shouldn’t interact with the karaf console (i think)
How do you call the bash script?

I tried the same script in my system and I don’t get that warning…
Maybe this is coming from another script/rule/etc?

I log in via SSH and type “/usr/sbin/service openhab2 status” (using the root-user)

I tried the same (copied your script) and I don’t get the same
I checked and I have org.apache.karaf on WARN level so I should get that log entry also… (but I don’t)
I am on S951

Correction: The /etc/init.d/openhab2 script does interact with the Karaf (it executes /usr/share/openhab2/runtime/bin/status which in turn, executes: "$KARAF_HOME"/bin/karaf status "$@"

Do you get the same log entry when you run: /usr/share/openhab2/runtime/bin/karaf status ?

update: If I run it manually, I get the same (Karaf shutdown socket: Invalid command '' received)
This means that the script is not executed correctly (for some strange reason)

Note: If I execute systemctl status openhab2 or service openhab2 status, I don’t get that log entry

Hi,
I’m also on S951.

When I run “/usr/share/openhab2/runtime/bin/karaf status”, I get:

root@DiskStation:/# /usr/share/openhab2/runtime/bin/karaf status
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.utf8)
/usr/share/openhab2/runtime/bin/setenv: line 161: die: command not found
/usr/share/openhab2/runtime/bin/setenv: line 181: [: : integer expression expected
/usr/share/openhab2/runtime/bin/karaf: line 261: [: : integer expression expected
/usr/share/openhab2/runtime/bin/karaf: line 306: [: : integer expression expected
/usr/share/openhab2/runtime/bin/karaf: line 497: /var/packages/java8/target/ejdk1.8.0_121/linux_i586/jre/bin/java: No such file or directory

When running “systemctl status openhab2”, I get:

root@DiskStation:/# systemctl status openhab2
Running in chroot, ignoring request.

When I run “service openhab2 status”, I get:

root@DiskStation:/# service openhab2 status
status: Ignoring predefined value for KARAF_HOME
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.utf8)
Running ...

And that last command also results in a “[WARN ] [ache.karaf.main.ShutdownSocketThread] - Karaf shutdown socket: Invalid command ‘’ received”

I guess it is related to the fact that I have installed OH under chroot. This is a way to have Debian (and thus apt-get) on my Synology.

If you get this error, or one like it, it means your java version isn’t set correctly
/usr/share/openhab2/runtime/bin/setenv: line 181: [: : integer expression expected

Run
java -version
To verify it. If it shows nothing, install java. For ubuntu this is:
sudo apt install default-jre default-jdk
If you are using a really new dev version, you’ll need to switch it:
sudo apt update-alternatives --config java
If you haven’t set these variables:
echo $JAVA
echo $JAVA_HOME
Then you need to set them
sudo nano /etc/environment
The correct value of JAVA_HOME is whatever dir has a bin/java in it (the bin dir in it), that is to say:
sudo updatedb && locate bin/java
or
JAVA=/usr/lib/jvm/java-8-openjdk-amd64

you all are GODS its all working now thanks so much one last thing is there a way i can get it to start if the computer reboots