Skip to content

Commit f7ef41c

Browse files
author
Hayder Sharhan
committed
Varnish Support
- Changed the way the command works. - m-varnish command now accounts for backwards compatibility. - m-varnish command now works on guest.
1 parent a8339cf commit f7ef41c

File tree

5 files changed

+33
-40
lines changed

5 files changed

+33
-40
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ Running vagrant reload will apply your preference. Or by using m-varnish script.
238238
It will use default file etc/magento2_default_varnish.vcl.dist generated from a Magento instance.
239239
Varnish Version: 3.0.5
240240

241+
Note: command m-varnish with arguments disable or enable is also available in guest or host to enable or disable varnish without reloading machine.
242+
241243
### Multiple Magento instances
242244

243245
To install several Magento instances based on different code bases, just follow [Installation steps](#installation-steps) to initialize project in another directory on the host.

m-varnish

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

3-
# Get args
4-
while getopts 'fh:c:' flag; do
5-
case "${flag}" in
6-
h) help=1 ;;
7-
c) command=$OPTARG ;;
8-
f) force_restart_services=1 ;;
9-
*) help=1 ;;
10-
esac
11-
done
12-
13-
if [[ $help ]]; then
14-
echo "Usage: ./m-varnish -c enable/disable (-f to force restart services)"
15-
exit 0
16-
fi
17-
18-
# Check if user created config.yaml file
19-
if [[ ! -f ./etc/config.yaml ]]; then
20-
echo "Please make sure you have create a config.yaml file copy from etc/config.yaml.dist"
21-
exit 0
22-
fi
23-
24-
if [[ $command == "enable" ]]; then
25-
sed -ie "s/use_varnish:.*/use_varnish: 1/" ./etc/config.yaml
26-
elif [[ $command == "disable" ]]; then
27-
sed -ie "s/use_varnish:.*/use_varnish: 0/" ./etc/config.yaml
28-
else
29-
echo "Usage: ./m-varnish -c enable/disable (-f to force restart services)"
30-
exit 0
31-
fi
32-
333
vagrant_dir=$(cd "$(dirname "$0")"; pwd)
344
cd ${vagrant_dir}
35-
if [[ $force_restart_services == 1 ]]; then
36-
vagrant ssh -c "m-configure_varnish -f"
37-
else
38-
vagrant ssh -c "m-configure_varnish"
39-
fi
40-
41-
echo "Done."
5+
vagrant ssh -c "m-varnish ${@}"

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

Lines changed: 0 additions & 2 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 'f' flag; do
75
case "${flag}" in

scripts/guest/m-varnish

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ $1 == "help" ]]; then
4+
echo "Usage: ./m-varnish enable/disable"
5+
exit 0
6+
fi
7+
8+
# Check if user created config.yaml file
9+
if [[ ! -f /vagrant/etc/config.yaml ]]; then
10+
echo "Please make sure you have create a config.yaml file copy from etc/config.yaml.dist"
11+
exit 1
12+
fi
13+
14+
if [[ -z "$(grep "use_varnish:" /vagrant/etc/config.yaml)" ]]; then
15+
sed -i '/environment:/a \ \ use_varnish: 0' /vagrant/etc/config.yaml
16+
fi
17+
18+
if [[ $1 == "enable" ]]; then
19+
sed -ie "s/use_varnish:.*/use_varnish: 1/" /vagrant/etc/config.yaml
20+
elif [[ $1 == "disable" ]]; then
21+
sed -ie "s/use_varnish:.*/use_varnish: 0/" /vagrant/etc/config.yaml
22+
else
23+
echo "Usage: ./m-varnish enable/disable"
24+
exit 1
25+
fi
26+
27+
configure_varnish
28+
29+
echo "Done."

scripts/provision/configure_environment_recurring.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ else
6767
fi
6868

6969
# Configure Varnish FPC, if enabled
70-
bash ${vagrant_dir}/scripts/guest/m-configure_varnish -f
70+
configure_varnish -f
7171

7272
# Setup PHP
7373
php_ini_paths=( /etc/php/7.0/cli/php.ini /etc/php/5.6/cli/php.ini )

0 commit comments

Comments
 (0)