Skip to content

Commit f8a07d1

Browse files
author
Till Brehm
committed
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 parents cb16d9a + ea476ac commit f8a07d1

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

server/lib/classes/system.inc.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,23 +1856,46 @@ function umount_backup_dir($backup_dir, $mount_cmd = '/usr/local/ispconfig/serve
18561856

18571857
}
18581858

1859-
function getinitcommand($servicename, $action, $init_script_directory = ''){
1859+
function _getinitcommand($servicename, $action, $init_script_directory = '', $check_service) {
18601860
global $conf;
18611861
// upstart
18621862
if(is_executable('/sbin/initctl')){
18631863
exec('/sbin/initctl version 2>/dev/null | /bin/grep -q upstart', $retval['output'], $retval['retval']);
18641864
if(intval($retval['retval']) == 0) return 'service '.$servicename.' '.$action;
18651865
}
1866+
18661867
// systemd
18671868
if(is_executable('/bin/systemd') || is_executable('/usr/bin/systemctl')){
1868-
return 'systemctl '.$action.' '.$servicename.'.service';
1869+
if ($check_service) {
1870+
exec("systemctl is-enabled ".$servicename." 2>&1", $out, $ret_val);
1871+
}
1872+
if ($ret_val == 0 || !$check_service) {
1873+
return 'systemctl '.$action.' '.$servicename.'.service';
1874+
}
18691875
}
1876+
18701877
// sysvinit
18711878
if($init_script_directory == '') $init_script_directory = $conf['init_scripts'];
18721879
if(substr($init_script_directory, -1) === '/') $init_script_directory = substr($init_script_directory, 0, -1);
1873-
return $init_script_directory.'/'.$servicename.' '.$action;
1880+
if($check_service && is_executable($init_script_directory.'/'.$servicename)) {
1881+
return $init_script_directory.'/'.$servicename.' '.$action;
1882+
}
1883+
if (!$check_service) {
1884+
return $init_script_directory.'/'.$servicename.' '.$action;
1885+
}
18741886
}
1875-
1887+
1888+
function getinitcommand($servicename, $action, $init_script_directory = '', $check_service=false) {
1889+
if (is_array($servicename)) {
1890+
foreach($servicename as $service) {
1891+
$out = $this->_getinitcommand($service, $action, $init_script_directory, true);
1892+
if ($out != '') return $out;
1893+
}
1894+
} else {
1895+
return $this->_getinitcommand($servicename, $action, $init_script_directory, $check_service);
1896+
}
1897+
}
1898+
18761899
function getapacheversion($get_minor = false) {
18771900
global $app;
18781901

server/plugins-available/mail_plugin_dkim.inc.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,11 @@ function check_system($data) {
171171
* This function restarts amavis
172172
*/
173173
function restart_amavis() {
174-
global $app, $conf;
175-
$pos_init=array(
176-
$conf['init_scripts'].'/amavis',
177-
$conf['init_scripts'].'/amavisd'
178-
);
179-
$initfile='';
180-
foreach($pos_init as $init) {
181-
if (is_executable($init)) {
182-
$initfile=$init;
183-
break;
184-
}
185-
}
186-
if ( $initfile == '' ) $initfile = 'service amavis';
187-
$app->log('Restarting amavis: '.$initfile.'.', LOGLEVEL_DEBUG);
188-
exec(escapeshellarg($initfile).' restart', $output);
189-
foreach($output as $logline) $app->log($logline, LOGLEVEL_DEBUG);
174+
global $app;
175+
$initcommand = $app->system->getinitcommand(array('amavis', 'amavisd'), 'restart');
176+
$app->log('Restarting amavis: '.$initcommand.'.', LOGLEVEL_DEBUG);
177+
exec($initcommand, $output);
178+
foreach($output as $logline) $app->log($logline, LOGLEVEL_DEBUG);
190179
}
191180

192181
/**

0 commit comments

Comments
 (0)