We have a shell script that -- for various reasons -- wraps a vendor's application. We have system administrators and application owners who have mixed levels of familiarity with systemd. As a result, in situations where the application has failed (systemctl indicates as much), some end users (including “root” system administrators) might start an application “directly” with the wrapper script instead of using
systemctl restart. This can cause issues during reboots, because systemd does not call the proper shutdown script -- because as far as it's concerned, the application was already stopped.
To help guide the transition to systemd, I want to update the wrapper script to determine whether it is being called by systemd or by an end-user; if it's being called outside systemd, I want to print a message to the caller, telling them to use systemctl.
How can I determine, within a shell script, whether it is being called by systemd or not?
You may assume:
- a bash shell for the wrapper script
- the wrapper script successfully starts and stops the application
- the systemd service works as expected
An example of the systemd service could be:
[Unit] Description=Vendor's Application After=network-online.target [Service] ExecStart=/path/to/wrapper start ExecStop=/path/to/wrapper stop Type=forking [Install] WantedBy=multi-user.target
I am not interested in Detecting the init system, since I already know it's systemd.