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 Answers4

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
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.

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 &
AeroJoe
  • 21
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