Commit 5bcf7819 authored by Till Brehm's avatar Till Brehm

Merge branch 'feature/5218-incron-plugin' into 'stable-3.1'

Add incron_plugin, fixes #5218

See merge request ispconfig/ispconfig3!864
parents 061583cf 80ef57a6
Pipeline #503 passed with stage
in 3 minutes and 12 seconds
......@@ -1211,6 +1211,12 @@ $form["tabs"]['web'] = array(
'value' => array('no' => 'disabled_txt', 'fast-cgi' => 'Fast-CGI', 'cgi' => 'CGI', 'mod' => 'Mod-PHP', 'suphp' => 'SuPHP', 'php-fpm' => 'PHP-FPM', 'hhvm' => 'HHVM'),
'searchable' => 2
),
'php_fpm_incron_reload' => array(
'datatype' => 'VARCHAR',
'formtype' => 'CHECKBOX',
'default' => 'y',
'value' => array(0 => 'n', 1 => 'y')
),
'nginx_cgi_socket' => array(
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
......
......@@ -261,6 +261,7 @@ $wb['backup_dir_mount_cmd_txt'] = 'Mount command, if backup directory not mounte
$wb['overquota_db_notify_admin_txt'] = 'Send DB quota warnings to admin';
$wb['overquota_db_notify_client_txt'] = 'Send DB quota warnings to client';
$wb['php_handler_txt'] = 'Default PHP Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['php_ini_check_minutes_txt'] = 'Check php.ini every X minutes for changes';
......
......@@ -261,6 +261,7 @@ $wb['backup_dir_mount_cmd_txt'] = 'Mount command, if backup directory not mounte
$wb['overquota_db_notify_admin_txt'] = 'Send DB quota warnings to admin';
$wb['overquota_db_notify_client_txt'] = 'Send DB quota warnings to client';
$wb['php_handler_txt'] = 'Default PHP Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['php_ini_check_minutes_txt'] = 'Check php.ini every X minutes for changes';
......
......@@ -261,6 +261,7 @@ $wb['backup_dir_mount_cmd_txt'] = 'Usar o comando mount, se o diretório de back
$wb['overquota_db_notify_admin_txt'] = 'Enviar mensagens de alerta de cota do banco de dados para o administrador';
$wb['overquota_db_notify_client_txt'] = 'Enviar mensagens de alerta de cota do banco de dados para o cliente';
$wb['php_handler_txt'] = 'Manipulador padrão PHP';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Desabilitado';
$wb['dkim_strength_txt'] = 'Dificuldade do DKIM';
$wb['php_ini_check_minutes_txt'] = 'Verificar modificações do php.ini a cada N minutos';
......
......@@ -208,6 +208,7 @@ $wb['overquota_db_notify_admin_txt'] = 'Send DB quota warnings to admin';
$wb['overquota_db_notify_client_txt'] = 'Send DB quota warnings to client';
$wb['monitor_system_updates_txt'] = 'Check for Linux updates';
$wb['php_handler_txt'] = 'Default PHP Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['invalid_apache_user_txt'] = 'Invalid apache user.';
......
......@@ -257,6 +257,7 @@ $wb['backup_delete_txt'] = 'Odstranit zálohy pokud byla smazána doména/webov
$wb['overquota_db_notify_admin_txt'] = 'Poslat varování o překročení nebo vyčerpání DB kvót adminovi';
$wb['overquota_db_notify_client_txt'] = 'Poslat varování o překročení nebo vyčerpání DB kvót klientovi';
$wb['php_handler_txt'] = 'Výchozí PHP obslužná rutina';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Vypnuto';
$wb['php_ini_check_minutes_txt'] = 'Provádět kontrolu změny obsahu souboru php.ini každých X minut';
$wb['php_ini_check_minutes_error_empty'] = 'Please specify a value how often php.ini should be checked for changes.';
......
......@@ -267,6 +267,7 @@ $wb['php_ini_check_minutes_txt'] = 'Prüfe php.ini alle X Minuten auf Änderunge
$wb['php_ini_check_minutes_error_empty'] = 'Bitte geben Sie einen Wert an, wie oft die php.ini auf Änderungen geprüft werden soll.';
$wb['php_ini_check_minutes_info_txt'] = '0 = keine Prüfung';
$wb['php_handler_txt'] = 'Standard-PHP-Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['enable_spdy_txt'] = 'Stellt SPDY/HTTP2 zur Verfügung';
$wb['disable_bind_log_txt'] = 'Disable bind9 messages for Loglevel WARN';
$wb['apps_vhost_enabled_txt'] = 'Apps-vhost enabled';
......
......@@ -260,6 +260,7 @@ $wb['backup_delete_txt'] = 'Delete backups on domain/website delete';
$wb['overquota_db_notify_admin_txt'] = 'Send DB quota warnings to admin';
$wb['overquota_db_notify_client_txt'] = 'Send DB quota warnings to client';
$wb['php_handler_txt'] = 'Default PHP Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['php_ini_check_minutes_txt'] = 'Check php.ini every X minutes for changes';
......
......@@ -261,6 +261,7 @@ $wb['backup_delete_txt'] = 'Delete backups on domain/website delete';
$wb['overquota_db_notify_admin_txt'] = 'Send DB quota warnings to admin';
$wb['overquota_db_notify_client_txt'] = 'Send DB quota warnings to client';
$wb['php_handler_txt'] = 'Default PHP Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['php_ini_check_minutes_txt'] = 'Check php.ini every X minutes for changes';
......
......@@ -212,6 +212,7 @@ $wb["overquota_db_notify_admin_txt"] = 'Send DB quota warnings to admin';
$wb["overquota_db_notify_client_txt"] = 'Send DB quota warnings to client';
$wb['monitor_system_updates_txt'] = 'Check for Linux updates';
$wb['php_handler_txt'] = "Default PHP Handler";
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['monitor_system_updates_txt'] = 'Check for Linux updates';
......
......@@ -206,6 +206,7 @@ $wb['php_fpm_socket_dir_txt'] = 'Directorio para el socket de PHP-FPM';
$wb['php_fpm_start_port_error_empty'] = 'El puerto de inicio de PHP-FPM está vacío.';
$wb['php_fpm_start_port_txt'] = 'Puerto de inicio de PHP-FPM';
$wb['php_handler_txt'] = 'Controlador PHP por defecto';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['php_ini_check_minutes_error_empty'] = 'Por favor especifique un valor para definir con qué frecuencia se deberían buscar cambios en el archivo php.ini.';
$wb['php_ini_check_minutes_info_txt'] = '0 = no comprobar';
$wb['php_ini_check_minutes_txt'] = 'Comprobar cambios en php.ini cada X minutos';
......
......@@ -261,6 +261,7 @@ $wb['backup_dir_mount_cmd_txt'] = 'Mount command, if backup directory not mounte
$wb['overquota_db_notify_admin_txt'] = 'Send DB quota warnings to admin';
$wb['overquota_db_notify_client_txt'] = 'Send DB quota warnings to client';
$wb['php_handler_txt'] = 'Default PHP Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['php_ini_check_minutes_txt'] = 'Check php.ini every X minutes for changes';
......
......@@ -259,6 +259,7 @@ $wb['backup_delete_txt'] = 'Delete backups on domain/website delete';
$wb['overquota_db_notify_admin_txt'] = 'Send DB quota warnings to admin';
$wb['overquota_db_notify_client_txt'] = 'Send DB quota warnings to client';
$wb['php_handler_txt'] = 'Default PHP Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['php_ini_check_minutes_txt'] = 'Check php.ini every X minutes for changes';
......
......@@ -261,6 +261,7 @@ $wb['do_not_try_rescue_mongodb_txt'] = 'Disable MongoDB monitoring';
$wb['overquota_db_notify_admin_txt'] = 'Send DB quota warnings to admin';
$wb['overquota_db_notify_client_txt'] = 'Send DB quota warnings to client';
$wb['php_handler_txt'] = 'Default PHP Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['php_ini_check_minutes_txt'] = 'Check php.ini every X minutes for changes';
......
......@@ -261,6 +261,7 @@ $wb['backup_dir_mount_cmd_txt'] = 'Mount command, if backup directory not mounte
$wb['overquota_db_notify_admin_txt'] = 'Send DB quota warnings to admin';
$wb['overquota_db_notify_client_txt'] = 'Send DB quota warnings to client';
$wb['php_handler_txt'] = 'Default PHP Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['php_ini_check_minutes_txt'] = 'Check php.ini every X minutes for changes';
......
......@@ -261,6 +261,7 @@ $wb['backup_dir_mount_cmd_txt'] = 'Mount command, if backup directory not mounte
$wb['overquota_db_notify_admin_txt'] = 'Send DB quota warnings to admin';
$wb['overquota_db_notify_client_txt'] = 'Send DB quota warnings to client';
$wb['php_handler_txt'] = 'Default PHP Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['php_ini_check_minutes_txt'] = 'Check php.ini every X minutes for changes';
......
......@@ -259,6 +259,7 @@ $wb['backup_delete_txt'] = 'Delete backups on domain/website delete';
$wb['overquota_db_notify_admin_txt'] = 'Send DB quota warnings to admin';
$wb['overquota_db_notify_client_txt'] = 'Send DB quota warnings to client';
$wb['php_handler_txt'] = 'Default PHP Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['php_ini_check_minutes_txt'] = 'Check php.ini every X minutes for changes';
......
......@@ -261,6 +261,7 @@ $wb['backup_dir_mount_cmd_txt'] = 'Mount command, if backup directory not mounte
$wb['overquota_db_notify_admin_txt'] = 'Send DB quota warnings to admin';
$wb['overquota_db_notify_client_txt'] = 'Send DB quota warnings to client';
$wb['php_handler_txt'] = 'Default PHP Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['php_ini_check_minutes_txt'] = 'Check php.ini every X minutes for changes';
......
......@@ -261,6 +261,7 @@ $wb['backup_dir_mount_cmd_txt'] = 'Mount command, if backup directory not mounte
$wb['overquota_db_notify_admin_txt'] = 'Send DB quota warnings to admin';
$wb['overquota_db_notify_client_txt'] = 'Send DB quota warnings to client';
$wb['php_handler_txt'] = 'Default PHP Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['php_ini_check_minutes_txt'] = 'Check php.ini every X minutes for changes';
......
......@@ -261,6 +261,7 @@ $wb['backup_dir_mount_cmd_txt'] = 'Mount command, if backup directory not mounte
$wb['overquota_db_notify_admin_txt'] = 'Send DB quota warnings to admin';
$wb['overquota_db_notify_client_txt'] = 'Send DB quota warnings to client';
$wb['php_handler_txt'] = 'Default PHP Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['php_ini_check_minutes_txt'] = 'Check php.ini every X minutes for changes';
......
......@@ -261,6 +261,7 @@ $wb['backup_dir_mount_cmd_txt'] = 'Mount command, if backup directory not mounte
$wb['overquota_db_notify_admin_txt'] = 'Send DB quota warnings to admin';
$wb['overquota_db_notify_client_txt'] = 'Send DB quota warnings to client';
$wb['php_handler_txt'] = 'Default PHP Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['php_ini_check_minutes_txt'] = 'Check php.ini every X minutes for changes';
......
......@@ -261,6 +261,7 @@ $wb['backup_dir_mount_cmd_txt'] = 'Mount command, if backup directory not mounte
$wb['overquota_db_notify_admin_txt'] = 'Send DB quota warnings to admin';
$wb['overquota_db_notify_client_txt'] = 'Send DB quota warnings to client';
$wb['php_handler_txt'] = 'Default PHP Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['php_ini_check_minutes_txt'] = 'Check php.ini every X minutes for changes';
......
......@@ -261,6 +261,7 @@ $wb['backup_dir_mount_cmd_txt'] = 'Выполните команду монти
$wb['overquota_db_notify_admin_txt'] = 'Присылать предупреждения квоты DB администратору';
$wb['overquota_db_notify_client_txt'] = 'Присылать предупреждения квоты DB клиенту';
$wb['php_handler_txt'] = 'Обработчик PHP по умолчанию';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Отключено';
$wb['dkim_strength_txt'] = 'Стойкость DKIM';
$wb['php_ini_check_minutes_txt'] = 'Проверять изменения в PHP.ini файле каждые Х минут';
......
......@@ -261,6 +261,7 @@ $wb['backup_dir_mount_cmd_txt'] = 'Mount command, if backup directory not mounte
$wb['overquota_db_notify_admin_txt'] = 'Send DB quota warnings to admin';
$wb['overquota_db_notify_client_txt'] = 'Send DB quota warnings to client';
$wb['php_handler_txt'] = 'Default PHP Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['php_ini_check_minutes_txt'] = 'Check php.ini every X minutes for changes';
......
......@@ -261,6 +261,7 @@ $wb['backup_dir_mount_cmd_txt'] = 'Mount command, if backup directory not mounte
$wb['overquota_db_notify_admin_txt'] = 'Send DB quota warnings to admin';
$wb['overquota_db_notify_client_txt'] = 'Send DB quota warnings to client';
$wb['php_handler_txt'] = 'Default PHP Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['php_ini_check_minutes_txt'] = 'Check php.ini every X minutes for changes';
......
......@@ -260,6 +260,7 @@ $wb['backup_delete_txt'] = 'Delete backups on domain/website delete';
$wb['overquota_db_notify_admin_txt'] = 'Send DB quota warnings to admin';
$wb['overquota_db_notify_client_txt'] = 'Send DB quota warnings to client';
$wb['php_handler_txt'] = 'Default PHP Handler';
$wb['php_fpm_incron_reload_txt'] = 'Install incron trigger file to reload PHP-FPM';
$wb['disabled_txt'] = 'Disabled';
$wb['dkim_strength_txt'] = 'DKIM strength';
$wb['php_ini_check_minutes_txt'] = 'Check php.ini every X minutes for changes';
......
......@@ -293,6 +293,12 @@
{tmpl_var name='php_handler'}
</select></div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{tmpl_var name='php_fpm_incron_reload_txt'}</label>
<div class="col-sm-9">
{tmpl_var name='php_fpm_incron_reload'}
</div>
</div>
<!-- End content -->
</div>
</div>
......
<?php
/**
* If your websites use PHP-FPM and you have incron installed, you can use this plugin to automatically add incron
* configuration which will take care of reloading the php-fpm pool when the file /private/php-fpm.reload is touched.
* Projects which use deployment tools can use this to reload php-fpm to clear the opcache at deploy time, without
* requiring superuser privileges.
*
* The plugin is prefixed with `z_` because plugins are executed alphabetically, and this plugin
* must only run after apache2/nginx plugins so we are sure the directories and user/group exist.
*/
class z_php_fpm_incron_reload_plugin {
var $plugin_name = 'z_php_fpm_incron_reload_plugin';
var $class_name = 'z_php_fpm_incron_reload_plugin';
function onInstall() {
global $conf;
return $conf['services']['web'] === true;
}
function onLoad() {
global $app;
if ($this->isPluginEnabled() === false) {
return;
}
if ($this->isIncronAvailable() === false) {
$app->log('You must install incron in order to use this plugin', LOGLEVEL_DEBUG);
return;
}
$app->plugins->registerEvent('web_domain_insert', $this->plugin_name, 'incronInsert');
$app->plugins->registerEvent('web_domain_update', $this->plugin_name, 'incronUpdate');
$app->plugins->registerEvent('web_domain_delete', $this->plugin_name, 'incronDelete');
}
function incronInsert($eventName, $data) {
$this->setup($data['new']);
}
function incronUpdate($eventName, $data) {
global $app;
if ($data['new']['document_root'] === $data['old']['document_root']) {
$app->log('Document root unchanged. Not updating incron configuration.', LOGLEVEL_DEBUG);
return;
}
$this->teardown($data['old']);
$this->setup($data['new']);
}
function incronDelete($eventName, $data) {
$this->teardown($data['old']);
}
private function setup($data)
{
$triggerFile = $this->getTriggerFilePath($data['document_root']);
$this->createTriggerFile($triggerFile, $data['system_user'], $data['system_group']);
$this->createIncronConfiguration(
$triggerFile,
$data['system_user'],
$data['fastcgi_php_version']
);
$this->restartIncronService();
}
private function teardown($data) {
$this->deleteIncronConfiguration($data['system_user']);
$this->deleteTriggerFile($this->getTriggerFilePath($data['document_root']));
$file = sprintf('/etc/incron.d/%s.conf', $data['system_user']);
@unlink($file);
$this->restartIncronService();
}
private function isIncronAvailable() {
exec('which incrond', $output, $retval);
return $retval === 0;
}
private function isPluginEnabled() {
global $app, $conf;
$app->uses('getconf');
$serverConfig = $app->getconf->get_server_config($conf['server_id'], 'web');
return $serverConfig['php_fpm_incron_reload'] === 'y';
}
private function createIncronConfiguration($triggerFile, $systemUser, $fastcgiPhpVersion) {
global $app;
$phpService = $this->getPhpService($fastcgiPhpVersion);
$configFile = $this->getIncronConfigurationFilePath($systemUser);
$content = sprintf(
'%s %s %s',
$triggerFile,
'IN_CLOSE_WRITE',
$app->system->getinitcommand($phpService, 'reload')
);
file_put_contents($configFile, $content);
$app->log(sprintf('Created incron configuration "%s"', $configFile), LOGLEVEL_DEBUG);
}
private function createTriggerFile($triggerFile, $systemUser, $systemGroup) {
global $app;
if (!file_exists($triggerFile)) {
exec(sprintf('touch %s', $triggerFile));
}
exec(sprintf('chown %s:%s %s', $systemUser, $systemGroup, $triggerFile));
$app->log(sprintf('Ensured incron trigger file "%s"', $triggerFile), LOGLEVEL_DEBUG);
}
private function deleteIncronConfiguration($systemUser) {
global $app;
$configFile = $this->getIncronConfigurationFilePath($systemUser);
if (!file_exists($configFile)) {
return;
}
unlink($configFile);
$app->log(sprintf('Deleted incron configuration "%s"', $configFile), LOGLEVEL_DEBUG);
}
private function deleteTriggerFile($triggerFile) {
global $app;
if (!file_exists($triggerFile)) {
return;
}
unlink($triggerFile);
$app->log(sprintf('Deleted incron trigger file "%s"', $triggerFile), LOGLEVEL_DEBUG);
}
private function getTriggerFilePath($documentRoot) {
return sprintf('%s/private/php-fpm.reload', $documentRoot);
}
private function getIncronConfigurationFilePath($systemUser) {
return sprintf('/etc/incron.d/%s.conf', $systemUser);
}
private function getPhpService($fastcgiPhpVersion) {
$phpInfo = explode(':', $fastcgiPhpVersion);
if (empty($phpInfo)) {
return null;
}
$phpService = $phpInfo[1];
if (empty($phpService)) {
return null;
}
return $phpService;
}
private function restartIncronService() {
global $app;
$serviceName = 'incrond';
if (file_exists('/etc/debian_version')) {
$serviceName = 'incron';
}
exec($app->system->getinitcommand($serviceName, 'restart'));
}
}
\ No newline at end of file
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