8

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.

4 Answers 4

10

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

myscript()
{
    sleep 300

    # do what you want
}

myscript &

# continue with other things
0
6

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.

2
  • 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). Aug 13, 2012 at 8:47
  • 1
    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, 2014 at 10:28
0

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 &
0

create file: delay

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

sleep $1
exec $2

then

chmod a+x delay
delay 10 "xxx"

put it in /etc/rc.local

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .