I have a service snmpAgent. I do not want to delete the pid file when i do "pkill -9 $pid". But the pid file is getting deleted any help will be great.

Please find below my snmpAgent.service file


ExecStart=$SNMPAGENT_HOME/scripts/snmpAgentserviceStartStop.sh snmpAgentstart
ExecStop=/usr/bin/kill -HUP $MAINPID

  • Why is this a problem? – Sven Jun 22 '17 at 14:46
  • i have another application which restarts the service automatically if the pid is present but the process does not exists...but this is not happening now because of this issue. – user3747182 Jun 22 '17 at 14:48

This sounds like systemd doing a bit of cleanup. Since you are running systemd and your purpose is to automate restart why not just request that systemd automatically restart the agent by adding Restart=always (or similar)to the [Service] section. Then your other app's restart functionality becomes redundant.

  • This is not the purpose..say if i had purposely stopped the service then the pid file should get deleted and the restart should not happen. – user3747182 Jun 22 '17 at 15:02
  • 1
    That's how it works with systemd. It knows not to restart it because you just told systemd directly to stop it. Using another program to handle this is added complexity that's not necessary. If you want to manage the start and stop of the application outside of systemd, take it out of systemd. – yoonix Jun 22 '17 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.