aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenato Botelho <garga@FreeBSD.org>2014-12-02 07:22:42 -0200
committerRenato Botelho <garga@FreeBSD.org>2014-12-02 07:22:42 -0200
commitfd63b28dc38d26cc59552f11e3f1109b52403bff (patch)
tree861c49a507acb27a8989b33e7177d01ac2c1c1c7
parentab0a79e736a2dce9b93a7a9232f56d45f5bc1b83 (diff)
parent4cbafb8f6f14e41bf9d90d4778a0ff5bcce3e584 (diff)
downloadpfsense-packages-fd63b28dc38d26cc59552f11e3f1109b52403bff.tar.gz
pfsense-packages-fd63b28dc38d26cc59552f11e3f1109b52403bff.tar.bz2
pfsense-packages-fd63b28dc38d26cc59552f11e3f1109b52403bff.zip
Merge pull request #744 from marcelloc/varnish_20141202
-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
-rw-r--r--pkg_config.10.xml2
-rw-r--r--pkg_config.8.xml2
-rw-r--r--pkg_config.8.xml.amd642
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.<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);
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 @@
<website>http://varnish-cache.org</website>
<pkginfolink>https://doc.pfsense.org/index.php/Varnish_package</pkginfolink>
<category>Services</category>
- <version>3.0.5_3 pkg v.0.2.2</version>
+ <version>3.0.5_3 pkg v.0.2.3</version>
<status>RC</status>
<required_version>2.2</required_version>
<config_file>https://packages.pfsense.org/packages/config/varnish3/varnish_backends.xml</config_file>
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 @@
<website>http://varnish-cache.org</website>
<pkginfolink>https://doc.pfsense.org/index.php/Varnish_package</pkginfolink>
<category>Services</category>
- <version>3.0.4 pkg v.0.2.2</version>
+ <version>3.0.4 pkg v.0.2.3</version>
<status>RC</status>
<required_version>2.0</required_version>
<config_file>https://packages.pfsense.org/packages/config/varnish3/varnish_backends.xml</config_file>
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 @@
<website>http://varnish-cache.org</website>
<pkginfolink>https://doc.pfsense.org/index.php/Varnish_package</pkginfolink>
<category>Services</category>
- <version>3.0.4 pkg v.0.2.2</version>
+ <version>3.0.4 pkg v.0.2.3</version>
<status>RC</status>
<required_version>2.0</required_version>
<config_file>https://packages.pfsense.org/packages/config/varnish3/varnish_backends.xml</config_file>