while playing around with my Raumfeld Devices i came to a point where I want to see if my Raumserver is running on my openHAB Server (Ubuntu).
When testing things out I created a script and HABPanel Widget that can check the status of a linux program and start/stop it. I’ve tried to built it for use with any daemon/program on linux, so it could maybe used for different purpose.
Exec Binding has to be installed.
What i’ve done:
Create a bash script runprogram.sh in the openHAB scripts folder
#!/bin/bash
#
# Script used by openHAB2 to check, start and stop a program on command line
status(){
[ "$(pidof $1)" ] && echo "ON" || echo "OFF";
}
start(){
$1
}
stop(){
killall $1
}
case "$1" in
start)
start $3$2
;;
stop)
stop $3$2
;;
status)
status $2
;;
restart)
stop $3$2
start $3$2
;;
*)
echo "Usage: $0 {start|stop|status|restart} program programpath"
exit 2
esac
to use this you need to call it with 3 parameters:
what should be done: start, stop, status, restart
program name: this has to be the name of the running process (used to start, check and kill it)
program path: this is the path to the executable file used to start it (see parameter 2)
Create a thing for the exec binding
Thing exec:command:raumservercheck [command="/etc/openhab2/scripts/runprogram.sh status raumsrvDaemon /etc/raumserver/raumserverDaemon/", interval=15, timeout=5]
Create an string item that receives ON or OFF from the status of the script
Create a rule that reacts on received commands for item
rule "RaumserverStart"
when
Item Raumserver received command ON
then
logInfo("raumserver.start", "Raumserver starting")
executeCommandLine("/etc/openhab2/scripts/runprogram.sh start raumsrvDaemon /etc/raumserver/raumserverDaemon/")
end
rule "RaumserverStop"
when
Item Raumserver received command OFF
then
logInfo("raumserver.stop", "Raumserver stopping")
executeCommandLine("/etc/openhab2/scripts/runprogram.sh stop raumsrvDaemon /etc/raumserver/raumserverDaemon/")
end
So that switch shows you the current state of the program/daemon and you can start/stop it.
I hope this maybe helps some users or gives you inspiration
I’m not a linux pro, so maybe this script is not the best. If somebody has ideas to make something better please let me know. At the moment it is maybe not the best solution, but it works for me
@sondi
Realizing that the thread is quite old, I hope you can help me out anyway.
I installed Raumserver on my OH3.2.0 system (PI4) via NPM.
I now want to start/stop it with a rule, similar as your scenario above.
I do not find the raumsrvDeamon anywhere.
What do I need to do to get a start/stop rule working?
thanks,
Frank
it has really be a little time since I last used that. A few years ago I’ve switched from Raumfeld to Sonos - so I’m not using this anymore.
When I got your problem right you can’t find the RaumserverDeamon after the installation. I’ve taken a quick look at the Raumserver repo and the one that is installed be npm seems to be a complete new Version that is using nodeJS. So the Raumserver is started with “npm start”. I think you could start and stop the Raumserver with commands like these:
Getting executeCommanLine to work can be a real bugger sometimes.
This is a good sign that the basic command is correct but something may be keeping it from running within openHAB. My first guess would be to check permissions on the script itself. Make sure the user openHAB runs as can execute the script. Doing so isn’t easy though because usually the user openHAB runs as does not have command line abilities
Edit to add: somewhere on this forum is a thread about getting it working… search
@rossko57
thanks for the hint.
I received the folllowing
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
sudo: no tty present and no askpass program specified
I then checked my sudoers.d file and changed it, so that the NPM command should be allowed without password.
Now … it looks like there is no STOP script defined in the package.js file for raumserver. What do I need to do to also enable STOP of raumserver via execcommandline??
nice to hear that you’ve got the START working. Because I’m not involved in the development of the raumserver (i was just a simple user) I can’t do anything to implement such a STOP script into the raumserver.
What you maybe could do is check the processes that are running when the raumserver is running an kill the whole process with linux standard command “kill” or “killall”, maybe with the command
killall node
(if node is the correct name of the process). Or maybe a better way is to get the PID of the running process and kill this one. I think for that you have to write a little bash script that searches the PID and then runs the kill command with that PID as parameter.
I’ve found this information about killing a node process on a linux machine. Maybe some linux enthusiastic can say more about that option.