I have a bash script. This script can be started as part of a systemd service (or transient systemd task with systemd-run
). One can also run it stand alone.
How can I see if “the current script” is being run as part of a systemd service?
I can see if the systemd service is running with if systemctl -q is-active my_service_name.service ; then …
, but that will always be true
inside the service. I want to detect if the script is not being run as part of that systemd service.
This is run on Ubuntu Linux 18.04, 20.04 & 22.04, so whatever versions of systemd & bash are installed via apt on them.