This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Monitoring running services and restart them if they stop working on Ubuntu.
#1
Monitoring running services and restart them if they stop working on Ubuntu.
To monitor running services and restart them if they stop working you can use Monit.

Here is the guide to install it:
https://www.digitalocean.com/community/t...gure-monit

But for a basic install run:

Code:
apt-get install monit

My setup:

Code:
nano /etc/monit/monitrc

And edit:

Code:
set httpd port 2812
    use address 12.34.56.789 or monit.YourDomain.com # only accept connection from localhost
    allow 0.0.0.0/0.0.0.0        # allow localhost to connect to the server and
    allow admin:*password*      # require user 'admin' with password 'monit'

And add this to the bottom of the file.

Code:
#Apache
Monitor
check process apache with pidfile /var/run/apache2/apache2.pid
    start program = "/etc/init.d/apache2 start" with timeout 60 seconds
    stop program  = "/etc/init.d/apache2 stop"
    if failed host YourDomain.com port 80 protocol http then restart

#MySQL
Monitor
check process mysqld with pidfile /var/run/mysqld/mysqld.pid
    start program = "/etc/init.d/mysql start"
    stop program = "/etc/init.d/mysql stop"
    if failed unixsocket /run/mysqld/mysqld.sock then restart

Code:
service monit restart

Here is an example of Monit restarting Apache when it went down 7hrs ago.

   
Reply
Thanks given by:
#2
RE: Monitoring running services and restart them if they stop working on Ubuntu.
I can not over state how well this has worked for me.
Reply
Thanks given by:


Possibly Related Threads…
Thread Author Replies Views Last Post
Upgrade to Ubuntu 16.04 from 14.04 HogensHero 8 30 ,370 07-18-2020, 03:13 AM
Last Post: dycott78
Ubuntu: How to Enable tls/ssl in proftpd Diablo925 2 12 ,850 04-21-2020, 03:35 AM
Last Post: iraqiboy90
Ubuntu 18.04 or 20.04 Kangarooo 1 6 ,955 03-20-2020, 11:39 AM
Last Post: Jettaman

Forum Jump:


Users browsing this thread: 1 Guest(s)