2013-04-07 13 views
5

Im usando Monit per monitorare uno script Ruby che utilizza Ruby daemons gem, che lancia un processo separato con PID - seguendo le istruzioni da Monitor ruby processes with Monitmonitoraggio di script Ruby, usando Monit - Compreso RVM

Al fine di eseguire lo script ruby ​​ho bisogno per includere RVM nelle stringhe Monit start e stop, così ho accesso a tutte le gemme.

Tuttavia quando .monitrc esegue ottengo il seguente errore:

$rvm_path (/usr/local/rvm) does not exist./home/william/.rvm/scripts/rvm: line 174: rvm_is_a_shell_function: command not found 
/home/william/.rvm/scripts/rvm: line 185: __rvm_teardown: command not found 
'myserver_1' failed to start 
Aborting event 

ho aggiunto PATH=$PATH:/home/william/.rvm/bin && . /home/william/.rvm/scripts/rvm alle stringhe di comando start e stop per cercare di includere RVM. Tuttavia ancora non funziona

file di configurazione .monitrc:

.... 

check process myserver_1 
    with pidfile /home/william/ruby/barclays/myapp.rb.pid 
    start = "/bin/bash -c 'PATH=$PATH:/home/william/.rvm/bin && . /home/william/.rvm/scripts/rvm && ruby /home/william/ruby/barclays/daemonloader.rb start'" 
    stop = "/bin/bash -c 'PATH=$PATH:/home/william/.rvm/bin && . /home/william/.rvm/scripts/rvm && ruby /home/william/ruby/barclays/daemonloader.rb stop'" 

    .... 

Grazie per il vostro aiuto.

EDIT

Ive ha ottenuto la sensazione che il problema è legato alle variabili di ambiente. Citando this page

You should also know that for security reasons Monit purges the environment and only sets a spartan PATH variable that contains /bin, /usr/bin, /sbin and /usr/sbin. If your program or script dies, the reason could be that it expects certain environment variables or to find certain programs via PATH. If this is the case you should set the environment variables you need directly in the start or stop script called by monit.

Finally, Monit uses the system call execv to execute a program or a script. This means that you cannot write shell commands directly in the start, stop or exec statements. To do this, you must do as above; start a shell and issue your commands there. For example:

start program = "/bin/bash -c 'my shell command && my other command'"

risposta

3

Utilizzare questa:

/path/to/rvm/bin/rvm in /path/to/project do ... 

sostituire i percorsi con directory appropriate per rvm e di progetto e la ... con i comandi per stop/start - provare:

/usr/bin/env "HOME=/home/william rvm_path=/home/william/.rvm 
    /home/william/.rvm/bin/rvm in /home/william/ruby/project do 
    ruby daemonloader.rb start" 

Questo comando carica RVM, cd nel percorso del progetto, carica ruby ​​per questo ruby ​​ed esegue il comando specificato.

+0

Ho provato questo: 'start =" /home/william/.rvm/bin/rvm in/home/william/ruby ​​/ project do ruby ​​daemonloader.rb start "'. Purtroppo ora ricevo il messaggio di errore "Impossibile trovare rvm install!" e fallisce. Cosa fa 'xxxx in yyy do zzz'? Potresti spiegare la risposta un po '? Grazie. – Imme22009

+0

stai eseguendo questo come 'william' utente? – mpapis

+0

Sì - Utente: william. – Imme22009

0

Si potrebbe provare qualcosa di simile in Monit.

start = "/bin/su - william -c 'cd /home/william/ruby/project && ~/.rvm/bin/rvm default do bundle exec ruby daemonloader.rb start'" 

Questo ha funzionato per me.

Problemi correlati