I'm running a CentOS6 instance and have an upstart job that depends on sshd to already be running. However when I boot up the box that job fails to start, I'm guessing because sshd isn't actually running yet. Is there a way I can delay upstart jobs from starting until all normal init scripts have started?

  • 1
    What is the priority of your startup script? You can order startup scripts at the appropriate runlevel by changing their numbers manually or by using some utility for configuring runlevels. Check centos.org/docs/5/html/Installation_Guide-en-US/… – jpe Aug 24 '13 at 15:49

I ended up figuring this out. CentOS6 uses upstart as its init program, but one of the scripts it initializes in /etc/init is rc.conf, which starts up the old-school rc scripts. So if you need your program to start AFTER those you can put:

start on started rc stop on stopped rc

in your upstart script and you should be good to go.

  • stop on stopped rc didn't seem to work for me; it stopped straight away. I think this is because rc is a task, not a service. I used stop on runlevel [016] instead. – Dave Gregory Dec 18 '17 at 11:08
  • rc is stopped and started on every runlevel transition. This probably isn't what you want. – Leolo Jun 8 '18 at 18:33

You can check process sshd with pidfile /var/run/sshd.pid in your script to make sure it is running.

  if [ -f /var/run/says.pid]; then
     "do what you want with your script"

You can put logic inside where you can sleep after check for sshd if the pid is not there yet.

  • I thought about doing something like this, but it seemed hacky. I guess if there's no other way to do it I'll end up having to do it this way though. – Mediocre Gopher Aug 24 '13 at 15:48

Just add your script to the /etc/rc.d/rc.local. Your script will be executed after all the other init scripts.

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.