diff options
author | Marcello Coutinho <marcellocoutinho@gmail.com> | 2014-12-02 03:57:28 -0200 |
---|---|---|
committer | marcelloc <marcellocoutinho@gmail.com> | 2014-12-02 03:57:28 -0200 |
commit | 4cbafb8f6f14e41bf9d90d4778a0ff5bcce3e584 (patch) | |
tree | 861c49a507acb27a8989b33e7177d01ac2c1c1c7 /config/varnish3/varnish.inc | |
parent | ab0a79e736a2dce9b93a7a9232f56d45f5bc1b83 (diff) | |
download | pfsense-packages-4cbafb8f6f14e41bf9d90d4778a0ff5bcce3e584.tar.gz pfsense-packages-4cbafb8f6f14e41bf9d90d4778a0ff5bcce3e584.tar.bz2 pfsense-packages-4cbafb8f6f14e41bf9d90d4778a0ff5bcce3e584.zip |
varnish3 - Add apply changes button to package gui
Diffstat (limited to 'config/varnish3/varnish.inc')
-rw-r--r-- | config/varnish3/varnish.inc | 58 |
1 files changed, 43 insertions, 15 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.<br>You must apply in order to take effect.<br>"; + } + else{ $savemsg.= implode("<br>",$output); $savemsg.= "<br>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 = <<<EOF #!/bin/sh mkdir -p /var/varnish @@ -306,14 +328,14 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ require_once("pkg-utils.inc"); require_once("varnish.inc"); sync_package_varnish(); - #varnish_start(); + unlink_if_exists(VARNISH_DIRTYPATH); ?> 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 = <<<EOF # Varnish configuration file # Automatically generated by the pfSense package system -# This file is located in /var/etc/default.vcl +# This file is located in {$conf_file} sub vcl_error { if (obj.status == 503 && req.restarts < {$vcl_restarts}) { @@ -710,7 +738,10 @@ sub vcl_fini { } EOF; - file_put_contents("/var/etc/default.vcl",$varnish_config_file,LOCK_EX); + file_put_contents(VARNISH_CONFFILE,$varnish_config_file,LOCK_EX); + touch(VARNISH_DIRTYPATH); + varnish_sync_on_changes(); + $cc_file=VARNISH_LOCALBASE."/bin/cc"; foreach (glob(VARNISH_LOCALBASE."/bin/gcc*") as $bin_file) { $gcc_file=$bin_file; @@ -719,11 +750,8 @@ EOF; symlink($gcc_file,$cc_file); } - $fd = fopen("/var/etc/default.vcl", "w"); - fwrite($fd, $varnish_config_file); - fclose($fd); + create_varnish_rcd_file(); - varnish_sync_on_changes(); } /* Uses XMLRPC to synchronize the changes to a remote node */ |