virtualMachineruby

Configure and use Gonit

Apart from the control script that lets you control the services, every Bitnami stack includes Gonit as a component that allows you to monitor and control the services.

Start or stop services

Using the sudo gonit command followed by the action and the service name as argument, you can easily stop, start and restart services.

  • Use Gonit to restart a single service, such as Apache, by passing the service name as argument:

      $ sudo gonit restart apache
    
  • Use Gonit to stop a single service, such as MySQL:

      $ sudo gonit stop mysql
    
  • Use Gonit to start a single service, such as PHP-FPM:

      $ sudo gonit start php-fpm
    

To check which services are included in your stack, execute the sudo gonit status command as discussed in the next section.

Check service status with Gonit

With Gonit, system status can be viewed directly from the command line. It monitors processes, program files, directories and filesystems of each service/component included in your stack.

  • To check which services are included in your stack, the main files, processes, and status, run the sudo gonit status command. You should see output similar to this:

      $ sudo gonit status
      Uptime                         15m50s
      Last Check                     2018-06-25 13:30:49.591583338 +0000 UTC
      Next Check                     2018-06-25 13:32:49.591583338 +0000 UTC
      Pid                            4041
      Pid File                       /var/run/gonit.pid
      Socket File                    /var/run/gonit.sock
      Log File                       /var/log/gonit.log
      Process 'apache'
        status                                        Running
        pid                                              2000
        Uptime                                            17s
        monitoring status                           monitored
      Process 'mysql'
        status                                        Running
        pid                                              3558
        Uptime                                            17s
        monitoring status                           monitored
      Process 'php-fpm'
        status                                        Running
        pid                                              3737
        Uptime                                            17s
        monitoring status                           monitored
    
  • Use sudo gonit to check the Gonit status:

      $ sudo gonit
      daemon with PID 4041 awakened
    

Modify Gonit configuration

The main Gonit configuration file is located at /etc/gonit/gonitrc.

The configuration files for the servers monitored by Gonit are located in the /opt/bitnami/config/monit/conf.d/ and /etc/monit/conf.d directories.

Test Gonit

Gonit continuously monitors server status. When a service goes down, Gonit automatically initiates the recovery of the affected services.

To test Gonit, try to kill one of its monitored processes and check, after a few minutes, the status of the service as shown below. The following examples are executed on a WordPress instance deployed in the cloud:

  • Execute the sudo gonit status command to identify all the running processes, and note the pid of the server process you want to stop. This example uses Apache.

    Check servers status

  • Execute the sudo kill command to abruptly stop the selected process:

      $ sudo kill 2000
    
  • Execute the sudo gonit status command to check that Apache is stopped:

    Server stopped

  • After a few minutes, check Apache again. The status should have changed from Stopped to Running:

    Server restarted

Last modification December 21, 2022