Commit 33bcd006 authored by Falko Timme's avatar Falko Timme

- Added support for systemd and upstart (besides sysvinit).

parent 2d2fd172
This diff is collapsed.
This diff is collapsed.
......@@ -1109,7 +1109,8 @@ class installer_base {
if(is_file('/etc/inetd.conf')) {
replaceLine('/etc/inetd.conf','/usr/sbin/pure-ftpd-wrapper','#ftp stream tcp nowait root /usr/sbin/tcpd /usr/sbin/pure-ftpd-wrapper',0,0);
if(is_file($conf['init_scripts'].'/'.'openbsd-inetd')) exec($conf['init_scripts'].'/'.'openbsd-inetd restart');
exec($inst->getinitcommand('openbsd-inetd', 'restart'));
//if(is_file($conf['init_scripts'].'/'.'openbsd-inetd')) exec($conf['init_scripts'].'/'.'openbsd-inetd restart');
}
if(!is_file('/etc/pure-ftpd/conf/DontResolve')) exec('echo "yes" > /etc/pure-ftpd/conf/DontResolve');
......@@ -2144,6 +2145,23 @@ class installer_base {
chmod($conf['ispconfig_log_dir'].'/cron.log', 0660);
}
public function getinitcommand($servicename, $action, $init_script_directory = ''){
global $conf;
// systemd
if(is_executable('/bin/systemd')){
return 'systemctl '.$action.' '.$servicename.'.service';
}
// 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;
}
// 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;
}
/**
* Helper function - get the path to a template file based on
......
This diff is collapsed.
......@@ -1597,6 +1597,23 @@ class system{
exec($cmd, $output, $return_var);
return $return_var == 0 ? true : false;
}
function getinitcommand($servicename, $action, $init_script_directory = ''){
global $conf;
// systemd
if(is_executable('/bin/systemd')){
return 'systemctl '.$action.' '.$servicename.'.service';
}
// 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;
}
// 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;
}
}
?>
......@@ -121,6 +121,8 @@ class dns_module {
function restartBind($action = 'restart') {
global $app,$conf;
$app->uses('system');
$daemon = '';
if(is_file($conf['init_scripts'] . '/' . 'bind9')) {
$daemon = 'bind9';
......@@ -130,9 +132,9 @@ class dns_module {
$retval = array('output' => '', 'retval' => 0);
if($action == 'restart') {
exec($conf['init_scripts'] . '/' . $daemon . ' restart 2>&1', $retval['output'], $retval['retval']);
exec($app->system->getinitcommand($daemon, 'restart').' 2>&1', $retval['output'], $retval['retval']);
} else {
exec($conf['init_scripts'] . '/' . $daemon . ' reload 2>&1', $retval['output'], $retval['retval']);
exec($app->system->getinitcommand($daemon, 'reload').' 2>&1', $retval['output'], $retval['retval']);
}
return $retval;
}
......@@ -140,6 +142,7 @@ class dns_module {
function restartPowerDNS($action = 'restart') {
global $app,$conf;
$app->uses('system');
$app->log("restartPDNS called.",LOGLEVEL_DEBUG);
/** Since PowerDNS does not currently allow to limit AXFR for specific zones to specific
......@@ -179,7 +182,7 @@ class dns_module {
}
$retval = array('output' => '', 'retval' => 0);
exec($conf['init_scripts'] . '/' . $daemon . ' restart 2>&1', $retval['output'], $retval['retval']);
exec($app->system->getinitcommand($daemon, 'restart').' 2>&1', $retval['output'], $retval['retval']);
// unset $tmps;
return $retval;
......
......@@ -363,6 +363,7 @@ class rescue_core_module {
private function _rescueDaemon($daemon){
global $conf;
$app->uses('system');
// if you need to find all restarts search for "['init_scripts']"
/*
* First we stop the running service "normally"
......@@ -374,7 +375,7 @@ class rescue_core_module {
* So we have to try to stop but if this will not work, we have to kill the stopping
* of the service
*/
exec($conf['init_scripts'] . '/' . $daemon . ' stop && (sleep 3; kill $!; sleep 2; kill -9 $!) &> /dev/null');
exec($app->system->getinitcommand($daemon, 'stop').' && (sleep 3; kill $!; sleep 2; kill -9 $!) &> /dev/null');
/*
* OK, we tryed to stop it normally, maybe this worked maybe not. So we have to look
......@@ -385,7 +386,7 @@ class rescue_core_module {
/*
* There are no more zombies left. Lets start the service..
*/
exec($conf['init_scripts'] . '/' . $daemon . ' start');
exec($app->system->getinitcommand($daemon, 'start'));
}
}
?>
......@@ -194,7 +194,7 @@ class web_module {
global $app,$conf;
// load the server configuration options
$app->uses('getconf');
$app->uses('getconf,system');
$web_config = $app->getconf->get_server_config($conf['server_id'], 'web');
$daemon = '';
......@@ -212,9 +212,10 @@ class web_module {
$retval = array('output' => '', 'retval' => 0);
if($action == 'restart') {
exec($conf['init_scripts'] . '/' . $daemon . ' restart 2>&1', $retval['output'], $retval['retval']);
exec($app->system->getinitcommand($daemon, 'restart').' 2>&1', $retval['output'], $retval['retval']);
} else {
exec($conf['init_scripts'] . '/' . $daemon . ' reload 2>&1', $retval['output'], $retval['retval']);
exec($app->system->getinitcommand($daemon, 'reload').' 2>&1', $retval['output'], $retval['retval']);
}
return $retval;
}
......@@ -223,15 +224,21 @@ class web_module {
global $app,$conf;
// load the server configuration options
$app->uses('getconf');
$app->uses('getconf,system');
$web_config = $app->getconf->get_server_config($conf['server_id'], 'web');
list($action, $init_script) = explode(':', $action);
if(!$init_script) $init_script = $conf['init_scripts'].'/'.$web_config['php_fpm_init_script'];
if(!$init_script){
//$init_script = $conf['init_scripts'].'/'.$web_config['php_fpm_init_script'];
$initcommand = $app->system->getinitcommand($web_config['php_fpm_init_script'], $action);
} else {
$path_parts = pathinfo($init_script);
$initcommand = $app->system->getinitcommand($path_parts['basename'], $action, $path_parts['dirname']);
}
$retval = array('output' => '', 'retval' => 0);
exec($init_script.' '.$action.' 2>&1', $retval['output'], $retval['retval']);
exec($initcommand.' 2>&1', $retval['output'], $retval['retval']);
return $retval;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment