0

I'm running ubuntu 18 and looking at the /etc/init.d/ssh file and I see that the command

if start-stop-daemon --start --quiet --oknodo --pidfile /run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_opts; then 

is used. I understand that this ssh script runs in the background and I can see in the /run directory that the pid file sshd is present and it has a pid number of 1044.

My init.d file is called startup and it will run a python script upon boot and will turn it back on if it crashes. I was wondering how could I get the .pid name of my file. It may not be startup.pid, correct? I know that I can place the line $! after my python line in the shell script but after that I have a variable with $? to capture the scripts return value so I can run it again. Should I scrap this return line and try to create another case with start-stop-daemon so I can try and get the pid of the file or is there a definite way to get the pid file name?

  • systemd will respawn a crashed daemon for you, if you wish. No need to write a whole script to reinvent that wheel. – user535733 Sep 27 '18 at 22:29

Your Answer

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

Browse other questions tagged or ask your own question.