Hello ! This is a continuation of our tutorial on how to deploy rails app to Ec2 with Capistrano. In the previous tutorial we were able to create the application, set up the development environment on Ec2 server (Ubuntu) and we successfully deployed the application, running the process (puma) in the background.
For this tutorial we will continue were we left off and add a monitoring tool called Monit. Monit is a small open source utility for managing and monitoring Unix systems.
In the previous tutorial, you may have stopped your puma server by trying kill -s SIGTERM (if you didn’t great!). Make sure your puma
server is running daemonized.
MONITORING WITH MONIT
In your Ec2 instance/server:
sudo apt-get install monit
sudo monit
To configure monit Interface:
sudo nano /etc/monit/monitrc
The file should open. Scroll down to the part the looks like the text below and edit like you see:
# set httpd port 2812 and # use address localhost # only accept connection from localhost # allow localhost # allow localhost to connect to the server and # allow admin:monit # require user ‘admin’ with password ‘monit’ You should get something like that. change it to look like set httpd port 2812 and use address 54.148.62.73 # use IP address or DNS name(Ec2 Public IP for us) allow 0.0.0.0/0.0.0.0 # allow localhost to connect to the server and allow admin:monit # require user ‘admin’ with password ‘monit’ |
Note => everytime you edit monitrc, run:sudo monit reload And then visit the website or with Ec2 instance, use the public IPv4 DNS name or IP address at port 2812.http://54.148.62.73:2812Remember to edit your Security Group and add a new http rule with port 2812 open. |
If you get this error when you run monit reload :
/etc/monit/monitrc:289: Include failed — Success ‘/etc/monit/conf.d/*’
/etc/monit/monitrc:290: Include failed — Success ‘/etc/monit/conf-enabled/*’
Go back to the monitrc
sudo nano monitrc
and comment out
include /etc/monit/conf.d/*
include /etc/monit/conf-enabled/*
(this will likely be at the bottom of the file.)
TO MONITOR NGINX
check process nginx with:
pidfile /var/run/nginx.pid
start program = “/etc/init.d/nginx start”
stop program = “/etc/init.d/nginx stop”
MONITORING POSTGRES
Your postgres version may be different, to check postgresql version :
cd /var/run/postgresql
Now we know our Postgres version
check process postgres with:
pidfile /var/run/postgresql/9.5-main.pid
start program = “/etc/init.d/postgresql start”
stop program = “/etc/init.d/postgresql stop”
You can also run sudo monit status to see the process on the terminal.
Hope this was/is helpful.