Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have severals RoR websites running on my webserver and I need to run a ruby script at startup.

So, I puted a bash script in /etc/init.d witch call a ruby process. Unfortunatly that ruby process needs some stuff that isn't loaded yet.

I tried to add a sleep 300 at the beginning of my bash script, but it doesn't really help because it also affect the startup of stuff like ssh, apache, etc...

Also, I don't want to load all the ruby libraries at startup, because it would slow down the boot time.

share|improve this question
up vote 6 down vote accepted

sleep 300 is the way to go, but you need to put it in a function which you will call asynchroneous:

    sleep 300

    # do what you want

myscript &

# continue with other things
share|improve this answer
Thanks man, exactly what i wanted – boby lapointe Aug 13 '12 at 8:44

Sleeping for five minutes is a pretty unstable hack. What if something later in the boot chain takes an unusal long time to start up? And why do you want your system to take longer than necessary to boot?

The right way to do it is to make your startup script run after the stuff it depends on. How you do this differs between distros.

In Debian you specify in the script header what dependencies your script have:. Here's an example from /etc/init.d/README in Debian Wheezy:

# Required-Start:    $remote_fs $syslog

On other systems you usually name the script with a number somewhere in the filename in one of the /etc/rc?.d/ folder. On such distros, just give it a higher number than the stuff it depends on.

share|improve this answer
Why would it be unstable, sleep even provides 5m syntax. I agree dependencies are the way to go, although boots that take more than five minutes should probably looked at and the RoR script failing is a good way to be brought to attention (but not the right way). – Tom Wijsman Aug 13 '12 at 8:47
It is unstable because usually delaying operations to fix a bug indicates a concurrency problem and adding a delay will work until your system gets slower/faster. – AsTeR Aug 12 '14 at 10:28

I wonder if you could start another thread and the first thing that thread does is sleep 300. Then it would call the script that you would have called from init.d

I think it would be something like

newscript &
share|improve this answer

create file: delay

# $1:delay time(s)
# $2:command
# example:
#    delay 10 "conky -d"

sleep $1
exec $2


chmod a+x delay
delay 10 "xxx"

put it in /etc/rc.local

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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