Skip to content

Commit 235f943

Browse files
author
Hayder Sharhan
committed
Varnish Support
- Changed name. - Made script executable. - Cache is cleared now after restarting services.
1 parent 3c9a680 commit 235f943

File tree

4 files changed

+25
-28
lines changed

4 files changed

+25
-28
lines changed

etc/config.yaml.dist

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
repository_url:
2-
# [Changeable: init-project -c]
2+
# [To apply changes: init-project -c]
33
ce: "git@github.com:magento/magento2.git"
44
ee: ""
55
guest:
6-
# [Changeable: init-project -f]
6+
# [To apply changes: init-project -f]
77
# NFS will be used for folder synchronization on *nix and OSX hosts by default.
88
use_nfs: 1
99
# Default is 2Gb, around 3Gb is necessary to run functional tests.
10-
# [Changeable: vagrant reload]
10+
# [To apply changes: vagrant reload]
1111
memory: 2048
1212
ip_address: "192.168.10.2"
1313
forwarded_ssh_port: 3000
1414
environment:
15-
# [Changeable: vagrant reload]
15+
# [To apply changes: vagrant reload]
1616
# If set to 0, PHP 5 will be installed.
1717
use_php7: 1
1818
composer_prefer_source: 0
1919
use_varnish: 0
2020
magento:
21-
# [Changeable: init-project -f]
21+
# [To apply changes: init-project -f]
2222
host_name: "magento2.vagrant2"
23-
# [Changeable: m-reinstall]
23+
# [To apply changes: m-reinstall]
2424
admin_frontname: "admin"
2525
language: "en_US"
2626
timezone: "America/Chicago"

m-varnish

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env bash
22

3-
set -ex
4-
53
# Get args
64
while getopts 'fh:c:' flag; do
75
case "${flag}" in
@@ -12,13 +10,13 @@ while getopts 'fh:c:' flag; do
1210
esac
1311
done
1412

15-
if [ $help ]; then
13+
if [[ $help ]]; then
1614
echo "Usage: ./m-varnish -c enable/disable (-f to force restart services)"
1715
exit 0
1816
fi
1917

2018
# Check if user created config.yaml file
21-
if [ ! -f ./etc/config.yaml ]; then
19+
if [[ ! -f ./etc/config.yaml ]]; then
2220
echo "Please make sure you have create a config.yaml file copy from etc/config.yaml.dist"
2321
exit 0
2422
fi
@@ -35,7 +33,9 @@ fi
3533
vagrant_dir=$(cd "$(dirname "$0")"; pwd)
3634
cd ${vagrant_dir}
3735
if [[ $force_restart_services == 1 ]]; then
38-
vagrant ssh -c "sudo bash /vagrant/scripts/guest/configure_varnish -f"
36+
vagrant ssh -c "m-configure_varnish -f"
3937
else
40-
vagrant ssh -c "sudo bash /vagrant/scripts/guest/configure_varnish"
38+
vagrant ssh -c "m-configure_varnish"
4139
fi
40+
41+
echo "Done."

scripts/guest/configure_varnish renamed to scripts/guest/m-configure_varnish

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env bash
22

3-
# Enable trace printing and exit on the first error
43
set -ex
54

65
# Get args
@@ -17,18 +16,18 @@ vagrant_dir="/vagrant"
1716
# Configure Varnish if enabled in config
1817
restart_services=0
1918
use_varnish=$(bash "${vagrant_dir}/scripts/get_config_value.sh" "environment_use_varnish")
20-
if [ $use_varnish -eq 1 ]; then
19+
if [[ $use_varnish == 1 ]]; then
2120

2221
# Configure apache files to be ready for varnish
23-
if [ -z "$(grep "VirtualHost\s\*:8080" /etc/apache2/sites-enabled/magento2.conf)" ]; then
22+
if [[ -z "$(grep "VirtualHost\s\*:8080" /etc/apache2/sites-enabled/magento2.conf)" ]]; then
2423
sudo sed -ie "s/<VirtualHost .*/<VirtualHost \*:8080>/" /etc/apache2/sites-enabled/magento2.conf
2524
restart_services=1
2625
fi
27-
if [ -z "$(grep "VirtualHost\s\*:8080" /etc/apache2/sites-available/magento2.conf)" ]; then
26+
if [[ -z "$(grep "VirtualHost\s\*:8080" /etc/apache2/sites-available/magento2.conf)" ]]; then
2827
sudo sed -ie "s/<VirtualHost .*/<VirtualHost \*:8080>/" /etc/apache2/sites-available/magento2.conf
2928
restart_services=1
3029
fi
31-
if [ -z "$(grep "Listen\s8080" /etc/apache2/ports.conf)" ]; then
30+
if [[ -z "$(grep "Listen\s8080" /etc/apache2/ports.conf)" ]]; then
3231
sudo sed -ie "s/Listen 80/Listen 8080/" /etc/apache2/ports.conf
3332
restart_services=1
3433
fi
@@ -42,15 +41,15 @@ if [ $use_varnish -eq 1 ]; then
4241
else
4342

4443
# Configure apache files to run without varnish
45-
if [ -z "$(grep "VirtualHost\s\*:80\b" /etc/apache2/sites-enabled/magento2.conf)" ]; then
44+
if [[ -z "$(grep "VirtualHost\s\*:80\b" /etc/apache2/sites-enabled/magento2.conf)" ]]; then
4645
sudo sed -ie "s/<VirtualHost .*/<VirtualHost \*:80>/" /etc/apache2/sites-enabled/magento2.conf
4746
restart_services=1
4847
fi
49-
if [ -z "$(grep "VirtualHost\s\*:80\b" /etc/apache2/sites-available/magento2.conf)" ]; then
48+
if [[ -z "$(grep "VirtualHost\s\*:80\b" /etc/apache2/sites-available/magento2.conf)" ]]; then
5049
sudo sed -ie "s/<VirtualHost .*/<VirtualHost \*:80>/" /etc/apache2/sites-available/magento2.conf
5150
restart_services=1
5251
fi
53-
if [ -z "$(grep "Listen\s80\b" /etc/apache2/ports.conf)" ]; then
52+
if [[ -z "$(grep "Listen\s80\b" /etc/apache2/ports.conf)" ]]; then
5453
sudo sed -ie "s/Listen 8080/Listen 80/" /etc/apache2/ports.conf
5554
restart_services=1
5655
fi
@@ -68,15 +67,13 @@ if [[ $force_restart_services == 1 ]]; then
6867
echo "Force restarting Apache and Varnish"
6968
restart_services=1
7069
fi
71-
if [ $restart_services -eq 1 ]; then
72-
if [ "$(ps -ax | pgrep varnish)" ]; then
70+
if [[ $restart_services == 1 ]]; then
71+
if [[ "$(ps -ax | pgrep varnish)" ]]; then
7372
sudo pkill varnishd
7473
fi
75-
if [ "$(ps -ax | pgrep apache2)" ]; then
76-
sudo apache2ctl stop
77-
fi
78-
sudo apache2ctl start
79-
if [ $use_varnish -eq 1 ]; then
74+
sudo service apache2 restart
75+
if [[ $use_varnish == 1 ]]; then
8076
sudo varnishd -f /etc/varnish/default.vcl
8177
fi
78+
bash "${vagrant_dir}/scripts/guest/m-clear-cache"
8279
fi

scripts/provision/configure_environment_recurring.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ else
6363
fi
6464

6565
# Configure Varnish FPC, if enabled
66-
bash ${vagrant_dir}/scripts/guest/configure_varnish -f
66+
bash ${vagrant_dir}/scripts/guest/m-configure_varnish -f
6767

6868
# Setup PHP
6969
php_ini_paths=( /etc/php/7.0/cli/php.ini /etc/php/5.6/cli/php.ini )

0 commit comments

Comments
 (0)