Skip to content

Commit f76fcc4

Browse files
committed
Improvement for web_module.inc.php as it may (re)start a non-running PHP FPM master.
The background of this MR is, that you may rollout multiple PHP versions to a server but not all should be started automatically. As long as not at least one valid conf is given, the process won't start. So you have the posibility to give your customers more PHP versions to select w/o having each PHP FPM master started, what may be a big memory consumption w/o any kind of advantage. Or better said, it may be a disadvantage on smaller VMs with just 1-2 GB RAM when there are already running 4-6 FPM masters which may consume up to 200MB w/o doing anything.
1 parent 7707cd3 commit f76fcc4

File tree

1 file changed

+43
-50
lines changed

1 file changed

+43
-50
lines changed

server/mods-available/web_module.inc.php

Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -248,60 +248,53 @@ function restartHttpd($action = 'restart') {
248248
return $retval;
249249
}
250250

251-
function restartPHP_FPM($action = 'restart') {
252-
global $app, $conf;
251+
function restartPHP_FPM($action = 'restart')
252+
{
253+
global $app, $conf;
253254

254-
// load the server configuration options
255-
$app->uses('getconf,system');
256-
$web_config = $app->getconf->get_server_config($conf['server_id'], 'web');
255+
// load the server configuration options
256+
$app->uses('getconf,system');
257+
$web_config = $app->getconf->get_server_config($conf['server_id'], 'web');
257258

258-
list($action, $init_script) = explode(':', $action);
259+
list($action, $init_script) = explode(':', $action);
259260

260-
if(!$init_script){
261-
//$init_script = $conf['init_scripts'].'/'.$web_config['php_fpm_init_script'];
262-
$initcommand = $app->system->getinitcommand($web_config['php_fpm_init_script'], $action);
263-
} else {
264-
$path_parts = pathinfo($init_script);
265-
$initcommand = $app->system->getinitcommand($path_parts['basename'], $action, $path_parts['dirname']);
266-
267-
if($action == 'reload' && $init_script == $conf['init_scripts'].'/'.$web_config['php_fpm_init_script']) {
268-
// we have to do a workaround because of buggy ubuntu fpm reload handling
269-
// @see: https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1242376
270-
if(file_exists('/etc/os-release')) {
271-
$tmp = file_get_contents('/etc/os-release');
272-
//if(preg_match('/^ID=ubuntu/m', $tmp) && preg_match('/^VERSION_ID="14\.04"/m', $tmp)) {
273-
if(preg_match('/^ID=ubuntu/m', $tmp) && preg_match('/^VERSION_ID="14\.04"/m', $tmp) && stristr(phpversion(), 'deb.sury.org') === false) {
274-
$initcommand = '/sbin/start-stop-daemon --stop --signal USR2 --quiet --pidfile /var/run/php5-fpm.pid --name php5-fpm';
275-
}
276-
// And the next workaround, php-fpm reloads in centos 7 downt work as well.
277-
/*
278-
if(preg_match('/^ID=centos/m', $tmp) && preg_match('/^VERSION_ID="7"/m', $tmp)) {
279-
$initcommand = 'systemctl restart php-fpm.service';
280-
}
281-
*/
282-
unset($tmp);
283-
}
284-
}
285-
/*
286-
if($action == 'reload') {
287-
// And the next workaround, php-fpm reloads in centos 7 downt work as well.
288-
if(file_exists('/etc/os-release')) {
289-
$tmp = file_get_contents('/etc/os-release');
290-
// And the next workaround, php-fpm reloads in centos 7 downt work as well.
291-
if(preg_match('/^ID="centos"/m', $tmp) && preg_match('/^VERSION_ID="7"/m', $tmp)) {
292-
$initcommand = 'systemctl restart php-fpm.service';
293-
}
294-
unset($tmp);
295-
}
296-
}
297-
*/
298-
}
261+
if (!$init_script) {
262+
$initcommand = $app->system->getinitcommand($web_config['php_fpm_init_script'], $action);
263+
} else {
264+
$path_parts = pathinfo($init_script);
299265

300-
$retval = array('output' => '', 'retval' => 0);
301-
exec($initcommand.' 2>&1', $retval['output'], $retval['retval']);
302-
$app->log("Restarting php-fpm: $initcommand", LOGLEVEL_DEBUG);
303-
return $retval;
304-
}
266+
if (is_executable('/bin/systemd') || is_executable('/usr/bin/systemctl')) {
267+
passthru('systemctl is-active ' . $init_script, $fpmstatus);
268+
269+
if ($fpmstatus !== "active") {
270+
$action = 'restart';
271+
$app->log('FPM Process ' . $init_script . ' seems to be not running', LOGLEVEL_DEBUG);
272+
} else {
273+
$app->log('FPM Process ' . $init_script . ' is running', LOGLEVEL_DEBUG);
274+
}
275+
}
276+
277+
$initcommand = $app->system->getinitcommand($path_parts['basename'], $action, $path_parts['dirname']);
278+
279+
if ($action == 'reload' && $init_script == $conf['init_scripts'] . '/' . $web_config['php_fpm_init_script']) {
280+
281+
if (file_exists('/etc/os-release')) {
282+
$tmp = file_get_contents('/etc/os-release');
283+
if (preg_match('/^ID=ubuntu/m', $tmp) && preg_match('/^VERSION_ID="14\.04"/m', $tmp) && stristr(phpversion(), 'deb.sury.org') === false) {
284+
$initcommand = '/sbin/start-stop-daemon --stop --signal USR2 --quiet --pidfile /var/run/php5-fpm.pid --name php5-fpm';
285+
}
286+
unset($tmp);
287+
}
288+
}
289+
}
290+
291+
292+
$retval = array('output' => '', 'retval' => 0);
293+
exec($initcommand . ' 2>&1', $retval['output'], $retval['retval']);
294+
$app->log("Restarting php-fpm: $initcommand", LOGLEVEL_DEBUG);
295+
296+
return $retval;
297+
}
305298

306299
} // end class
307300

0 commit comments

Comments
 (0)