Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to reload web_app immediately via param for definition #442

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Expand Up @@ -557,6 +557,8 @@ combine the template with enabling a site, see `web_app`.

* `name` - Name of the site.
* `enable` - Default true, which uses `a2ensite` to enable the site. If false, the site will be disabled with `a2dissite`.
* `reload_speed` - Defaults to `:delayed` and can be set to `:immediately` to

This comment was marked as outdated.

reload apache service directly after web_app definition during the chef-run

web\_app
--------
Expand Down Expand Up @@ -606,6 +608,20 @@ the apache httpd directives defining the `VirtualHost` that would serve up "my_a
end
``````

If you need your web_app to be accessible during the chef-run and directly after
you ran the definition `web_app`, you can set `reload_speed` to `:immediately`
(which will immediately reload the apache2 service) instead of the default
`:delayed` (which reloads your apache2 configuration at the end of the
chef-run).

``````
web_app "my_app" do
template 'web_app.conf.erb'
server_name node['my_app']['hostname']
reload_speed :immediately
end
``````

All parameters are passed into the template. You can use whatever you
like. The apache2 cookbook comes with a `web_app.conf.erb` template as
an example. The following parameters are used in the template:
Expand Down
4 changes: 2 additions & 2 deletions definitions/web_app.rb
Expand Up @@ -17,7 +17,7 @@
# limitations under the License.
#

define :web_app, :template => 'web_app.conf.erb', :local => false, :enable => true, :server_port => 80 do
define :web_app, :template => 'web_app.conf.erb', :local => false, :enable => true, :server_port => 80, reload_speed: :delayed do
application_name = params[:name]

include_recipe 'apache2::default'
Expand All @@ -37,7 +37,7 @@
:params => params
)
if ::File.exist?("#{node['apache']['dir']}/sites-enabled/#{application_name}.conf")
notifies :reload, 'service[apache2]', :delayed
notifies :reload, 'service[apache2]', params[:reload_speed]

This comment was marked as outdated.

end
end

Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/cookbooks/apache2_test/recipes/basic_web_app.rb
Expand Up @@ -31,6 +31,14 @@
action :create
end

web_app 'basic_immediate_webapp' do
cookbook 'apache2'
server_name node['hostname']
server_aliases [node['fqdn']]
docroot app_dir
reload_speed :immediately
end

web_app 'basic_webapp' do
cookbook 'apache2'
server_name node['hostname']
Expand Down