How to automatically switch HABApp launch mode

I use the command /opt/habapp/bin/habapp -c /etc/openhab/habapp to debug my rules, and I can see the result of executing print command. However, if I close the terminal session,
the execution HABApp is interrupted. On the other hand, if you execute the /opt/habapp/bin/habapp -c /etc/openhab/habapp < /dev/null & exit 0, the terminal session is closed, but the HABApp does not stop.
Unfortunately, if I run /opt/habapp/bin/habapp -c /etc/openhab/habapp again, duplication of messages occurs, which is logical.
The question is how to make a script that restarted the HABApp automatically when the terminal session ended and vice versa?

Why don’t you run it as a service? If you want to debug stop the service and start HABApp manually?

However I recommend running it as a service and log to a file.
That way you never have to stop/start/restart HABApp.
Instead of print use a logger.

Of course, I tried to use the service, but I wanted to use the print only for debugging, I write only the necessary information to the log file, it seems to me that this will be more convenient.

Why not log the debug information with log level DEBUG and switch the logger to INFO once you are done debugging. This even goes on the fly without restarting HABApp…

1 Like

Sebastian, you convinced me, thank you!
By the way, I use the extended format for MyRule logger, maybe it will be useful to someone
MyFormat_format:
format: ‘%(asctime)s.%(msecs)03d [%(levelname)-5s] [%(name)s:%(filename)s.%(funcName)-18s] - %(message)s’
datefmt: ‘%Y-%m-%d %H:%M:%S’

1 Like

nice, thank you! i adopt that :+1: