Till Brehm
2016-05-27 f8a07d139335a2c21a288546e6fb1922e4623127
Merge branch 'master' into 'stable-3.1'

add optional arrays for service-name to function system->getinitcommand and also…

… a parameter to check if the current service exists (mandatory if you use an array) Fixes #3910

See merge request !349
2 files modified
52 ■■■■■ changed files
server/lib/classes/system.inc.php 31 ●●●● patch | view | raw | blame | history
server/plugins-available/mail_plugin_dkim.inc.php 21 ●●●● patch | view | raw | blame | history
server/lib/classes/system.inc.php
@@ -1856,23 +1856,46 @@
    }
    function getinitcommand($servicename, $action, $init_script_directory = ''){
    function _getinitcommand($servicename, $action, $init_script_directory = '', $check_service) {
        global $conf;
        // upstart
        if(is_executable('/sbin/initctl')){
            exec('/sbin/initctl version 2>/dev/null | /bin/grep -q upstart', $retval['output'], $retval['retval']);
            if(intval($retval['retval']) == 0) return 'service '.$servicename.' '.$action;
        }
        // systemd
        if(is_executable('/bin/systemd') || is_executable('/usr/bin/systemctl')){
            return 'systemctl '.$action.' '.$servicename.'.service';
            if ($check_service) {
                exec("systemctl is-enabled ".$servicename." 2>&1", $out, $ret_val);
            }
            if ($ret_val == 0 || !$check_service) {
                return 'systemctl '.$action.' '.$servicename.'.service';
            }
        }
        // sysvinit
        if($init_script_directory == '') $init_script_directory = $conf['init_scripts'];
        if(substr($init_script_directory, -1) === '/') $init_script_directory = substr($init_script_directory, 0, -1);
        return $init_script_directory.'/'.$servicename.' '.$action;
        if($check_service && is_executable($init_script_directory.'/'.$servicename)) {
            return $init_script_directory.'/'.$servicename.' '.$action;
        }
        if (!$check_service) {
            return $init_script_directory.'/'.$servicename.' '.$action;
        }
    }
    function getinitcommand($servicename, $action, $init_script_directory = '', $check_service=false) {
        if (is_array($servicename)) {
            foreach($servicename as $service) {
                $out = $this->_getinitcommand($service, $action, $init_script_directory, true);
                if ($out != '') return $out;
            }
        } else {
            return $this->_getinitcommand($servicename, $action, $init_script_directory, $check_service);
        }
    }
    function getapacheversion($get_minor = false) {
        global $app;
        
server/plugins-available/mail_plugin_dkim.inc.php
@@ -171,22 +171,11 @@
     * This function restarts amavis
     */
    function restart_amavis() {
        global $app, $conf;
        $pos_init=array(
            $conf['init_scripts'].'/amavis',
            $conf['init_scripts'].'/amavisd'
        );
        $initfile='';
        foreach($pos_init as $init) {
            if (is_executable($init)) {
                $initfile=$init;
                break;
                }
        }
        if ( $initfile == '' ) $initfile = 'service amavis';
        $app->log('Restarting amavis: '.$initfile.'.', LOGLEVEL_DEBUG);
        exec(escapeshellarg($initfile).' restart', $output);
        foreach($output as $logline) $app->log($logline, LOGLEVEL_DEBUG);
        global $app;
        $initcommand = $app->system->getinitcommand(array('amavis', 'amavisd'), 'restart');
        $app->log('Restarting amavis: '.$initcommand.'.', LOGLEVEL_DEBUG);
        exec($initcommand, $output);
        foreach($output as $logline) $app->log($logline, LOGLEVEL_DEBUG);
    }
    /**