Skip to content

Commit 0ff8688

Browse files
jaymzhfacebook-github-bot
authored andcommitted
fb_apache: Add 'manage_service' configurable (facebook#247)
Summary: It is sometimes desired to have apache configured but not running. Allow the user to manage the service themselves, just like we do with packages. Of course, the default remains that Chef manages the service. I added a few nicities here: * For those who were using `manage_packages=false`, you can now easily get the list of packages cleanly * You also easily get the right service name Signed-off-by: Phil Dibowitz <phil@ipom.com> Pull Request resolved: facebook#247 Differential Revision: D68170508 fbshipit-source-id: c23831cd9d4a9b47f272863f87a07b54d58b0dd7
1 parent d3f443e commit 0ff8688

File tree

4 files changed

+39
-20
lines changed

4 files changed

+39
-20
lines changed

cookbooks/fb_apache/README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Requirements
88
Attributes
99
----------
1010
* node['fb_apache']['manage_packages']
11+
* node['fb_apache']['manage_service']
1112
* node['fb_apache']['sites'][$SITE][$CONFIG]
1213
* node['fb_apache']['sysconfig'][$KEY]
1314
* node['fb_apache']['sysconfig']['_extra_lines']
@@ -22,17 +23,27 @@ Attributes
2223
Usage
2324
-----
2425
### Packages
25-
My default `fb_apache` will install and keep up to date the `apache` and
26+
By default `fb_apache` will install and keep up to date the `apache` and
2627
`mod_ssl` packages as relevant for your distribution. If you'd prefer to do
2728
this on your own then you can set `node['fb_apache']['manage_packages']` to
28-
`false`.
29+
`false` and get the set of packages by calling `FB::Apache.packages` - but
30+
you must do this at runtime (i.e. in a `lazy` block) if you want it to take
31+
into account your `node['fb_apache']['modules']` settings.
2932

3033
For modules, we keep a mapping of the package required for modules in
3134
`node['fb_apache']['module_packages']`. If `manage_packages` is enabled, we will
3235
install the relevant packages for any modules you enable in
3336
`node['fb_apache']['modules']`. This is important since it'll happen before we
3437
attempt to start apache.
3538

39+
### Service
40+
By default, `fb_apache` will enable and start the Apache service, whatever it
41+
may be called on your platform. If you'd prefer to do this on your own you can
42+
set `node['fb_apache']['manage_service']` to `false` and get the name of the
43+
service on your platform from `FB::Apache.service`. Do not name the resource
44+
`service[apache]`, however, as it'll conflict with the resource from this
45+
cookbook (which will be `only_if`'d out).
46+
3647
### Sites / VirtualHosts
3748
The `node['fb_apache']['sites']` hash configures virtual hosts. All virtual
3849
hosts are kept in a single file called `fb_apache_sites.cfg` in a directory

cookbooks/fb_apache/attributes/default.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
default['fb_apache'] = {
8989
'sysconfig' => sysconfig,
9090
'manage_packages' => true,
91+
'manage_service' => true,
9192
'enable_default_site' => true,
9293
'sites' => {},
9394
'extra_configs' => {},

cookbooks/fb_apache/libraries/default.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,26 @@ def self.template_rewrite_helper(buf, _indent, _key, rules)
6767
def self.get_module_packages(mods, pkgs)
6868
mods.map { |mod| pkgs[mod] }.uniq.compact
6969
end
70+
71+
def self.base_packages(node)
72+
node.value_for_platform_family(
73+
'rhel' => ['httpd', 'mod_ssl'],
74+
'debian' => ['apache2'],
75+
)
76+
end
77+
78+
def self.packages(node)
79+
base_packages(node) + FB::Apache.get_module_packages(
80+
node['fb_apache']['modules'],
81+
node['fb_apache']['module_packages'],
82+
)
83+
end
84+
85+
def self.service(node)
86+
node.value_for_platform_family(
87+
'rhel' => 'httpd',
88+
'debian' => 'apache2',
89+
)
90+
end
7091
end
7192
end

cookbooks/fb_apache/recipes/default.rb

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,9 @@
9999
'debian' => '/etc/default/apache2',
100100
)
101101

102-
pkgs = value_for_platform_family(
103-
'rhel' => ['httpd', 'mod_ssl'],
104-
'debian' => ['apache2'],
105-
)
106-
107-
svc = value_for_platform_family(
108-
'rhel' => 'httpd',
109-
'debian' => 'apache2',
110-
)
111-
112-
package pkgs do
102+
package 'apache packages' do
113103
only_if { node['fb_apache']['manage_packages'] }
114-
package_name lazy {
115-
pkgs + FB::Apache.get_module_packages(
116-
node['fb_apache']['modules'],
117-
node['fb_apache']['module_packages'],
118-
)
119-
}
104+
package_name lazy { FB::Apache.packages(node) }
120105
action :upgrade
121106
end
122107

@@ -229,6 +214,7 @@
229214
end
230215

231216
service 'apache' do
232-
service_name svc
217+
only_if { node['fb_apache']['manage_service'] }
218+
service_name FB::Apache.service(node)
233219
action [:enable, :start]
234220
end

0 commit comments

Comments
 (0)