Skip to content

Commit 13518e8

Browse files
author
jtimberman
committed
Merge branch 'master' into thewoolleyman/COOK-301
2 parents fb4fff5 + 0d619e9 commit 13518e8

18 files changed

Lines changed: 269 additions & 202 deletions

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ tmp/*
22
.rake_test_cache
33
*.swp
44
*.swo
5+
*~

‎application/README.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ Using the node's `run_state` that contains the current application in the search
5858

5959
This recipe can be used on nodes that are going to run the application, or on nodes that need to have the application code checkout available such as supporting utility nodes or a configured load balancer that needs static assets stored in the application repository.
6060

61+
For Gem Bundler: include `bundler` or `bundler08` in the gems list. `bundle install` or `gem bundle` will be run before migrations.
62+
For config.gem in environment: `rake gems:install RAILS_ENV=<node environment>` will be run when a Gem Bundler command is not.
63+
6164
unicorn
6265
-------
6366

@@ -133,7 +136,7 @@ Note about gems and packages, the version is optional. If specified, the version
133136
"production": "true or false boolean to force migration, see rails.rb recipe"
134137
},
135138
"databases": {
136-
"db_name_production": {
139+
"production": {
137140
"reconnect": "true",
138141
"encoding": "utf8",
139142
"username": "db_user",

‎application/recipes/rails.rb‎

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,45 @@
169169
user app['owner']
170170
group app['group']
171171
deploy_to app['deploy_to']
172+
environment 'RAILS_ENV' => node.app_environment
172173
action app['force'][node.app_environment] ? :force_deploy : :deploy
173174
ssh_wrapper "#{app['deploy_to']}/deploy-ssh-wrapper" if app['deploy_key']
175+
176+
before_migrate do
177+
if app['gems'].has_key?('bundler')
178+
execute "bundle install" do
179+
ignore_failure true
180+
cwd release_path
181+
end
182+
elsif app['gems'].has_key?('bundler08')
183+
execute "gem bundle" do
184+
ignore_failure true
185+
cwd release_path
186+
end
187+
188+
elsif node.app_environment && app['databases'].has_key?(node.app_environment)
189+
# chef runs before_migrate, then symlink_before_migrate symlinks, then migrations,
190+
# yet our before_migrate needs database.yml to exist (and must complete before
191+
# migrations).
192+
#
193+
# maybe worth doing run_symlinks_before_migrate before before_migrate callbacks,
194+
# or an add'l callback.
195+
execute "(ln -s ../../../shared/database.yml config/database.yml && rake gems:install); rm config/database.yml" do
196+
ignore_failure true
197+
cwd release_path
198+
end
199+
end
200+
end
201+
202+
symlink_before_migrate({
203+
"database.yml" => "config/database.yml",
204+
"memcached.yml" => "config/memcached.yml"
205+
})
206+
174207
if app['migrate'][node.app_environment] && node[:apps][app['id']][node.app_environment][:run_migrations]
175208
migrate true
176209
migration_command "rake db:migrate"
177210
else
178211
migrate false
179212
end
180-
symlink_before_migrate({
181-
"database.yml" => "config/database.yml",
182-
"memcached.yml" => "config/memcached.yml"
183-
})
184213
end

‎application/recipes/unicorn.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
node.default[:unicorn][:worker_timeout] = 60
2525
node.default[:unicorn][:preload_app] = false
26-
node.default[:unicorn][:worker_processes] = node[:cpu][:total].to_i * 4
26+
node.default[:unicorn][:worker_processes] = [node[:cpu][:total].to_i * 4, 8].min
2727
node.default[:unicorn][:preload_app] = false
2828
node.default[:unicorn][:before_fork] = 'sleep 1'
2929
node.default[:unicorn][:port] = '8080'

‎chef/README.md‎

Lines changed: 91 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,21 @@ This cookbook is used to configure the system to be a Chef Client or a Chef Serv
2121
REQUIREMENTS
2222
============
2323

24-
Chef 0.8.x or higher is required.
24+
Chef 0.8.16 or later is required.
25+
26+
Chef 0.9.0 or later is required to use the `chef.init_style` attribute value `init`, in order to have the init scripts available.
2527

2628
Platform
2729
--------
2830

29-
If using this cookbook to manage a Chef Server system that was installed from Debian/Ubuntu packages, note that the configuration files are split up for server.rb, solr.rb and webui.rb, and the `chef::server` recipe may not work as desired.
31+
If using this cookbook to manage a Chef Server system that was installed from Debian/Ubuntu packages, note that in the packages, the configuration files are split up for server.rb, solr.rb and webui.rb, and the `chef::server` recipe may not work as desired.
32+
33+
We recommend using a recent version of Ubuntu or Debian for the Chef Server.
34+
35+
* Ubuntu 9.10/10.04
36+
* Debian testing/unstable
37+
38+
These versions have newer versions of CouchDB and RabbitMQ packaged.
3039

3140
`chef::client` is tested on Ubuntu 8.04+, Debian 5.0, CentOS 5.x, Fedora 10+, OpenBSD 4.6, FreeBSD 7.1 and Gentoo.
3241

@@ -44,14 +53,14 @@ Client
4453
Server
4554
------
4655

47-
The `chef::bootstrap_server` recipe uses the following other cookbooks from the Opscode repo.
56+
The `chef::bootstrap_server` recipe uses the following other cookbooks from the Opscode repository.
4857

49-
couchdb
50-
rabbitmq_chef
51-
openssl
52-
zlib
53-
xml
54-
java
58+
* couchdb
59+
* `rabbitmq_chef`
60+
* openssl
61+
* zlib
62+
* xml
63+
* java
5564

5665
The `chef::server_proxy` recipe uses the following cookbook:
5766

@@ -62,6 +71,8 @@ ATTRIBUTES
6271

6372
The attributes for configuring the `chef` cookbook are under the `chef` namespace on the node, i.e., `@node[:chef]` or `@node.chef`.
6473

74+
When using the bootstrap recipe, set the desired attributes using a JSON file. See "BOOTSTRAPPING" for examples.
75+
6576
umask
6677
-----
6778

@@ -77,9 +88,13 @@ By default the only URL config setting for Chef 0.8.x+ is `Chef::Config[:chef_se
7788
init_style
7889
----------
7990

80-
Specifies the init style to use. Default `runit`. Other possible values `init`, `bsd`, any other string will be treated as unknown.
91+
Specifies the init style to use. Default `runit`. Other possible values `init`, `bsd`, any other string will be treated as unknown and a message will be displayed during the Chef run.
92+
93+
If your platform doesn't have a `runit` package or if the cookbook doesn't detect it, but you still want to use runit, set `init_style` to `none` and install runit separately. You may need to configure the runit services separately.
8194

82-
If your platform doesn't have a `runit` package or if the cookbook doesn't detect it, but you still want to use runit, set `init_style` to `none` and install runit separately.
95+
Using the `init` value for this attribute will retrieve the init scripts that are distributed with the Chef gem.
96+
97+
This cookbook does not yet support Upstart for Ubuntu/Debian, but that is planned for a future release, and will be specified via this attribute.
8398

8499
path
85100
----
@@ -104,7 +119,7 @@ If `init_style` is `init`, this is used, and should match what the init script i
104119
cache_path
105120
----------
106121

107-
Location where the client will cache cookbooks and other data. Default is `cache` underneath the `chef[:path]` location. Linux distributions might prefer `/var/cache/chef` instead.
122+
Location where the client will cache cookbooks and other data. Default is `cache` underneath the `chef[:path]` location. Linux distributions adhering to the FHS prefer `/var/cache/chef` instead.
108123

109124
Base directory for data that is easily regenerated such as cookbook tarballs (`Chef::Config[:cookbook_tarballs]`) on the server, downloaded cookbooks on the client, etc. See the config templates.
110125

@@ -116,12 +131,12 @@ Used by the Chef server as the base location to "serve" cookbooks, roles and oth
116131
server_version
117132
--------------
118133

119-
Version of Chef to install for the server. Used by the `server_proxy` recipe to set the location of the DocumentRoot of the WebUI.
134+
Version of Chef to install for the server. Used by the `server_proxy` recipe to set the location of the DocumentRoot of the WebUI. Automatically determined via ohai's `chef_packages[:chef][:version]` by default.
120135

121136
client_version
122137
--------------
123138

124-
Version of Chef to install for the client. Used to display a log message about the location of the init scripts when `init_style` is `init`, and can be used to upgrade `chef` gem with the `chef::bootstrap_client` recipe.
139+
Version of Chef to install for the client. Used to display a log message about the location of the init scripts when `init_style` is `init`, and can be used to upgrade `chef` gem with the `chef::bootstrap_client` recipe. Automatically determined via ohai's `chef_packages[:chef][:version]` by default.
125140

126141
client_interval
127142
---------------
@@ -136,14 +151,12 @@ Splay interval to randomly add to interval. Default `20`.
136151
log_dir
137152
-------
138153

139-
Directory where logs are stored if logs are not sent to STDOUT. Systems using runit should send logs to STDOUT as runit manages log output. Default STDOUT when `init_style` is `runit`, otherwise the default is `/var/log/chef`.
154+
When `init_style` is `init`, this directory needs to be created. The default is `/var/log/chef`.
140155

141156
client_log, indexer_log, server_log
142157
-----------------------------------
143158

144-
Location of the client, indexer and server logs, respectively. Default `STDOUT` on systems with runit, `/var/log/chef/{client,indexer,server}.log` on other systems.
145-
146-
Note that `chef-indexer` is deprecated for `chef-solr-indexer`.
159+
These options are deprecated to reduce complexity and potential confusion.
147160

148161
server_port
149162
-----------
@@ -160,12 +173,6 @@ webui_enabled
160173

161174
As of version 0.8.x+, the WebUI part of the Chef Server is optional, and disabled by default. To enable it, set this to true.
162175

163-
webui_admin_password
164-
--------------------
165-
166-
The default password in the `Chef::Config` is `p@ssw0rd1`, which may not be desirable. Change the webui `admin` user's password with this attribute. Note that this may require the `chef-server-webui` service be restarted an additional time, and it should still be changed on first login with the `admin` user.
167-
168-
169176
server_fqdn
170177
-----------
171178

@@ -175,6 +182,21 @@ On servers, this specifies the URL the server expects to use by default `Chef::C
175182

176183
On clients, this specifies the URL the client uses to connect to the server as `Chef::Config[:chef_server_url]`.
177184

185+
server_url
186+
----------
187+
188+
Full URI for the Chef Server. Used for `chef_server_url` config setting. The default value combines the attributes `chef.url_type`, `chef.server_fqdn` and `chef.server_port`, creating for example "http://chef.example.com:4000". If you are using the Opscode Platform, set this to "https://api.opscode.com/organizations/ORGNAME", where ORGNAME is your organization's simple string name.
189+
190+
SERVER PROXY
191+
------------
192+
193+
The following attributes are used by the `server_proxy.rb` recipe, and are stored in the `server_proxy.rb` attributes file.
194+
195+
doc_root
196+
--------
197+
198+
DocumentRoot for the WebUI. Also gets set in the vhost for the API, but it is not used since the vhost merely proxies to the server on port 4000.
199+
178200
server_ssl_req
179201
--------------
180202

@@ -188,11 +210,30 @@ Used by the `server_proxy` recipe, this attribute can be used to set up a self-s
188210
* CN: canonical name, usually the fully qualified domain name of the server (FQDN)
189211
* emailAddress: contact email address
190212

213+
This attribute is now in the `server_proxy.rb` attributes file, as it is specific to that context.
214+
215+
server_proxy.css_expire_hours
216+
-----------------------------
217+
218+
Sets expiration time for CSS in the WebUI.
219+
220+
server_proxy.js_expire_hours
221+
----------------------------
222+
223+
Sets expiration time for JavaScript in the WebUI.
224+
191225
RECIPES AND USAGE
192226
=================
193227

194228
This section describes the recipes in the cookbook and how to use them in your environment.
195229

230+
BOOTSTRAPPING
231+
-------------
232+
233+
The first two recipes described are for "bootstrapping" a system to be a Chef Client or Chef Server, respectively. Only use these recipes with RubyGems installations of Chef.
234+
235+
These recipes are typically used with chef-solo using a JSON file of attributes and a run list, and a solo config file. For more information see [Bootstrap Chef RubyGems Installation](http://wiki.opscode.com/display/chef/Bootstrap+Chef+RubyGems+Installation) on the Chef Wiki.
236+
196237
bootstrap_client
197238
----------------
198239

@@ -205,20 +246,25 @@ Use this recipe to "bootstrap" a client so it can connect to a Chef Server. This
205246
* Sets up some directories for Chef to use.
206247
* Creates the client configuration file `/etc/chef/client.rb` based on the configuration passed via JSON.
207248

208-
Minimal JSON to use for the client configuration:
249+
For configuring a new client to connect to the Opscode Platform:
209250

210251
{
211252
"chef": {
212-
"url_type": "http",
213-
"init_style": "runit",
214-
"server_port": "4000",
215-
"path": "/srv/chef",
216-
"server_fqdn": "localhost.localdomain",
253+
"server_url": "https://api.opscode.com/organizations/ORGNAME"
217254
},
218255
"run_list": "recipe[chef::bootstrap_client]"
219256
}
220257

221-
This recipe is typically used with chef-solo. For more information see [Bootstrap Chef RubyGems Installation](http://wiki.opscode.com/display/chef/Bootstrap+Chef+RubyGems+Installation)
258+
For configuring a new client to connect to a local Chef Server:
259+
260+
{
261+
"chef": {
262+
"server_url": "http://chef.example.com:4000"
263+
},
264+
"run_list": "recipe[chef::bootstrap_client]"
265+
}
266+
267+
This is the minimal JSON to use for the client configuration. See the ATTRIBUTES section above for more options.
222268

223269
bootstrap_server
224270
----------------
@@ -232,20 +278,15 @@ Use this recipe to "bootstrap" a system to become a Chef Server. This recipe doe
232278
* Installs Java for the `chef-solr` search engine.
233279
* Installs RabbitMQ (`rabbitmq_chef` cookbook) for the `chef-solr-indexer` consumer.
234280
* Installs all the Server-related Gems.
235-
* Creates the server configuration file `/etc/chef/server.rb` based on the configuration passed via JSON.
281+
* Creates the server configuration file `/etc/chef/server.rb` based on the configuration passed via JSON.
236282
* Sets up some directories for the server to use.
237283
* Sets up the `chef-server`, `chef-solr`, `chef-solr-indexer` services depending on the `init_style` attribute (see above).
238284

239-
Minimal JSON to use for the client configuration:
285+
Minimal JSON to use for the server configuration:
240286

241287
{
242-
"chef": {
243-
"url_type": "http",
244-
"init_style": "runit",
245-
"path": "/srv/chef",
246-
"server_port": "4000",
247-
"serve_path": "/srv/chef",
248-
"server_fqdn": "localhost.localdomain",
288+
"chef": {
289+
"server_url": "http://localhost.localdomain:4000",
249290
},
250291
"run_list": "recipe[chef::bootstrap_server]"
251292
}
@@ -254,27 +295,27 @@ Note that the `chef-server-webui` is optional and can be enabled if desired by a
254295

255296
"webui_enabled": true
256297

257-
See above about the `webui_admin_password` to use something other than the `Chef::Config` default.
258-
259-
This recipe is typically used with chef-solo. For more information see [Bootstrap Chef RubyGems Installation](http://wiki.opscode.com/display/chef/Bootstrap+Chef+RubyGems+Installation)
260-
261298
client
262299
------
263300

264301
The client recipe is used to manage the configuration of an already-installed and configured Chef client. It can be used after a RubyGems installation bootstrap (per above), or with clients that were installed from platform packaging.
265302

266-
The recipe itself manages the `/etc/chef/client.rb` config file based on the attributes in this cookbook. When the client config is updated, the recipe will also reread the configuration during the Chef run, so the way Chef runs can be dynamically changed.
303+
The recipe itself manages the `/etc/chef/client.rb` config file based on the attributes in this cookbook. When the client config is updated, the recipe will also reread the configuration during the Chef run, so the current Chef run can be dynamically changed.
304+
305+
This recipe does not manage the `chef-client` service. It is assumed to have been set up and started from the `bootstrap_client` recipe above, or from OS / distribution packaging. The `chef-client` service should not be restarted as a result of `/etc/chef/client.rb` changing, as that can cause the current process running the client to be restarted, having unpredictable results.
267306

268307
default
269308
-------
270309

271-
There is no spoon.
310+
There is no spoon :-).
272311

273312
delete_validation
274313
-----------------
275314

276315
This is a standalone recipe that merely deletes the validation certificate (default `/etc/chef/validation.pem`). Use this if managing the client config file is not required in your environment.
277316

317+
Beware if using this on your Chef Server. First copy the validation.pem certificate file to another location, such as your knife configuration directory (`~/.chef`) or [Chef Repository](http://wiki.opscode.com/display/chef/Chef+Repository).
318+
278319
server
279320
------
280321

@@ -291,12 +332,14 @@ The following services are managed:
291332

292333
Changes to the `/etc/chef/server.rb` will trigger a restart of these services.
293334

294-
Since the Chef Server itself typically runs the CouchDB service for the data store, the recipe will do a compaction on the Chef database and all the views associated with the Chef Server. These compactions only occur if the database/view size is more than 100Mb. It will use the configured CouchDB URL, which is `http://localhost:5984` by default.
335+
Since the Chef Server itself typically runs the CouchDB service for the data store, the recipe will do a compaction on the Chef database and all the views associated with the Chef Server. These compactions only occur if the database/view size is more than 100Mb. It will use the configured CouchDB URL, which is `http://localhost:5984` by default. The actual value used for the CouchDB server is from the `Chef::Config[:couchdb_url]`, so this can be dynamically changed.
295336

296337
server_proxy
297338
------------
298339

299-
Sets up an Apache2 VirtualHost to proxy HTTPS for the Chef Server API and WebUI.
340+
This recipe sets up an Apache2 VirtualHost to proxy HTTPS for the Chef Server API and WebUI.
341+
342+
The API will be proxied on port 443. If the `chef-serer-webui` is installed, it will be proxied on port 444. The recipe dynamically creates the OpenSSL certificate based on the `chef.server_ssl_req` attribute. It uses some additional configuration for Apache to improve performance of the webui. The virtual host template is `chef_server.conf.erb`. The DocumentRoot setting is used for the WebUI, but not the API, and is set with the attribute `chef.doc_root`.
300343

301344
TEMPLATES
302345
=========

‎chef/attributes/default.rb‎

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
set_unless[:chef][:serve_path] = "/srv/chef"
3535
end
3636

37-
set_unless[:chef][:server_version] = "0.8.16"
38-
set_unless[:chef][:client_version] = "0.8.16"
37+
set_unless[:chef][:server_version] = node.chef_packages.chef[:version]
38+
set_unless[:chef][:client_version] = node.chef_packages.chef[:version]
3939
set_unless[:chef][:client_interval] = "1800"
4040
set_unless[:chef][:client_splay] = "20"
4141
set_unless[:chef][:log_dir] = "/var/log/chef"
@@ -44,17 +44,5 @@
4444
set_unless[:chef][:webui_enabled] = false
4545
set_unless[:chef][:validation_client_name] = "chef-validator"
4646

47-
case chef[:init_style]
48-
when "runit"
49-
set_unless[:chef][:client_log] = "STDOUT"
50-
set_unless[:chef][:indexer_log] = "STDOUT"
51-
set_unless[:chef][:server_log] = "STDOUT"
52-
else
53-
set_unless[:chef][:client_log] = "#{chef[:log_dir]}/client.log"
54-
set_unless[:chef][:indexer_log] = "#{chef[:log_dir]}/indexer.log"
55-
set_unless[:chef][:server_log] = "#{chef[:log_dir]}/server.log"
56-
end
57-
5847
set_unless[:chef][:server_fqdn] = node.has_key?(domain) ? "chef.#{domain}" : "chef"
59-
set_unless[:chef][:server_ssl_req] = "/C=US/ST=Several/L=Locality/O=Example/OU=Operations/" +
60-
"CN=#{chef[:server_fqdn]}/emailAddress=ops@#{chef[:server_fqdn]}"
48+
set_unless[:chef][:server_url] = "#{node.chef.url_type}://#{node.chef.server_fqdn}:#{node.chef.server_port}"

0 commit comments

Comments
 (0)