From 7d6d683e5212e0df430d412cdad5876d62f254d2 Mon Sep 17 00:00:00 2001 From: "Florian Aders (EleRas)" Date: Mon, 27 Feb 2012 19:27:13 +0100 Subject: [PATCH] Added Fast CGI Idle Timeout, patch by Slydder, fixes #1017 Signed-off-by: Florian Aders (EleRas) --- actions/admin/settings/135.fcgid.php | 8 ++++++ actions/admin/settings/136.phpfpm.php | 8 ++++++ install/froxlor.sql | 5 ++-- .../updates/froxlor/0.9/update_0.9.inc.php | 26 ++++++++++++++++++- lib/tables.inc.php | 2 +- lng/english.lng.php | 4 +++ lng/german.lng.php | 4 +++ .../jobs/cron_tasks.inc.http.10.apache.php | 25 +++++++++++++++++- .../cron_tasks.inc.http.15.apache_fcgid.php | 3 ++- 9 files changed, 79 insertions(+), 6 deletions(-) diff --git a/actions/admin/settings/135.fcgid.php b/actions/admin/settings/135.fcgid.php index 80cad481..97a62d76 100644 --- a/actions/admin/settings/135.fcgid.php +++ b/actions/admin/settings/135.fcgid.php @@ -135,6 +135,14 @@ return array( 'save_method' => 'storeSettingField', 'websrv_avail' => array('apache2') ), + 'system_mod_fcgid_idle_timeout' => array( + 'label' => $lng['serversettings']['mod_fcgid']['idle_timeout'], + 'settinggroup' => 'system', + 'varname' => 'mod_fcgid_idle_timeout', + 'type' => 'int', + 'default' => 30, + 'save_method' => 'storeSettingField' + ), ) ) ) diff --git a/actions/admin/settings/136.phpfpm.php b/actions/admin/settings/136.phpfpm.php index d7ce5c8b..d959679f 100644 --- a/actions/admin/settings/136.phpfpm.php +++ b/actions/admin/settings/136.phpfpm.php @@ -153,6 +153,14 @@ return array( 'default' => 0, 'save_method' => 'storeSettingField', ), + 'system_phpfpm_idle_timeout' => array( + 'label' => $lng['serversettings']['phpfpm_settings']['idle_timeout'], + 'settinggroup' => 'phpfpm', + 'varname' => 'idle_timeout', + 'type' => 'int', + 'default' => 30, + 'save_method' => 'storeSettingField' + ), ), ), ), diff --git a/install/froxlor.sql b/install/froxlor.sql index 511c5cd4..3e835963 100644 --- a/install/froxlor.sql +++ b/install/froxlor.sql @@ -469,7 +469,7 @@ INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('syste INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'bind_enable', '1'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'bindconf_directory', '/etc/bind/'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'bindreload_command', '/etc/init.d/bind9 reload'); -INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('panel', 'version', '0.9.27-svn1'); +INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('panel', 'version', '0.9.27-svn2'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'hostname', 'SERVERNAME'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('login', 'maxloginattempts', '3'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('login', 'deactivatetime', '900'); @@ -617,6 +617,7 @@ INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('phpfp INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('phpfpm', 'enabled_ownvhost', '0'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('phpfpm', 'vhost_httpuser', 'froxlorlocal'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('phpfpm', 'vhost_httpgroup', 'froxlorlocal'); +INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('phpfpm', 'idle_timeout', '30'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'report_enable', '1'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'report_webmax', '90'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'report_trafficmax', '90'); @@ -640,7 +641,7 @@ INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('syste INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'logrotate_binary', '/usr/sbin/logrotate'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'logrotate_interval', 'weekly'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'logrotate_keep', '4'); - +INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'mod_fcgid_idle_timeout', '30'); # -------------------------------------------------------- # diff --git a/install/updates/froxlor/0.9/update_0.9.inc.php b/install/updates/froxlor/0.9/update_0.9.inc.php index 48d21739..939b3d33 100644 --- a/install/updates/froxlor/0.9/update_0.9.inc.php +++ b/install/updates/froxlor/0.9/update_0.9.inc.php @@ -1779,4 +1779,28 @@ if(isFroxlorVersion('0.9.26')) } updateToVersion('0.9.27-svn1'); -} \ No newline at end of file +} + +if(isFroxlorVersion('0.9.27-svn1')) +{ + showUpdateStep("Updating from 0.9.27-svn1 to 0.9.27-svn2"); + lastStepStatus(0); + + // Get FastCGI timeout setting if available + $handle = $db->query("SELECT `value` FROM `panel_settings` WHERE `settinggroup` = 'system' AND `varname` = 'mod_fcgid_idle_timeout';"); + + // If timeout is set then skip + if ($db->num_rows($handle) < 1) { + $db->query("INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'mod_fcgid_idle_timeout', '30');"); + } + + // Get FastCGI timeout setting if available + $handle = $db->query("SELECT `value` FROM `panel_settings` WHERE `settinggroup` = 'phpfpm' AND `varname` = 'idle_timeout';"); + + // If timeout is set then skip + if ($db->num_rows($handle) < 1) { + $db->query("INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('phpfpm', 'idle_timeout', '30');"); + } + + updateToVersion('0.9.27-svn2'); +} diff --git a/lib/tables.inc.php b/lib/tables.inc.php index 19a6d1f0..2656fa52 100644 --- a/lib/tables.inc.php +++ b/lib/tables.inc.php @@ -73,6 +73,6 @@ define('PACKAGE_ENABLED', 2); // VERSION INFO -$version = '0.9.27-svn1'; +$version = '0.9.27-svn2'; $dbversion = '2'; $branding = ''; diff --git a/lng/english.lng.php b/lng/english.lng.php index 08bff569..99ca4745 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -1904,3 +1904,7 @@ $lng['error']['invalidhostname'] = 'Hostname can\'t be empty nor can it consist $lng['traffic']['http'] = 'HTTP (MB)'; $lng['traffic']['ftp'] = 'FTP (MB)'; $lng['traffic']['mail'] = 'Mail (MB)'; +$lng['serversettings']['mod_fcgid']['idle_timeout']['title'] = 'Idle Timeout'; +$lng['serversettings']['mod_fcgid']['idle_timeout']['description'] = 'Timeout setting for Mod FastCGI.'; +$lng['serversettings']['phpfpm_settings']['idle_timeout']['title'] = 'Idle Timeout'; +$lng['serversettings']['phpfpm_settings']['idle_timeout']['description'] = 'Timeout setting for PHP5 FPM FastCGI.'; \ No newline at end of file diff --git a/lng/german.lng.php b/lng/german.lng.php index a922351b..f8843f11 100644 --- a/lng/german.lng.php +++ b/lng/german.lng.php @@ -1635,3 +1635,7 @@ $lng['error']['invalidhostname'] = 'Hostname darf nicht leer sein oder nur aus L $lng['traffic']['http'] = 'HTTP (MB)'; $lng['traffic']['ftp'] = 'FTP (MB)'; $lng['traffic']['mail'] = 'Mail (MB)'; +$lng['serversettings']['mod_fcgid']['idle_timeout']['title'] = 'Idle Timeout'; +$lng['serversettings']['mod_fcgid']['idle_timeout']['description'] = 'Timeout einstellung für Mod FastCGI.'; +$lng['serversettings']['phpfpm_settings']['idle_timeout']['title'] = 'Idle Timeout'; +$lng['serversettings']['phpfpm_settings']['idle_timeout']['description'] = 'Timeout einstellung für PHP5 FPM FastCGI.'; diff --git a/scripts/jobs/cron_tasks.inc.http.10.apache.php b/scripts/jobs/cron_tasks.inc.http.10.apache.php index 6223e151..c96f0ee3 100644 --- a/scripts/jobs/cron_tasks.inc.http.10.apache.php +++ b/scripts/jobs/cron_tasks.inc.http.10.apache.php @@ -236,6 +236,7 @@ class apache { $configdir = makeCorrectDir($this->settings['system']['mod_fcgid_configdir'] . '/froxlor.panel/' . $this->settings['system']['hostname']); + $this->virtualhosts_data[$vhosts_filename].= ' FastCgiConfig -idle-timeout ' . $this->settings['system']['mod_fcgid_idle_timeout'] . "\n"; if((int)$this->settings['system']['mod_fcgid_wrapper'] == 0) { $this->virtualhosts_data[$vhosts_filename].= ' SuexecUserGroup "' . $this->settings['system']['mod_fcgid_httpuser'] . '" "' . $this->settings['system']['mod_fcgid_httpgroup'] . '"' . "\n"; @@ -273,7 +274,7 @@ class apache $php = new phpinterface($this->getDB(), $this->settings, $domain); $this->virtualhosts_data[$vhosts_filename].= ' SuexecUserGroup "' . $this->settings['system']['mod_fcgid_httpuser'] . '" "' . $this->settings['system']['mod_fcgid_httpgroup'] . '"' . "\n"; - $this->virtualhosts_data[$vhosts_filename].= ' FastCgiExternalServer ' . $mypath . 'fpm.external -socket ' . $php->getInterface()->getSocketFile() . ' -user ' . $this->settings['system']['mod_fcgid_httpuser'] . ' -group ' . $this->settings['system']['mod_fcgid_httpuser'] . "\n"; + $this->virtualhosts_data[$vhosts_filename].= ' FastCgiExternalServer ' . $mypath . 'fpm.external -socket ' . $php->getInterface()->getSocketFile() . ' -user ' . $this->settings['system']['mod_fcgid_httpuser'] . ' -group ' . $this->settings['system']['mod_fcgid_httpuser'] . " -idle-timeout " . $this->settings['phpfpm']['idle_timeout'] . "\n"; $this->virtualhosts_data[$vhosts_filename].= ' ' . "\n"; $this->virtualhosts_data[$vhosts_filename].= ' AddHandler php5-fastcgi .php'. "\n"; $this->virtualhosts_data[$vhosts_filename].= ' Action php5-fastcgi /fastcgiphp' . "\n"; @@ -1295,6 +1296,28 @@ class apache } } } + if($this->settings['phpfpm']['enabled'] == '1') + { + foreach($this->known_vhostfilenames as $vhostfilename){ + $known_phpfpm_files[]=preg_replace('/^(05|10|20|21|22|30|50|51)_(froxlor|syscp)_(dirfix|ipandport|normal_vhost|wildcard_vhost|ssl_vhost)_/', '', $vhostfilename); + } + + $configdir = $this->settings['phpfpm']['configdir']; + $phpfpm_file_dirhandle = opendir($this->settings['phpfpm']['configdir']); + + while(false !== ($phpfpm_filename = readdir($phpfpm_file_dirhandle))) + { + if($phpfpm_filename != '.' + && $phpfpm_filename != '..' + && !in_array($phpfpm_filename, $known_phpfpm_files) + && file_exists(makeCorrectFile($this->settings['phpfpm']['configdir'] . '/' . $phpfpm_filename))) + { + fwrite($this->debugHandler, ' apache::wipeOutOldVhostConfigs: unlinking PHP5-FPM ' . $phpfpm_filename . "\n"); + $this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'unlinking ' . $phpfpm_filename); + unlink(makeCorrectFile($this->settings['phpfpm']['configdir'] . '/' . $phpfpm_filename)); + } + } + } } /* diff --git a/scripts/jobs/cron_tasks.inc.http.15.apache_fcgid.php b/scripts/jobs/cron_tasks.inc.http.15.apache_fcgid.php index 7b697d91..7d321f0f 100644 --- a/scripts/jobs/cron_tasks.inc.http.15.apache_fcgid.php +++ b/scripts/jobs/cron_tasks.inc.http.15.apache_fcgid.php @@ -38,7 +38,7 @@ class apache_fcgid extends apache if((int)$this->settings['phpfpm']['enabled'] == 1) { $php_options_text.= ' SuexecUserGroup "' . $domain['loginname'] . '" "' . $domain['loginname'] . '"' . "\n"; - $php_options_text.= ' FastCgiExternalServer ' . makeCorrectDir($domain['documentroot']) . 'fpm.external -socket ' . $php->getInterface()->getSocketFile() . ' -user ' . $domain['loginname'] . ' -group ' . $domain['loginname'] . "\n"; + $php_options_text.= ' FastCgiExternalServer ' . makeCorrectDir($domain['documentroot']) . 'fpm.external -socket ' . $php->getInterface()->getSocketFile() . ' -user ' . $domain['loginname'] . ' -group ' . $domain['loginname'] . " -idle-timeout " . $this->settings['phpfpm']['idle_timeout'] . "\n"; $php_options_text.= ' ' . "\n"; $php_options_text.= ' ' . "\n"; $php_options_text.= ' SetHandler php5-fastcgi'. "\n"; @@ -52,6 +52,7 @@ class apache_fcgid extends apache } else { + $php_options_text.= ' FastCgiConfig -idle-timeout ' . $this->settings['system']['mod_fcgid_idle_timeout'] . "\n"; if((int)$this->settings['system']['mod_fcgid_wrapper'] == 0) { $php_options_text.= ' SuexecUserGroup "' . $domain['loginname'] . '" "' . $domain['loginname'] . '"' . "\n";