[Solved] Executing Linux command "killall5" via rule with "executeCommandLine" does not have any effect

Hi all,

I have a condition from time to time where I need to recycle my OpenHAB docker container to reset that condition. I found that there is a command killall5 which is located in /sbin/killall5 that initiates the recycle of the docker container:

root@openhab-2:/openhab# ls -l /sbin/killall5 
-rwxr-xr-x 1 root root 23224 Feb 12  2017 /sbin/killall5

killall5 is executable for all users! I can run it from command line as user root and user openhab and the container stops … (and restarts automatically)

I have created a test rule (see below) to initiate the recycle by a rule.
It seems to execute the command but it does not bring down the container.

Does anyone have any advice what I am doing wrong?

rule "Do what I want"
    Item test changed
    logInfo("FILE", "***** Entering: DO WHAT I WANT: " + test.state)

    logInfo("FILE", "***** BEFORE ... ")

    var results = executeCommandLine("/sbin/killall5", 5000)
    logInfo("FILE", "***** RESULT: >" + results + "< *****")
    // executeCommandLine("/sbin/killall5")

    logInfo("FILE", "***** AFTER ... ")


I have also set the following debug level in Karaf log:
log:set debug org.eclipse.smarthome.io.net.exec
because as you can see from the log there is no output from results :

19:35:20.975 [INFO ] [smarthome.event.ItemStateChangedEvent] - test changed from 1 to 2
19:35:21.010 [INFO ] [g.eclipse.smarthome.model.script.FILE] - ***** Entering: DO WHAT I WANT: 2
19:35:21.012 [INFO ] [g.eclipse.smarthome.model.script.FILE] - ***** BEFORE ...
19:35:21.034 [DEBUG] [clipse.smarthome.io.net.exec.ExecUtil] - executed commandLine '/sbin/killall5'
19:35:21.086 [DEBUG] [clipse.smarthome.io.net.exec.ExecUtil] - exit code '0', result ''
19:35:21.088 [INFO ] [g.eclipse.smarthome.model.script.FILE] - ***** RESULT: >< *****
19:35:21.089 [INFO ] [g.eclipse.smarthome.model.script.FILE] - ***** AFTER ...

I would expect that killall5 immediately kills the system like it does, when run from command line …

EDIT: The log output shows that the command is actually executed but the explanation below shows why the command does not have any effect. So the problem was not that the command is not executed correctly but that the command did not have the expected result!!!
But the solution to my problem that I like to stop the system was achieved by leveraging a different command as shown below!!!


maybe that is the reason why:

killall5 is the SystemV killall command. It sends a signal to all processes except the processes in its own session, so it won’t kill the shell that is running the script it was called from. Its primary (only) use is in the rc scripts found in the /etc/init.d directory.

As killall5 does not kill the processes from its own origin shell, it can not kill the system as the rule is initiating the killall5out of the same root shell from which the openhab java process is initiated. Hence killall5 is in the same process tree and does not kill itself …

But I found the solution on my own leveraging the simple kill command: # kill -9 -1

  • The parameter -9 lets kill send the SIGKILL signal to the specified process-id (PID)
  • The parameter -1 represents the PID. When PID equals -1 the signal (here: SIGKILL) is sent to every process for which the calling process has permission to send signals, except for process 1

Hence I changed the rule to:

rule "Do what I want"
    Item test changed to 2
    logInfo("FILE", "***** Entering: DO WHAT I WANT: " + test.state)

    logInfo("FILE", "***** BEFORE ... ")

    val results = executeCommandLine("/openhab/recycle.sh", 5000)
    logInfo("FILE", results)
    logInfo("FILE", "***** AFTER ... ")


to call the following script /openhab/recycle.sh :

kill -9 -1

This kills my docker container and it restarts because of the Restart-Policy: alyways