Best way to set monit apache [SOLVED]

Discussion in 'ISPConfig 3 Priority Support' started by SupuS, Feb 17, 2017.

  1. SupuS

    SupuS Member HowtoForge Supporter

    Hi,
    I use monit to monitor apache2 and it works fine. But sometimes, after change web settings, restart performed by ISPConfig is detected by monit and monit restart apache2 too. Than ISPConfig revert configuration change with error:
    Code:
    WARNING - Apache did not restart after the configuration change for website domain.ltd. Reverting the configuration. Saved non-working config as /etc/apache2/sites-available/domain.ltd.vhost.err
    
    WARNING - Reason for Apache restart failure: Restarting web server: apache2AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/sites-enabled/000-ispconfig.conf:69
    (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
    no listening sockets available, shutting down
    AH00015: Unable to open logs
    Action 'start' failed.
    The Apache error log may have more information.
    failed!
    What is the best way to prevent this colision?
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Maybe you can configure monit to not restart apache on first error cycle but wait for 2 or 3 cycles of "apache down" before a restart is performed.
     
  3. SupuS

    SupuS Member HowtoForge Supporter

    Hi Till,
    but it increase extend downtime in case of apache problems. I thinking about monitoring ispconfig lock file in /usr/local/ispconfig/server/temp. When exactly lock file appear and disappear from temp directory please?
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    Thi might be an option as well. The lock file get's set when the server job starts and removed when the server job finished.
     
  5. SupuS

    SupuS Member HowtoForge Supporter

    I am not able to monitor it by monit so I thinking about different way. Is it possible to run command before/after server job? For example:
    Code:
    /usr/bin/monit unmonitor apache
    [run server job]
    /usr/bin/monit monitor apache
    May be it could be new optional feature when monit is integrated into ISPConfig interface :)
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    Yes, you can do that with server plugins. Basically you need 2 small plugins, one that is in alphaber before the apache plugin (so it gets called before the original ispconfig apache plugin) and one that is behind the apache plugin in alphabet. These plugins need to have a small event function to stop / start monit.
    Example for the stop plugin:

    Code:
    <?php
    
    class aaa_apache2_plugin {
    
        var $plugin_name = 'aaa_apache2_plugin';
        var $class_name = 'aaa_apache2_plugin';
    
        //* This function is called during ispconfig installation to determine
        //  if a symlink shall be created for this plugin.
        function onInstall() {
            global $conf;
    
            if($conf['services']['web'] == true) {
                return true;
            } else {
                return false;
            }
    
        }
    
    
        /*
            This function is called when the plugin is loaded
        */
    
        function onLoad() {
            global $app;
    
            /*
            Register for the events
            */
            $app->plugins->registerEvent('web_domain_insert', $this->plugin_name, 'stopmonit');
            $app->plugins->registerEvent('web_domain_update', $this->plugin_name, 'stopmonit');
            $app->plugins->registerEvent('web_domain_delete', $this->plugin_name, 'stopmonit');
        }
       
        function stopmonit($event_name, $data) {
            exec('/usr/bin/monit unmonitor apache');
        }
    }
    
    Example for the start plugin:

    Code:
    <?php
    
    class xxx_apache2_plugin {
    
        var $plugin_name = 'xxx_apache2_plugin';
        var $class_name = 'xxx_apache2_plugin';
    
        //* This function is called during ispconfig installation to determine
        //  if a symlink shall be created for this plugin.
        function onInstall() {
            global $conf;
    
            if($conf['services']['web'] == true) {
                return true;
            } else {
                return false;
            }
    
        }
    
    
        /*
            This function is called when the plugin is loaded
        */
    
        function onLoad() {
            global $app;
    
            /*
            Register for the events
            */
            $app->plugins->registerEvent('web_domain_insert', $this->plugin_name, 'startmonit');
            $app->plugins->registerEvent('web_domain_update', $this->plugin_name, 'startmonit');
            $app->plugins->registerEvent('web_domain_delete', $this->plugin_name, 'startmonit');
        }
       
        function startmonit($event_name, $data) {
            exec('/usr/bin/monit monitor apache');
        }
    }
    
    Put the files in /usr/local/ispconfig/server/plugins-available/ and enable them with a symlink in /usr/local/ispconfig/server/plugins-enabled/

    Btw. I havent tested the code :)
     
  7. SupuS

    SupuS Member HowtoForge Supporter

    Hi Till,
    it is work as I expected. Thank you.
     

Share This Page