aboutsummaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
Diffstat (limited to 'config')
-rw-r--r--config/varnish3/varnish.inc58
-rw-r--r--config/varnish3/varnish_backends.xml4
-rw-r--r--config/varnish3/varnish_custom_vcl.xml2
-rw-r--r--config/varnish3/varnish_lb_directors.xml4
-rw-r--r--config/varnish3/varnish_settings.xml1
5 files changed, 43 insertions, 26 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 */
diff --git a/config/varnish3/varnish_backends.xml b/config/varnish3/varnish_backends.xml
index 2a2db35e..95248cb9 100644
--- a/config/varnish3/varnish_backends.xml
+++ b/config/varnish3/varnish_backends.xml
@@ -297,13 +297,9 @@
</custom_php_command_before_form>
<custom_delete_php_command>
sync_package_varnish();
- create_varnish_rcd_file();
- varnish_start();
</custom_delete_php_command>
<custom_php_resync_config_command>
sync_package_varnish();
- create_varnish_rcd_file();
- varnish_start();
</custom_php_resync_config_command>
<custom_php_validation_command>
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 @@
</custom_php_validation_command>
<custom_php_resync_config_command>
sync_package_varnish();
- create_varnish_rcd_file();
- varnish_start();
</custom_php_resync_config_command>
</packagegui> \ 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 @@
</custom_php_command_before_form>
<custom_delete_php_command>
sync_package_varnish();
- create_varnish_rcd_file();
- varnish_start();
</custom_delete_php_command>
<custom_php_resync_config_command>
sync_package_varnish();
- create_varnish_rcd_file();
- varnish_start();
</custom_php_resync_config_command>
<custom_php_validation_command>
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 @@
<custom_php_resync_config_command>
sync_package_varnish();
create_varnish_rcd_file();
- varnish_start();
</custom_php_resync_config_command>
<custom_php_validation_command>
varnish_settings_post_validate($_POST, $input_errors);