Monit

    Monit is free and open source software that helps you keep track of processes. It can restart services that are not responding or that have crashed. You can use Systemd or daemontools for the same purpose. In this article, we'll show you how to install and configure monit to control processes on Debian or Ubuntu Linux.

    Install

    for Centos 7-8

    To install, run the command on the server:

    yum install epel-release
    yum update
    yum install monit
    systemctl enable monit
    systemctl start monit
    for Debian-like system:

    To install, run the command on the server:

    sudo apt install monit

    Recommended configuration file /etc/monit/monitrc:

    set daemon 1
      with start delay 1
    
    set logfile /var/log/monit.log
    set idfile /var/lib/monit/id
    set statefile /var/lib/monit/state
    
    set httpd port 2812 and
      use address localhost
      allow localhost
    
    include /etc/monit/conf.d/*
    Configuration file for Astra service

    /etc/monit/conf.d/astra.conf

    check process astra with pidfile /var/run/astra.pid
        start program = "/etc/init.d/astra start"
        stop program = "/etc/init.d/astra stop"

    OR

    Configuration file for simple Astra process

    /etc/monit/conf.d/astra.conf

    check process astra.pid with pidfile /var/run/astra.pid
        start program = "/bin/sh -c 'ulimit -n 65536;  /usr/bin/astra -c /etc/astra/astra.conf -p 8000 --pid /var/run/astra.pid --log /var/log/astra.log --daemon'"
        stop program = "/bin/sh -c 'kill `cat /var/run/astra.pid`'"

    Restart monit to apply changes:

    systemctl restart monit

    or

    sudo /etc/init.d/monit restart

    Commands:

    monit reload — reload configuration files\
    monit summary — short information\
    monit start astra — start Astra\
    monit stop astra — stop Astra\
    monit restart astra — restart Astra