Orderly shutdown?

Hi all,
I’m using OH to control my home theatre (KODI, FireTV, AVR, several lights controlled by media player state etc). I’m searching for a reliable way to shutdown; only way I’ve found is via openhab.service:

1.) added line to openhab.service:
  ExecStart=/usr/share/openhab/runtime/bin/karaf  ${OPENHAB_STARTMODE}   ## OH3 start 
  ExecStop=-/home/dietpi/OH3-shutdown.sh                                 ## set SHUTDOWN_SWITCH=ON
  ExecStop=/usr/share/openhab/runtime/bin/karaf   stop                   ## OH3 stop

2.) bash> cat /home/dietpi/OH3-shutdown.sh #secured for user openhab to execute
  # set shutdown switch ON -> invoke shutdown rule
  curl -X POST --header "Content-Type: text/plain"                       \
               --header "Accept: application/json"                       \
                -d "ON"                                                  \ 
				""       # port 8023 in my OH config
  sleep 3s ## wait 3 secs to allow rule "ORDERLY_SHUTDOWN" to be exexuted

3.) Rules file:
      Item SHUTDOWN_SWITCH changed to ON
      logInfo("SHUTDOWN", "SHUTDOWN in progress !")
      // other shutdown statements (max 3 seconds to run )
      // before rule execution stopped by "/usr/share/openhab/runtime/bin/karaf stop"

I’m looking for a more reliable solution as OH is overwriting openhab.service with every (milestone-) release.
Any ideas on that?
Thank you very much in advance.

btw: I’m also using ExecStartPre|ExecStartPost|ExecStopPost in openhab.service

You can also setup another systemd service and make its start/stop dependent on the openhab.service (or any other).
But it’s unclear what you want to achieve. Shutdown your home cinema? OH?
Your post is confusing.

Yes, I want to shutdown/reset my whole home cinema equipment BEFORE OH does the shutdown of rule engine (like media lights off, main light on, AVR/media player shutdown, mqtt cleanup/LWT etc).
I’m simply searching for a way to fire a rule on shutdown as system shutdown rule triggers are no longer supported in OH3.

You’ve already started on the wrong track. OH is supposed to run 24/7. No need to shut it down.


I was confused by the post as well. If I had to restart OH for some reason, I would want it to NOT affect other equipment.

Perhaps this is an XY Problem. Why do you want to shutdown the cinema equipment before OH shuts down? Maybe there’s a better way to achieve the end goal without messing with .service files and such.