How can I tell if a script was called from systemd or from a user?
I created a service for an old school daemon. We just switched to systemd and some of my admin like to call the rc-script directly. This won't work very well in the case of machine reboot. Systemd won't honor the
PIDFile= because the new started daemon is not part of it's cgroup for the service.
I added the service file and the rc_script. I can't differ by user id, because to use the script the user has to be
The stop service is now problem, because systemd will recognize this from the deleted pid file.
So how do I find out if the script was called from systemd?
[Unit] Description=Foobar Service After=syslog.target network.target [Service] Type=forking User=foobaruser LimitNOFILE=60000 LimitNPROC=8000 TasksMax=8000 PIDFile=/local/foobar/foo.pid ExecStart=/opt/foobar/rc_script start ExecStop=/opt/foobar/rc_script stop TimeoutSec=100 TimeoutStopSec=300 KillMode=none RemainAfterExit=no Environment=LANG=de_DE.UTF-8 [Install] WantedBy=multi-user.target
#!/bin/bash case $1 in start) VAR_IS_SYSTEMD=$( ... script to check if bash is run from systemd ... ) if [ "$VAR_IS_SYSTEMD" = false ] ; then sudo systemctl start foobar.service exit fi # start service within systemd ;; stop) # stop service ;; esac