"System started" Rule gets executed twice

Hi,

i got this basic rule which starts the motion detection for my backdoor security camera.

rule "Start Motion Detection"
when
	System started
then
	executeCommandLine("/usr/share/openhab/configurations/scripts/cam_backdoor.sh")
end

The Shell Script contains the following content

#!/bin/sh
hotFolder="/home/administrator/C1_C4D6553E69B6/snap" 
logFile="/usr/share/openhab/configurations/scripts/scripts.log"
url="http://localhost:8080/rest/items/backDoorFilename"

while true; do
  inotifywait -m $hotFolder -e create |
  while read path action file; do
		/usr/bin/curl -s --header "Content-Type: text/plain" --request POST --data $file $url
		find $hotFolder* -mtime +1 -exec rm {} \;
  done
done

So basically the shell script will run indefinitely.

I am going to terminate the shell script when the system shuts down with the following rule

rule "Stop Motion Detection"
when
	System shuts down
then
	executeCommandLine("killall cam_backdoor.sh")
end

However i got the problem, that the “System started” Rule gets executed twice.

Here you can see the behaviour on the command line:

root@openHAB:/home/administrator# service openhab stop
 * Stopping openHAB server openhab                                                                                                                                                                                                    [ OK ]
root@openHAB:/home/administrator# ps aux | grep cam_backdoor.sh
openhab    1947  0.0  0.1   4448   804 ?        S    10:17   0:00 /bin/sh /usr/share/openhab/configurations/scripts/cam_backdoor.sh
openhab    1949  0.0  0.2   4448  1412 ?        S    10:17   0:00 /bin/sh /usr/share/openhab/configurations/scripts/cam_backdoor.sh
root       4728  0.0  0.4  11752  2256 pts/0    S+   11:12   0:00 grep --color=auto cam_backdoor.sh
root@openHAB:/home/administrator# killall cam_backdoor.sh
root@openHAB:/home/administrator# ps aux | grep cam_backdoor.sh
root       4731  0.0  0.4  11752  2252 pts/0    S+   11:12   0:00 grep --color=auto cam_backdoor.sh
root@openHAB:/home/administrator# service openhab start
 * Starting openHAB server openhab                                                                                                                                                                                                    [ OK ]
root@openHAB:/home/administrator# ps aux | grep cam_backdoor.sh
openhab    5529  0.0  0.1   4448   800 ?        S    11:13   0:00 /bin/sh /usr/share/openhab/configurations/scripts/cam_backdoor.sh
openhab    5531  0.0  0.0   4448   100 ?        S    11:13   0:00 /bin/sh /usr/share/openhab/configurations/scripts/cam_backdoor.sh
root       5535  0.0  0.4  11752  2260 pts/0    S+   11:13   0:00 grep --color=auto cam_backdoor.sh
root@openHAB:/home/administrator#

What am i doing wrong?

PS: I know that there are workarounds to execute a bash script only once, but i would like to use as most of possible of the openhab system, so that my openHAB Installation is as os agnostic as possible.

Cheers

Andreas

Add some logging to the rule and maybe bump up the openHAB logging to debug and then try to see if there are any events in the log to explain why the rule is being triggered twice. My System started rules only execute once on a reboot as far as I can tell. However, they are also triggered when openHAB reads the rules file (e.g. when I’m editing my files) so if for some reason your rules file gets loaded twice it will trigger twice. Not sure what would cause that though.