Setup a Rack-based application server to run Unicorn & Passenger apps.
It performs the following tasks when setup the server:
- setup a ruby version manager (now using
rbenv
). - setup
nginx
as front-end server. - setup
runit
service. - setup Unicorn apps (if any).
- setup Passenger apps (if any).
To install with Berkshelf, add this into Berksfile
:
cookbook 'cookbook_rackbox'
And overwrite attributes to customize the cookbook.
See also teohm/kitchen-sample for cookbook_rackbox
usage example with chef-solo.
You should specify the ruby versions to be installed:
node["cookbook_rackbox"]["ruby"]["versions"]
(default:["1.9.3-p385"]
) - ruby versions to be installed.node["cookbook_rackbox"]["ruby"]["global_version"]
(default:"1.9.3-p385"
) - set the system-wide ruby version.
To setup unicorn apps, provide a list of unicorn app entries:
-
node["cookbook_rackbox"]["apps"]["unicorn"]
(default:[]
)# Example: node["cookbook_rackbox"]["apps"]["unicorn"] = [ { "appname" => "app1", # app name "hostname" => "app1.test.com" # domain name }, { "appname" => "app2", # app name "hostname" => "app2.test.com", # domain name "nginx_config" => { # overwrite default config: ... # node["cookbook_rackbox"]["default_config"]["nginx"] }, "runit_config" => { # overwrite default config: "rack_env" => "staging" # node["cookbook_rackbox"]["default_config"]["unicorn_runit"] } } ]
To setup passenger apps, provide a list of passenger app entries:
-
node["cookbook_rackbox"]["apps"]["passenger"]
(default:[]
)# Example: node["cookbook_rackbox"]["apps"]["passenger"] = [ { "appname" => "app3", # app name "hostname" => "app3.test.com" # domain name }, { "appname" => "app4", # app name "hostname" => "app4.test.com", # domain name "nginx_config" => { # overwrite default config: ... # node["cookbook_rackbox"]["default_config"]["nginx"] }, "runit_config" => { # overwrite default config: "rack_env" => "staging" # node["cookbook_rackbox"]["default_config"]["passenger_runit"] } } ]
You may change the default config settings:
- nginx:
node["cookbook_rackbox"]["default_config"]["nginx"]["template_name"]
(default:"nginx_vhost.conf.erb"
) - nginx vhost/site config template.node["cookbook_rackbox"]["default_config"]["nginx"]["template_cookbook"]
(default:"cookbook_rackbox"
) - cookbook containing the nginx vhost/site config template.node["cookbook_rackbox"]["default_config"]["nginx"]["listen_port"]
(default:"80"
) - nginx vhost/site listen port.node["cookbook_rackbox"]["upstream_start_port"]["unicorn"]
(default:10001
) - start number for unicorn app listen port.node["cookbook_rackbox"]["upstream_start_port"]["passenger"]
(default:20001
) - start number for passenger app listen port.
- unicorn:
node["cookbook_rackbox"]["default_config"]["unicorn"]["listen_port_options"]
(default:{ :tcp_nodelay => true, :backlog => 100 }
) - unicorn listen port options.node["cookbook_rackbox"]["default_config"]["unicorn"]["worker_timeout"]
(default:60
) - unicorn worker timeout.node["cookbook_rackbox"]["default_config"]["unicorn"]["preload_app"]
(default:false
) - unicorn preload app flag.node["cookbook_rackbox"]["default_config"]["unicorn"]["worker_processes"]
(default:[node[:cpu][:total].to_i * 4, 8].min
) - total unicorn worker.node["cookbook_rackbox"]["default_config"]["unicorn"]["before_fork"]
(default:'sleep 1'
) - unicorn before_fork handler.
- unicorn_runit:
node["cookbook_rackbox"]["default_config"]["unicorn_runit"]["template_name"]
(default:"unicorn"
) - name to lookup unicorn runit templates (templates:"sv-#{template_name}-run.erb"
,"sv-#{template_name}-log-run.erb
).node["cookbook_rackbox"]["default_config"]["unicorn_runit"]["template_cookbook"]
(default:"cookbook_rackbox"
) - cookbook containing the templates.node["cookbook_rackbox"]["default_config"]["unicorn_runit"]["rack_env"]
(default:"production"
) - default RACK_ENV to run a unicorn app.
- passenger_runit:
node["cookbook_rackbox"]["default_config"]["passenger_runit"]["template_name"]
(default:"passenger"
) - name to lookup passenger runit templates (templates:"sv-#{template_name}-run.erb"
,"sv-#{template_name}-log-run.erb
).node["cookbook_rackbox"]["default_config"]["passenger_runit"]["template_cookbook"]
(default:"cookbook_rackbox"
) - cookbook containing the templates.node["cookbook_rackbox"]["default_config"]["passenger_runit"]["rack_env"]
(default:"production"
) - default RACK_ENV to run a passenger app.node["cookbook_rackbox"]["default_config"]["passenger_runit"]["max_pool_size"]
(default:6
) - passenger max pool size.node["cookbook_rackbox"]["default_config"]["passenger_runit"]["min_instances"]
(default:1
) - passenger min instance.node["cookbook_rackbox"]["default_config"]["passenger_runit"]["spawn_method"]
(default:"smart-lv2"
) - passenger spawn method.node["cookbook_rackbox"]["default_config"]["passenger_runit"]["host"]
(default:"localhost"
) - passenger host.
cookbook_rackbox::default
- run all recipes.cookbook_rackbox::ruby
- setup a ruby version managerrbenv
.cookbook_rackbox::nginx
- setupnginx
as front-end server.cookbook_rackbox::unicorn
- setupunicorn
apps, if any.cookbook_rackbox::passenger
- setuppassenger
apps, if any.
ubuntu
- tested on Ubuntu 12.10debian
- should work
Pull requests, issue and test reports are welcomed to better support your platform.
- Depends on these cookbooks:
- appbox
- rbenv
- nginx
- unicorn (>= 1.2.2)
- runit (>= 1.1.2)
- Author:: Huiming Teo [email protected]
Copyright 2013, Huiming Teo
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.