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
Using Send_File to Download a File from Amazon S3
How to Update Ruby to 1.9.X on Mac
Difference Between Gemfile and Gemfile.Lock in Ruby on Rails
Ignoring Gem Because Its Extensions Are Not Built
How to Use Gem to Install Rails on Ubuntu
Rails Sends 0 Byte Files Using Send_File
Mavericks, Rbenv, Your Ruby Version Is 2.0.0, But Your Gemfile Specified 2.1.1
How to Match Something With Regex That Is Not Between Two Special Characters
Shortcut to Make Case/Switch Return a Value
How to Solve This Trouble to Deploy a Rails App to Heroku
Why Does White-Space Affect Ruby Function Calls
Flutter Pod Install Problem - Undefined Method 'Each_Child' For #≪Dir:0X00007Fa6F7E2Ec80≫
Looking For Suggestions For Building a Secure Rest API Within Ruby on Rails
Gem Eventmachine Fatal Error: 'Openssl/Ssl.H' File Not Found