Can't configure mongrel_cluster to start on boot

Hi everyone,

I’ve been working with Mongrel, Mongrel_cluster and Apache and it is
great.
However, I can’t get mongrel_cluster to start at boot time. I followed
the
instructions from http://mongrel.rubyforge.org/docs/mongrel_cluster.html
(On
Boot Initialization Setup) and mongrel_cluster does not start after
rebooting the machine.

I made sure that the shebang line is correct and I also made sure that
the
mongrel_cluster_ctl location is in the PATH variable. Just to be on the
safe
side I created a symbolic link in /usr/bin and still no luck.

The next thing I did was to trace the mongrel_cluster script. There is
something strange about it, and I can’t believe that nobody complained
about
it yet: the script takes an argument (start, stop or restart), but the
instructions provided on the mongrel_cluster webpage do not pass any
argument(s) to it. So, how is the script supposed to start? I’m not an
expert on Linux admin, but is the chkconfig application supposed to pass
“start” to the script? What about when the machine gets shut down, where
in
the script do we delete the mongrel pid files? (or worse, if it gets
powered
off, and if we restart without deleting the pid files, then the script
won’t
even start the mongrel processes).

Anyway, those are small things that can be easily changed in the script,
so
I hardcoded “start” in the script, and my script failed on the following
line:
which mongrel_cluster_ctl >/dev/null || exit 0
I commented out the line and provided the full path to
mongrel_cluster_ctl.
I dumped the $RETVAL into a log file (after calling mongrel_cluster_ctl)
and
it was 137.

I don’t know what else to do. I am logged in as admin, I successfully
used
chkconfig to add Apache to the boot script, and if I run the script
manually

  • it works!

Thanks,
Tiberiu

On 11/5/07, Tiberiu M. [email protected] wrote:

Hi everyone,

Hello Tiberiu,

I’m not sure if I can solve your problem, but I hope I can shed some
light
on what’s going on during boot time.

I’ve been working with Mongrel, Mongrel_cluster and Apache and it is
great.

However, I can’t get mongrel_cluster to start at boot time. I followed the
instructions from http://mongrel.rubyforge.org/docs/mongrel_cluster.html (On
Boot Initialization Setup) and mongrel_cluster does not start after
rebooting the machine.

I made sure that the shebang line is correct and I also made sure that the
mongrel_cluster_ctl location is in the PATH variable. Just to be on the safe
side I created a symbolic link in /usr/bin and still no luck.

When you installed the gem, you should have gotten mongrel_cluster_ctl
in
/usr/bin. If you didn’t, you will definately need a symlink, since PATH
is
very limited during boot (typically “/bin:/usr/bin:/sbin:/usr/sbin”).
What
version of mongrel and mongrel_cluster are you using (run ‘gem list
mongrel’)?

The next thing I did was to trace the mongrel_cluster script. There is

something strange about it, and I can’t believe that nobody complained about
it yet: the script takes an argument (start, stop or restart), but the
instructions provided on the mongrel_cluster webpage do not pass any
argument(s) to it. So, how is the script supposed to start?

The ‘mongrel_cluster’ script found in "
/path/to/mongrel_cluster_gem/resources/mongrel_cluster" that the
instructions tell you to copy to /etc/init.d is a normal init.d script.
It
can be run directly by you (as root):

/etc/init.d/mongrel_cluster stop

or through the ‘service’ helper (still as root or sudo)

$ sudo service mongrel_cluster start

When you ran ‘chkconfig --level 345 mongrel_cluster’, chkconfig created
symlinks in the directories /etc/rc0.d, /etc/rc1.d, up to /etc/rc6.d.
In
rc3.d, rc4.d and rc5.d there are symlinks named S85mongrel_cluster that
tell
the system (specifically the script ‘/etc/rc’) to run the script with
the
argument ‘start’ (S for start) and in rc0.d etc, there is
K15mongrel_cluster
which the system will take as a signal to run the script with ‘stop’ (K
for
kill). So there is the magic and the reason noone has complained about
the
script. It is good the way it is.

What about when the machine gets shut down, where in the script do we
delete

the mongrel pid files?

When the machine is shut down, mongrel_cluster will be run with ‘stop’,
and
mongrel_cluster_ctl will take care of the pid files.

(or worse, if it gets powered off, and if we restart without deleting
the

pid files, then the script won’t even start the mongrel processes).

That was a problem in and earlier release of mongrel_cluster (the gem,
not
the script). Now it actually peeks inside the pid files, and if it
can’t
find the processes listed there, it will remove the pid files and
proceed.

As I said, this will not solve your problem, but perhaps it tells you
where
you should start looking. I can recommend the man pages for ‘init’ and
‘inittab’ to better understand what’s going on. And everyone should
read
the source of /etc/rc at least once; it’s short and dispels a lot of
magic.

Good luck, and tell us about your findings!

/David

Hi David,

Thanks for all your help. It now makes sense how it all works.
Unfortunately
for me it doesn’t work and I don’t think it is because of
mongrel_cluster.

After you mentioned that I should have a symbolic link to
mongrel_cluster_ctl in /usr/bin, I realized that maybe the whole Ruby
environment is not available at boot time. I installed Ruby in a shared
location, but there are not symbolic links in /usr/bin to any of the
Ruby
utilities.

To test this, I created a small Ruby script which write “TEST” to a file
in
/tmp; I call this script from a bash script which I put in the
/etc/init.d
directory and which I configured using /sbin/chkconfig (similar to the
setup
of mongrel_cluster). Guess what?! No file is created in the /tmp
directory
at boot time.

So now my question becomes: what is the proper way of installing Ruby on
a
Linux machine? I did create a symbolic link to “ruby” in /usr/bin, but I
don’t think that’s enough. What other symbolic links do I need?

Thanks,
Tiberiu

On Nov 7, 2007 9:13 PM, Tiberiu M. [email protected] wrote:

Hi David,

Thanks for all your help. It now makes sense how it all works.

Hi Tiberiu, thanks, I’m glad to hear that!

Unfortunately for me it doesn’t work and I don’t think it is because
of mongrel_cluster.

After you mentioned that I should have a symbolic link to
mongrel_cluster_ctl in /usr/bin,

Oops, did I say that? I meant to say that the actual script
‘mongrel_cluster_ctl’ should reside in /usr/bin. But I have to admit
that
that was a simplification; the script should reside in the same
directory as
the ‘ruby’ binary.

I realized that maybe the whole Ruby environment is not available at
boot

time. I installed Ruby in a shared location, but there are not symbolic
links in /usr/bin to any of the Ruby utilities.

Well, there needn’t be. You can have you entire ruby installation in
/usr/local or /what/ever, as long as you put /usr/local/bin or
/what/ever/bin in your path. Where is that shared location? How do you
access it? The reason I ask is that mongrel_cluster normally starts
after
all network services have been started. A typical FC6 box would have
this
(and more) in /etc/rc3.d:

S10network (starts the network interface)
S25netfs (mounts remote shares)
S28autofs (starts the automounter)
S60nfs (starts nfs sharing)
S85mongrel_cluster

And since the scripts are run in this order, remote shares should be
available.

To test this, I created a small Ruby script which write “TEST” to a
file in

/tmp; I call this script from a bash script which I put in the /etc/init.d
directory and which I configured using /sbin/chkconfig (similar to the setup
of mongrel_cluster). Guess what?! No file is created in the /tmp directory
at boot time.

Just to check: if you put

echo TEST > /tmp/my_test_script_runs

in the bash script, does that work as expected? And second, do you call
the
ruby script as a command or a script, i.e., do you say

my_script

or

ruby my_script

And finally, what does the script look like?

So now my question becomes: what is the proper way of installing Ruby
on a

Linux machine? I did create a symbolic link to “ruby” in /usr/bin, but I
don’t think that’s enough. What other symbolic links do I need?

You don’t need any symbolic links as long as the bin directory is in
your
path. If you compile it on your own, it’s quite common to put it
/usr/local
since that is what ‘configure’ does by default.

The ‘proper’ way is a matter of taste. If you enjoy being an admin, go
ahead and install everything from source and put it in /usr/local. If
you
don’t, use your distro’s package manager (yum, dep, apt, rpm, what have
you)
and let it put things in /usr. Arguing about which is best borders on
philosophy.

I still don’t have a solution for you, but keep talking!

Good luck,

/David