Forum: Mongrel "service mongrel_cluster start" startup fails

Posted by Steve Meyer (stevejm)
on 2008-09-15 04:44
I've attempted to configure mongrel to start as a service in RHEL.
I've copied mongrel_cluster to /etc/init.d and
"#/etc/init.d/mongrel_cluster start" does work. However when I attempt
to start mongrel_cluster using "service mongrel_cluster start" I get the
following error:
 service mongrel_cluster start
/usr/bin/env: ruby: No such file or directory

I am somewhat new to ruby. But could sure use some help.


chkconfig --level 35 mongrel_cluster on
# chkconfig --list mongrel_cluster
mongrel_cluster 0:off   1:off   2:off   3:on    4:off   5:on    6:off
Posted by David Vrensk (Guest)
on 2008-09-15 14:13
(Received via mailing list)
On Mon, Sep 15, 2008 at 4:44 AM, Steve Meyer <lists@ruby-forum.com> 
wrote:

> I've attempted to configure mongrel to start as a service in RHEL.
> I've copied mongrel_cluster to /etc/init.d and
> "#/etc/init.d/mongrel_cluster start" does work. However when I attempt
> to start mongrel_cluster using "service mongrel_cluster start" I get the
> following error:
>  service mongrel_cluster start
> /usr/bin/env: ruby: No such file or directory


"service" gives a better picture of what will happen on boot since it 
sets
up the environment as it would be for the init process that runs all the
little start scripts.  In this case, it looks like ruby is not in the
default path.  Read the man-page for 'service' for a little more 
information
and try creating a simple script in /etc/init.d that just prints out the
environment variables, like this (untested):

---------------8<--------
#! /bin/sh
env
-------------8<---------

Make it executable and run it with "service name_of_script start" to see
what it prints.  It's not the solution to your problem, but it's a 
start.

/David
Posted by Steve Meyer (stevejm)
on 2008-12-13 04:27
David Vrensk wrote:
> On Mon, Sep 15, 2008 at 4:44 AM, Steve Meyer <lists@ruby-forum.com> 
> wrote:
> 
>> I've attempted to configure mongrel to start as a service in RHEL.
>> I've copied mongrel_cluster to /etc/init.d and
>> "#/etc/init.d/mongrel_cluster start" does work. However when I attempt
>> to start mongrel_cluster using "service mongrel_cluster start" I get the
>> following error:
>>  service mongrel_cluster start
>> /usr/bin/env: ruby: No such file or directory
> 
> 
> "service" gives a better picture of what will happen on boot since it 
> sets
> up the environment as it would be for the init process that runs all the
> little start scripts.  In this case, it looks like ruby is not in the
> default path.  Read the man-page for 'service' for a little more 
> information
> and try creating a simple script in /etc/init.d that just prints out the
> environment variables, like this (untested):
> 
> ---------------8<--------
> #! /bin/sh
> env
> -------------8<---------
> 
> Make it executable and run it with "service name_of_script start" to see
> what it prints.  It's not the solution to your problem, but it's a 
> start.
> 
> /David

I did get past this but now the "service mongrel_cluster" fails with the 
following; (i've added the env command to the script)
service mongrel_cluster start
TERM=xterm
PATH=/sbin:/usr/sbin:/bin:/usr/bin
PWD=/
LANG=en_US.UTF-8
SHLVL=1
_=/bin/env
/usr/bin/mongrel_cluster_ctl:9:in `require': no such file to load -- 
rubygems (LoadError)
        from /usr/bin/mongrel_cluster_ctl:9

While /init.d/mongrel_cluster start works and the env info is;
SHELL=/bin/bash
TERM=xterm
HISTSIZE=1000
USER=sfcapp
LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
MAIL=/var/spool/mail/root
PWD=/etc/init.d
INPUTRC=/etc/inputrc
LANG=en_US.UTF-8
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
HOME=/root
SHLVL=2
LOGNAME=root
CVS_RSH=ssh
SSH_CONNECTION=9.65.247.187 3708 9.54.168.71 22
LESSOPEN=|/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=1
_=/bin/env

I have tried adding /usr/local/bin to the path; didn't work
Posted by Steve Meyer (stevejm)
on 2008-12-13 04:30
Steve Meyer wrote:


If you have the mongrel_cluster working on a linux box; could you print
out the result of the env command as you have it?
Posted by David Vrensk (Guest)
on 2008-12-15 00:42
(Received via mailing list)
On Sat, Dec 13, 2008 at 04:30, Steve Meyer <lists@ruby-forum.com> wrote:

> Steve Meyer wrote:
>
>
> If you have the mongrel_cluster working on a linux box; could you print
> out the result of the env command as you have it?
>

[root@blade init.d]# service envtest start
TERM=xterm-color
PATH=/sbin:/usr/sbin:/bin:/usr/bin
PWD=/
LANG=en_US.UTF-8
SHLVL=1
_=/bin/env

and, not unimportantly:

[root@blade init.d]# which ruby
/usr/bin/ruby

/David
Posted by David Vrensk (Guest)
on 2008-12-15 00:48
(Received via mailing list)
On Sat, Dec 13, 2008 at 04:27, Steve Meyer <lists@ruby-forum.com> wrote:

> /usr/bin/mongrel_cluster_ctl:9:in `require': no such file to load --
> [...] I have tried adding /usr/local/bin to the path; didn't work
>

Let me be clear on this... did you add /usr/local/bin to the path in 
such a
way that 'service mongrel_cluster start' showed PATH=/usr/local/bin:..., 
but
the cluster did still not start?  Or do you mean that you didn't succeed 
in
adding /usr/local/bin to the path?  Or something else?

Seeing as three months have gone and we're now in a different era, you 
could
have a go at setting up apache with mod_rails instead.  The time might 
be
better spent there; I understand that mod_rails (Fusion passenger) is a 
nice
experience.

Good luck!

/David
Posted by Steve Meyer (stevejm)
on 2008-12-17 07:20
I did add /usr/local/bin to the path in the mongrel_cluster file and I 
still had issues; these were other ruby issues.
What I ended up doing was creating a custom file to do the start and 
stop. That worked and I did have to add /usr/local/bin to the path.

I've pasted in the file I created; I am sure there are issues with it. 
But it works...

Thanks for your help the path suggestion was key to my getting this to 
work.

#!/bin/sh
###########################################################################
# chkconfig: - 85 35
# description: Mongrel Rails appserver
# processname: mongrel_rails
# config: /home/sfcapp/sfc/current/config/mongrel_cluster.yml
#
export PATH=$PATH:/usr/local/bin
export SFCAPPHOME="/home/sfcapp/sfc"
export CURRENT_DIR="$SFCAPPHOME/current/config"
export MONGREL_RAILS="/usr/local/bin/mongrel_rails"
echo $SFCAPPHOME $CURRENT_DIR $MONGREL_RAILS


case "$1" in start)
 /usr/local/bin/mongrel_rails cluster::start -C 
/home/sfcapp/sfc/current/config/
mongrel_cluster.yml
;;
stop)
 /usr/local/bin/mongrel_rails cluster::stop -C 
/home/sfcapp/sfc/current/config/m
ongrel_cluster.yml
;;
restart)
 /usr/local/bin/mongrel_rails cluster::stop -C 
/home/sfcapp/sfc/current/config/mongrel_cluster.yml
 /usr/local/bin/mongrel_rails cluster::start -C 
/home/sfcapp/sfc/current/config/mongrel_cluster.yml
;;
*)
echo "usage start | stop | restart"
;;
esac
Posted by Chris Markle (cmarkle)
on 2009-01-11 04:52
All,

> /usr/bin/mongrel_cluster_ctl:9:in `require': no such file to load --
> [...] I have tried adding /usr/local/bin to the path; didn't work

A similar thing happened to me when I was testing a Ruby-based startup 
(/etc/init.d) script and was getting failures on my "load" command 
(similar symptoms to David's failure on "require".

I looked at the failure using strace and noticed that the final library 
lookup for say xxx.rb would be ./xxx.rb. This made me wonder what the 
current working directory was and it seems that scripts started with 
/sbin/service are started in the directory "/". So unless your loaded or 
required script is in "/" it will fail. Here is what the contents of var 
$: look like on my machine that seem to confirm this (this is the load 
order):

/usr/lib/ruby/site_ruby/1.8
/usr/lib/ruby/site_ruby/1.8/i386-linux
/usr/lib/ruby/site_ruby
/usr/lib/site_ruby/1.8
/usr/lib/site_ruby/1.8/i386-linux
/usr/lib/site_ruby
/usr/lib/ruby/1.8
/usr/lib/ruby/1.8/i386-linux
.

Notice that "." (current dir is the last one). I tried adding 
/etc/init.d (where my other scripts were for startup) using: 
$:.unshift("/etc/init.d") to dynamically change the search order and 
ended up with this, which worked:

/etc/init.d
/usr/lib/ruby/site_ruby/1.8
/usr/lib/ruby/site_ruby/1.8/i386-linux
/usr/lib/ruby/site_ruby
/usr/lib/site_ruby/1.8
/usr/lib/site_ruby/1.8/i386-linux
/usr/lib/site_ruby
/usr/lib/ruby/1.8
/usr/lib/ruby/1.8/i386-linux
.

Now I can keep the whole thing Ruby-based without having to change the 
/sbin/service code or resort to bash startup scripts to kick things 
off...

The section entitled "Where Ruby Finds Its Modules" in the Programming 
Ruby book (http://www.ruby-doc.org/docs/ProgrammingRuby/) was helpful to 
me in understanding this.

Hope this helps the next victim.
Posted by Christopher Zimmermann (topherzee)
on 2009-02-20 00:49
Hi all,

Im having the same problem as Steve Meyer was and still hope to find out 
what was wrong rather then writing a custom file as he ended up doing.
I very much appreciate any insight you can provide!

Same Problem:
My rails application runs great, but it needs to be started manually. I 
need it to restart when the machine restarts.

More explicitly,
If I manually run
> /etc/init.d/mongrel_cluster status
Then everything runs great.

But if i run
> service mongrel_cluster status
Then I get the error:
/usr/bin/mongrel_cluster_ctl:9:in `require': no such file to load -- 
rubygems (LoadError)

That line in mongrel_cluster_ctl is just:
require 'rubygems'

*****

What have I done to anger the gods??

Some details on my system - perhaps i installed something in wrong 
place?
ruby: /usr/bin/ruby
rubygems: /usr/local/rubygems

*****

I am new to linux - can someone help me with that line "require 
'rubygems'"..
What does 'require' mean in a shell script - i found no man page. What 
should it actually find, a file? I have the directory 
"/usr/local/rubygems" is that what it is looking for? Or should it find 
an actual file called 'rubygems' somewhere?

By the way, in the /etc/init.d/mongrel_cluster I did expand the path 
with:
export PATH=/usr/local:/usr/local/bin:$PATH

And that script then echos the path when run with service command as:
/usr/local:/usr/local/bin:/sbin:/usr/sbin:/usr/bin

*****

Thanks for reading!

Topher
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.