Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 0238113

Browse files
authored
Merge pull request #123 from ByteInternet/inline-ensure-varnish-is-running
inline plugin to ensure varnish is running
2 parents 651cb5b + 5844b69 commit 0238113

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

Vagrantfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ SETTINGS_FILE = "local.yml"
1818
# load the settingsfile or if it does not exist yet a hash where every attribute two levels deep is nil
1919
settings = YAML.load_file(SETTINGS_FILE) rescue Hash.new(Hash.new(nil))
2020

21+
require_relative 'vagrant/plugins/inline/ensure-varnish.rb'
2122
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
2223
# run hypernode-vagrant configuration wizard if needed during 'vagrant up'
2324
config.hypconfigmgmt.enabled = true
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
require "vagrant"
2+
3+
module VagrantPlugins
4+
module VagrantInlinePlugin
5+
class Command
6+
def initialize(app, env)
7+
@app = app
8+
@env = env
9+
end
10+
11+
def call(env)
12+
env[:machine].communicate.sudo(
13+
"ps -ef | grep -v \"grep\" | grep varnishd -q || (service varnish start && sleep 1)",
14+
{:error_check => false}
15+
) do |type, data|
16+
output = data.to_s.strip()
17+
if output.include? "Starting HTTP accelerator varnishd"
18+
env[:ui].info("Started Varnish")
19+
end
20+
end
21+
@app.call(env)
22+
end
23+
end
24+
end
25+
26+
class Plugin < Vagrant.plugin("2")
27+
name "Ensure varnish is started as soon as the instance is started"
28+
29+
action_hook(:VagrantInlinePlugin) do |hook|
30+
hook.after(
31+
Vagrant::Action::Builtin::WaitForCommunicator,
32+
VagrantInlinePlugin::Command
33+
)
34+
end
35+
end
36+
end

vagrant/provisioning/hypernode.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ EOF
4343

4444
# Restart varnish if the hostname changed
4545
if [ ! -d "/var/lib/varnish/$HOSTNAME" ]; then
46-
service varnish restart
46+
service varnish restart && sleep 1
4747
fi
4848

4949
rm -rf /etc/cron.d/hypernode-fpm-monitor
@@ -65,10 +65,6 @@ else
6565
sudo -u $user rm -f /data/web/nginx/magento2.flag
6666
fi
6767

68-
# ensure varnish is running. in lxc vagrant boxes for some reason the varnish init script in /etc/init.d doesn't bring up the service on boot
69-
# todo: find out why varnish isn't always started on startup on lxc instances
70-
ps -ef | grep -v "grep" | grep varnishd -q || (service varnish start && sleep 1)
71-
7268
# if the webroot is empty, place our default index.php which shows the settings
7369
if ! find /data/web/public/ -mindepth 1 -name '*.php' -name '*.html' | read; then
7470
cp /vagrant/vagrant/resources/*.{php,js,css} /data/web/public/
@@ -132,7 +128,7 @@ if $xdebug_enabled; then
132128
echo "this article: https://support.hypernode.com/knowledgebase/install-xdebug-hypernode-vagrant/"
133129
fi
134130

135-
if ! $varnish_enabled; then
131+
if ! $varnish_enabled; then
136132
su $user -c "echo -e 'vcl 4.0;\nbackend default {\n .host = \"127.0.0.1\";\n .port= \"8080\";\n}\nsub vcl_recv {\n return(pass);\n}' > /data/web/disabled_caching.vcl"
137133
varnishadm vcl.list | grep -q nocache || varnishadm vcl.load nocache /data/web/disabled_caching.vcl
138134
varnishadm vcl.use nocache

0 commit comments

Comments
 (0)