From 4cbafb8f6f14e41bf9d90d4778a0ff5bcce3e584 Mon Sep 17 00:00:00 2001 From: Marcello Coutinho Date: Tue, 2 Dec 2014 03:57:28 -0200 Subject: varnish3 - Add apply changes button to package gui --- config/varnish3/varnish.inc | 58 +++++++++++++++++++++++--------- config/varnish3/varnish_backends.xml | 4 --- config/varnish3/varnish_custom_vcl.xml | 2 -- config/varnish3/varnish_lb_directors.xml | 4 --- config/varnish3/varnish_settings.xml | 1 - pkg_config.10.xml | 2 +- pkg_config.8.xml | 2 +- pkg_config.8.xml.amd64 | 2 +- 8 files changed, 46 insertions(+), 29 deletions(-) diff --git a/config/varnish3/varnish.inc b/config/varnish3/varnish.inc index f14e514e..730bf5ab 100644 --- a/config/varnish3/varnish.inc +++ b/config/varnish3/varnish.inc @@ -41,6 +41,9 @@ if (is_dir('/usr/pbi/varnish-' . php_uname("m"))) { define('VARNISH_LOCALBASE','/usr/local'); } +define('VARNISH_DIRTYPATH',"{$g['varrun_path']}/varnish.conf.dirty"); +define('VARNISH_CONFFILE','/var/etc/default.vcl'); + function varnish_settings_post_validate($post, &$input_errors) { if( !is_numeric($post['storagesize'])) $input_errors[] = "A valid number is required for the field 'Storage size'"; @@ -132,13 +135,22 @@ function text_area_decode($text){ } function varnish_check_config(){ - global $savemsg; + global $savemsg,$config; if (!isset($config['installedpackages']['varnishsettings']['config'][0]['enablevarnish'])) return; - exec(VARNISH_LOCALBASE."/bin/varnishd -C -f /var/etc/default.vcl 2>&1",$output,$return); - if ($return >0){ + exec(VARNISH_LOCALBASE."/bin/varnishd -C -f ".VARNISH_CONFFILE." 2>&1",$output,$return); + if ($return == 0){ + if (isset($_REQUEST['apply'])){ + varnish_start(true); + return; + } + + if (file_exists(VARNISH_DIRTYPATH)) + $savemsg="Varnish configuration has been changed.
You must apply in order to take effect.
"; + } + else{ $savemsg.= implode("
",$output); $savemsg.= "
Daemon will not be restarted."; return 1; @@ -147,13 +159,22 @@ function varnish_check_config(){ } -function varnish_start() { +function varnish_start($force_start=false) { global $g, $config; + + if ($force_start){ + mwexec("/usr/local/etc/rc.d/varnish.sh"); + unlink_if_exists(VARNISH_DIRTYPATH); + return; + } + if ($config['installedpackages']['varnishsettings']['config'][0]['enablevarnish']){ exec("chmod +x /usr/local/etc/rc.d/varnish.sh"); - if (varnish_check_config() == 0) - mwexec("/usr/local/etc/rc.d/varnish.sh");} - else{ + if (varnish_check_config() == 0 || $force_start){ + unlink_if_exists(VARNISH_DIRTYPATH); + mwexec("/usr/local/etc/rc.d/varnish.sh"); + } + }else{ exec("chmod -x /usr/local/etc/rc.d/varnish.sh"); mwexec("/usr/bin/killall varnishd");} } @@ -287,6 +308,7 @@ function create_varnish_rcd_file() { } } $fd = fopen("/usr/local/etc/rc.d/varnish.sh", "w"); + $conf_file=VARNISH_CONFFILE; $rc_file = << ENDOFF /usr/local/sbin/varnishd \ {$listeningport} \ - -f /var/etc/default.vcl \ + -f {$conf_file} \ {$storage_type} \ -w {$minworkers},{$maxworkers},{$timeoutworkers} \ {$advancedstartup} @@ -442,6 +464,12 @@ EOFA; function sync_package_varnish() { global $config, $g; + + if (isset($_POST["apply"])){ + varnish_start(); + unlink_if_exists(VARNISH_DIRTYPATH); + return; + } if (is_array($config['installedpackages']['varnishcustomvcl']['config'])) { foreach($config['installedpackages']['varnishcustomvcl']['config'] as $vcl) { if ($vcl['vcl_recv_early']) @@ -610,7 +638,7 @@ $varnish_config_file = << sync_package_varnish(); - create_varnish_rcd_file(); - varnish_start(); sync_package_varnish(); - create_varnish_rcd_file(); - varnish_start(); varnish_backends_post_validate($_POST, $input_errors); diff --git a/config/varnish3/varnish_custom_vcl.xml b/config/varnish3/varnish_custom_vcl.xml index d0d9ff21..4950c6ed 100644 --- a/config/varnish3/varnish_custom_vcl.xml +++ b/config/varnish3/varnish_custom_vcl.xml @@ -176,7 +176,5 @@ sync_package_varnish(); - create_varnish_rcd_file(); - varnish_start(); \ No newline at end of file diff --git a/config/varnish3/varnish_lb_directors.xml b/config/varnish3/varnish_lb_directors.xml index 313bf0d6..c8868ec4 100644 --- a/config/varnish3/varnish_lb_directors.xml +++ b/config/varnish3/varnish_lb_directors.xml @@ -276,13 +276,9 @@ sync_package_varnish(); - create_varnish_rcd_file(); - varnish_start(); sync_package_varnish(); - create_varnish_rcd_file(); - varnish_start(); varnish_lb_directors_post_validate($_POST, $input_errors); diff --git a/config/varnish3/varnish_settings.xml b/config/varnish3/varnish_settings.xml index b80b7fcf..accfaae8 100644 --- a/config/varnish3/varnish_settings.xml +++ b/config/varnish3/varnish_settings.xml @@ -290,7 +290,6 @@ sync_package_varnish(); create_varnish_rcd_file(); - varnish_start(); varnish_settings_post_validate($_POST, $input_errors); diff --git a/pkg_config.10.xml b/pkg_config.10.xml index 3de363e7..dc62ec96 100644 --- a/pkg_config.10.xml +++ b/pkg_config.10.xml @@ -568,7 +568,7 @@ http://varnish-cache.org https://doc.pfsense.org/index.php/Varnish_package Services - 3.0.5_3 pkg v.0.2.2 + 3.0.5_3 pkg v.0.2.3 RC 2.2 https://packages.pfsense.org/packages/config/varnish3/varnish_backends.xml diff --git a/pkg_config.8.xml b/pkg_config.8.xml index 51fde64e..f4722412 100644 --- a/pkg_config.8.xml +++ b/pkg_config.8.xml @@ -728,7 +728,7 @@ http://varnish-cache.org https://doc.pfsense.org/index.php/Varnish_package Services - 3.0.4 pkg v.0.2.2 + 3.0.4 pkg v.0.2.3 RC 2.0 https://packages.pfsense.org/packages/config/varnish3/varnish_backends.xml diff --git a/pkg_config.8.xml.amd64 b/pkg_config.8.xml.amd64 index 81441cff..86dda795 100644 --- a/pkg_config.8.xml.amd64 +++ b/pkg_config.8.xml.amd64 @@ -715,7 +715,7 @@ http://varnish-cache.org https://doc.pfsense.org/index.php/Varnish_package Services - 3.0.4 pkg v.0.2.2 + 3.0.4 pkg v.0.2.3 RC 2.0 https://packages.pfsense.org/packages/config/varnish3/varnish_backends.xml -- cgit v1.2.3