Cleaning up the startup process / renaming rules (windows possible)

Hi @job,

I like to come back an this topic with my current solution. Now it’s also tested and at least working for me :wink:

But first let me recommend to not alter the upstream version of the openhab2.service file. Instead I would go with an override of the same. One can do this with

sudo systemctl edit openhab2.service

That will create a new file /etc/systemd/system/openhab2.service.d/override.conf with all the content you like. This file will survive also an upgrade of openhab to the next version.

To undo such a change you can also activate the original state with

sudo systemctl revert openhab2.service

The content of the file may e.g. be (according Alternative 3 from the first post):

[Service]
ExecStartPre=/etc/openhab2/exec-scripts/moverules.sh rules rules_away
ExecStartPost=/bin/sleep 240
ExecStartPost=/etc/openhab2/exec-scripts/moverules.sh rules_away rules

Next we want to

sudo systemctl daemon-reload

Now, another alternative is to go with this override to the openhab2.service

[Service]
ExecStartPre=-/bin/bash -c '/usr/bin/find ${OPENHAB_CONF} -name "*.rules" -exec /usr/bin/rename.ul .rules .x {} \\;'
ExecStartPost=-/bin/sleep 90
ExecStartPost=-/bin/bash -c '/usr/bin/find ${OPENHAB_CONF} -name "*.x" -exec /usr/bin/rename.ul .x .rules {} \\;'
TimeoutStartSec=180

Well, TimeoutStartSec is optional, but I found it useful to prevent the openhab2.service to go into failed-state due to long startup times. I’ve set this value to the duration of the sleep (90 seconds) plus another 90 seconds.

9 Likes