I have setup my Mac's launchd to run this monit script:
set daemon 60
set logfile /var/log/monit.log
check host ac_server with address 127.0.0.1
if failed port 3000
then exec "/bin/bash -c '/Users/liren/ac-project/monit_task.sh'"
Basically at 60s interval, it will ping my Ruby on Rails server and execute the monit_task.sh
script if server is down:
#!/bin/bash
cd "/Users/liren/ac-project/rails_app"
bundle exec "sidekiq -C config/sidekiq.yml" &
rails s -e production
monit script is located at /usr/local/etc/monit/monitrc
, executed by my LaunchDaemon plist located at /Library/LaunchDaemons/
.
However, the shell script just doesn't get executed without any errors showing in log. Any idea why?
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