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?
Asked
Active
Viewed 4,205 times
2
-
1What 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 http://www.centos.org/docs/5/html/Installation_Guide-en-US/s1-boot-init-shutdown-sysv.html – jpe Aug 24 '13 at 15:49
3 Answers
4
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.
Mediocre Gopher
- 803
- 1
- 12
- 24
-
`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 08 '18 at 18:33
0
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"
fi
You can put logic inside where you can sleep after check for sshd if the pid is not there yet.
Danila Ladner
- 5,241
- 21
- 30
-
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
0
Just add your script to the /etc/rc.d/rc.local. Your script will be executed after all the other init scripts.
ALex_hha
- 7,025
- 1
- 23
- 39