Monit Bundle Exec Rails S

Monit bundle exec rails s

As i expected, it was user-environment issue and i solved it by editing monit configuration as below:

Before (not working)

check process myapp
matching ":4445"
start program = "/bin/bash -c '/home/user/start-app.sh'" as uid "user" and gid "user"
stop program = "/bin/bash -c /home/user/stop-app.sh" as uid "user" and gid "user"

After (working)

check process myapp
matching ":4445"
start program = "/bin/su -s /bin/bash -c '/home/user/start-app.sh' user"
stop program = "/bin/su -s /bin/bash -c '/home/user/stop-app.sh' user"

Explanation: i removed (uid and gid) as "user" from monit because it will only execute the shell script in the name of "user" but it won't get/import/use user's env path, or env variables.

How to exec a shell script from root monit (Mac)

Try running:

type bundle
type rails

to find what is actually being run when you use those commands. Then put the full paths you discover as a result into your script.

#!/bin/bash

cd "/Users/liren/ac-project/rails_app"
/full/path/to/bundle exec "sidekiq -C config/sidekiq.yml" &
/full/path/to/rails s -e production

Monit gives error after first run of exec command

Let's break apart what Monit is being asked to do:

if cpu usage < 30% for 5 cycles then exec "/bin/bash /var/www/stop.sh"

 warning : 'host_name' cpu usage of 0.5% matches resource limit [cpu usage < 30.0%]
warning : 'host_name' cpu usage of 1.6% matches resource limit [cpu usage < 30.0%]
warning : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
warning : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]

Your cpu usage is below 30%, so you get 4 warnings (but no action)

if cpu usage < 30% for 5 cycles then exec "/bin/bash /var/www/stop.sh"

error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
info : 'host_name' exec: '/bin/bash /var/www/stop.sh'

We've reached the 5th cycle, it's now considered an error and /var/www/stop.sh is run

error : 'host_name' cpu usage of 0.5% matches resource limit [cpu usage < 30.0%]
error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
error : 'host_name' cpu usage of 0.2% matches resource limit [cpu usage < 30.0%]
error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]

Since it has no further instructions, it just repeats the error (since it still exists).
If you want monit to run stop.sh again, you will need to tell it to (and how often) for example you could do

if cpu usage < 30% for 5 cycles then exec "/bin/bash /var/www/stop.sh"
repeat every 5 cycles



Related Topics



Leave a reply



Submit