Forum: Ruby on Rails monit newbie problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
11a08b97f4904999b2398a0c265b38e4?d=identicon&s=25 Frioffol Friofool (friofool)
on 2008-10-07 14:31
Hi,

I tried to make monit up on my server to manage ruby on rails
application.
I have some problem when i try to start monit :

[root@seb seb]# /usr/local/bin/monit start all
'mongrel_rails_3003' start: /usr/bin/ruby
'mongrel_rails_3003' failed to start

[root@seb seb]# monit status
monit: no status available -- the monit daemon is not running

my monitrc file is in /usr/local/src/monitrc :

---------
set daemon 30
set logfile /var/log/monit.log
set mailserver 127.0.0.1
set mail-format {from:watchseb@mydomain.com}
set alert friofool@mydomain.com only on {timeout, nonexist}
set httpd port 4000
include /home/seb/watchdog/*
---------

my application config file in /home/seb/watchdog/ :

---------
check process mongrel_rails_3003
        with pidfile /var/run/mongrel/mongrel.3003.pid
        start program = "/usr/bin/ruby /usr/bin/mongrel_rails
cluster::start -C
/home/seb/railsproject/cpericard/config/mongrel_cluster.yml --clean
--only 3003"
        stop program = "/usr/bin/ruby /usr/bin/mongrel_rails
cluster::stop -C
/home/seb/railsproject/cpericard/config/mongrel_cluster.yml --only 3003"
if totalmem > 100.0 MB for 5 cycles then restart
if failed host 127.0.0.1 port 3003 protocol http with timeout 10 seconds
then restart
---------

The mongrel process start but monit daemon is not running.

What's wrong with my configuration ?

Thanks a lot for your help !
9b4c04c050122bcea16a6f3376d680fa?d=identicon&s=25 Daniel Bush (danb)
on 2008-10-07 15:36
Frioffol Friofool wrote:
> Hi,
>
> I tried to make monit up on my server to manage ruby on rails
> application.
> I have some problem when i try to start monit :
>

Hi,
What do you get when you run:
# /usr/local/bin/monit -t -c /usr/local/src/monitrc

Daniel
11a08b97f4904999b2398a0c265b38e4?d=identicon&s=25 Frioffol Friofool (friofool)
on 2008-10-07 16:00
Daniel Bush wrote:
> Frioffol Friofool wrote:
>> Hi,
>>
>> I tried to make monit up on my server to manage ruby on rails
>> application.
>> I have some problem when i try to start monit :
>>
>
> Hi,
> What do you get when you run:
> # /usr/local/bin/monit -t -c /usr/local/src/monitrc
>
> Daniel

[root@seb cpericard]# /usr/local/bin/monit -t -c /usr/local/etc/monitrc
Control file syntax OK
D893e113b51a8f200d2abb3ed9e54143?d=identicon&s=25 Gaspard Bucher (gazoduc)
on 2008-10-07 16:01
(Received via mailing list)
I'm not sure you need to include the '/usr/bin/ruby' in your start
program. The following setup works for me:

check process mongrel-8007 with pidfile /var/zena/current/log/mongrel.
8007.pid
   start program = "/var/lib/gems/1.8/bin/mongrel_rails start -d -e
production -p 8007 -a 127.0.0.1 -P log/mongrel.8007.pid -c /var/zena/
current" --user www-data --group www-data
   stop program = "/var/lib/gems/1.8/bin/mongrel_rails stop -P log/
mongrel.8007.pid -c /var/zena/current"


Gaspard
4c438a80fc30661ad619ea177cf9cbd0?d=identicon&s=25 Freddy Andersen (Guest)
on 2008-10-07 16:23
(Received via mailing list)
Monit does NOT get the normal path information that a regular user on
the server would get so you have to be VERY specific in you
configuration files. Some times the best solution is to create a
startup script that you call from monit...

script:
#!/bin/bash
# Get the port number
PORT=$2
# Set the initial path
export PATH=${PATH}:/usr/bin:/usr/local/bin
start () {  mongrel_rails cluster::start --config $CONFIG_FILE --clean
--only $PORT }
stop () {  mongrel_rails cluster::stop --config $CONFIG_FILE --clean --
only $PORT --force }
case $1 in
  start)
    start
  ;;
  stop)
    stop
  ;;
  *)
  echo $"Usage: $0 {start|stop} port"
  exit 1
  ;;
esac
exit 0

Now you can call it from monit like this:

  start program = "/usr/local/bin/script.sh start 8000"
  stop program = "/usr/local/bin/script.sh stop 8000"
11a08b97f4904999b2398a0c265b38e4?d=identicon&s=25 Frioffol Friofool (friofool)
on 2008-10-07 16:33
Gaspard Bucher wrote:
> I'm not sure you need to include the '/usr/bin/ruby' in your start
> program. The following setup works for me:
>
> check process mongrel-8007 with pidfile /var/zena/current/log/mongrel.
> 8007.pid
>    start program = "/var/lib/gems/1.8/bin/mongrel_rails start -d -e
> production -p 8007 -a 127.0.0.1 -P log/mongrel.8007.pid -c /var/zena/
> current" --user www-data --group www-data
>    stop program = "/var/lib/gems/1.8/bin/mongrel_rails stop -P log/
> mongrel.8007.pid -c /var/zena/current"
>
>
> Gaspard

i have updated my monitrc file :

-------
set daemon 60

set httpd port 2812 and
    use address 127.0.0.1
    allow 127.0.0.1

check process mongrel-3003 with pidfile
/home/seb/railsproject/cpericard/log/mongrel.3003.pid
  start program = "/usr/bin/mongrel_rails start -d -e development -p
3003 -a 127.0.0.1 -P
/home/seb/railsproject/cpericard/log/mongrel.3003.pid -c
/home/seb/railsproject/cpericard"
  stop program = "/usr/bin/mongrel_rails stop -P
/home/seb/railsproject/cpericard/log/mongrel.3003.pid -c
/home/seb/railspoject/cpericard"
group mongrel
-------

when i try to start monit :

[root@seb cpericard]# /usr/local/bin/monit start all
'mongrel-3003' start: /usr/bin/mongrel_rails
'mongrel-3003' failed to start

monit daemon is not starting but mongrel is working !
D893e113b51a8f200d2abb3ed9e54143?d=identicon&s=25 Gaspard Bucher (gazoduc)
on 2008-10-07 16:55
(Received via mailing list)
Try running your start program without any environment variables (as
it is probably run by monit):

# env -i /usr/bin/mongrel_rails start -d -e development -p 3003 -a
127.0.0.1 -P /home/seb/railsproject/cpericard/log/mongrel.3003.pid -c /
home/seb/railsproject/cpericard

Make sure "which mongrel_rails" gives
/usr/bin/mongrel_rails

I had to use (debian)
/var/lib/gems/1.8/bin/mongrel_rails

Gaspard
11a08b97f4904999b2398a0c265b38e4?d=identicon&s=25 Frioffol Friofool (friofool)
on 2008-10-07 17:17
Gaspard Bucher wrote:
> Try running your start program without any environment variables (as
> it is probably run by monit):
>
> # env -i /usr/bin/mongrel_rails start -d -e development -p 3003 -a
> 127.0.0.1 -P /home/seb/railsproject/cpericard/log/mongrel.3003.pid -c /
> home/seb/railsproject/cpericard
>
> Make sure "which mongrel_rails" gives
> /usr/bin/mongrel_rails
>
> I had to use (debian)
> /var/lib/gems/1.8/bin/mongrel_rails
>
> Gaspard

that's better, monit is starting but ... not my rails app

my monitrc file :

-----
set daemon 60

set httpd port 2812 and
    use address 127.0.0.1
    allow 127.0.0.1

check process mongrel-3003 with pidfile
/home/seb/railsproject/cpericard/log/mongrel.3003.pid
  start program = "/bin/env -i /usr/bin/mongrel_rails start -d -e
development -p 3003 -a 127.0.0.1 -P
/home/seb/railsproject/cpericard/log/mongrel.3003.pid -c
/home/seb/railsproject/cpericard"
  stop program = "/bin/env -i /usr/bin/mongrel_rails stop -P
/home/seb/railsproject/cpericard/log/mongrel.3003.pid -c
/home/seb/railsproject/cpericard"
group mongrel
----

[root@seb cpericard]# which mongrel_rails
/usr/bin/mongrel_rails
[root@seb cpericard]# /usr/local/bin/monit
Starting monit daemon with http interface at [127.0.0.1:2812]
[root@seb cpericard]# monit status
The monit daemon 4.10.1 uptime: 0m

Process 'mongrel-3003'
  status                            Execution failed
  monitoring status                 monitored
  data collected                    Tue Oct  7 17:16:52 2008

System 'seb'
  status                            Monit instance changed
  monitoring status                 monitored
  load average                      [0.04] [0.07] [0.08]
  cpu                               0.0%us 0.0%sy 0.0%wa
  memory usage                      399392 kB [77.6%]
  data collected                    Tue Oct  7 17:16:52 2008
D893e113b51a8f200d2abb3ed9e54143?d=identicon&s=25 Gaspard Bucher (gazoduc)
on 2008-10-07 17:34
(Received via mailing list)
You misunderstood me. Try running your command * in the shell *
to test it first. You also get any error messages. So you should type:

# env -i /usr/bin/mongrel_rails start -d -e development -p 3003 -a
127.0.0.1 -P /home/seb/railsproject/cpericard/log/mongrel.3003.pid -c /
home/seb/railsproject/cpericard

and see how it works.

Setting "env -i" in the shell reproduces the environment used in
monit, so it lets you test your command as if it was run by monit.

Gaspard
11a08b97f4904999b2398a0c265b38e4?d=identicon&s=25 Frioffol Friofool (friofool)
on 2008-10-07 18:12
Gaspard Bucher wrote:
> You misunderstood me. Try running your command * in the shell *
> to test it first. You also get any error messages. So you should type:
>
> # env -i /usr/bin/mongrel_rails start -d -e development -p 3003 -a
> 127.0.0.1 -P /home/seb/railsproject/cpericard/log/mongrel.3003.pid -c /
> home/seb/railsproject/cpericard
>
> and see how it works.
>
> Setting "env -i" in the shell reproduces the environment used in
> monit, so it lets you test your command as if it was run by monit.
>
> Gaspard

sorry ! and thanks for your help gaspard

i tried this command and mongrel is starting.
11a08b97f4904999b2398a0c265b38e4?d=identicon&s=25 Frioffol Friofool (friofool)
on 2008-10-07 18:32
Frioffol Friofool wrote:
> Gaspard Bucher wrote:
>> You misunderstood me. Try running your command * in the shell *
>> to test it first. You also get any error messages. So you should type:
>>
>> # env -i /usr/bin/mongrel_rails start -d -e development -p 3003 -a
>> 127.0.0.1 -P /home/seb/railsproject/cpericard/log/mongrel.3003.pid -c /
>> home/seb/railsproject/cpericard
>>
>> and see how it works.
>>
>> Setting "env -i" in the shell reproduces the environment used in
>> monit, so it lets you test your command as if it was run by monit.
>>
>> Gaspard
>
> sorry ! and thanks for your help gaspard
>
> i tried this command and mongrel is starting.

now it's working !

i didn't change anything.

my definitive conf file is :

set daemon 60

set httpd port 2812 and
    use address 127.0.0.1
    allow 127.0.0.1

check process mongrel-3003 with pidfile
/home/seb/railsproject/cpericard/log/mongrel.3003.pid
  start program = "/usr/bin/mongrel_rails start -d -e development -p
3003 -a 127.0.0.1 -P
/home/seb/railsproject/cpericard/log/mongrel.3003.pid -c
/home/seb/railsproject/cpericard"
  stop program = "/usr/bin/mongrel_rails stop -P
/home/seb/railsproject/cpericard/log/mongrel.3003.pid -c
/home/seb/railsproject/cpericard"
group mongrel

thanks for all your help !
This topic is locked and can not be replied to.