Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# Description

This cookbook is designed to be able to run [Errbit](http://github.com/errbit/errbit).
Its github is at [chef-errbit](https://github.com/millisami/chef-errbit)
Its github is at [chef-errbit](https://github.com/klamontagne/chef-errbit)

# Requirements

Developed using chef 10.14.0 and it should work with higher versions. But not tested against chef 11 family.

The following Opscode cookbooks are dependencies:

* mongodb
* git
* unicorn
* apt
* nginx

You also need a MongoDB installation, such as with the [mongodb cookbook](https://github.com/edelight/chef-mongodb).

If you have other installations of rbenv on the node, you need to edit the node's user_installs as described in [chef-rbenv's documentation](https://github.com/fnichol/chef-rbenv#-rbenv-installed-for-a-specific-user-with-rubies).

# Usage

Just to install the Errbit app, include the following in your wrapper cookbook's recipe
Expand Down
1 change: 0 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ Vagrant.configure("2") do |config|
}

chef.run_list = [
'recipe[errbit::install_ruby]',
'recipe[nginx]',
'recipe[errbit::default]',
'recipe[errbit::bootstrap]'
Expand Down
18 changes: 16 additions & 2 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@
# All rights reserved - Do Not Redistribute
#



default['errbit']['name'] = "errbit"
default['errbit']['user'] = "deployer"
default['errbit']['password'] = "$1$qqO27xay$dtmwY9NMmJiSa47xhUZm0." #errbit
default['errbit']['user'] = "errbit"
default['errbit']['group'] = node['errbit']['user']
default['errbit']['deploy_to'] = "/home/#{default['errbit']['user']}/#{node['errbit']['name']}"
default['errbit']['repo_url'] = "git://github.com/errbit/errbit.git"
default['errbit']['revision'] = "master"
default['errbit']['environment'] = "production"

# Local ruby to install via rbenv
default['errbit']['install_ruby'] = "1.9.3-p429"
default['rbenv']['user_installs'] = [{ 'user' => default['errbit']['user'] }]


# errbit config.yml
default['errbit']['config']['host'] = "errbit.example.com"
default['errbit']['config']['enforce_ssl'] = false
Expand Down Expand Up @@ -43,6 +49,14 @@

# app server (Optional: More info in README)
default['errbit']['server'] = "unicorn" # or use others like puma
default[:errbit][:unicorn][:worker_timeout] = 60
default[:errbit][:unicorn][:worker_processes] = 2 #[node[:cpu][:total].to_i * 4, 8].min
default[:errbit][:unicorn][:preload_app] = false
default[:errbit][:unicorn][:tcp_nodelay] = true
default[:errbit][:unicorn][:backlog] = 100
default[:errbit][:unicorn][:tcp_nopush] = true
default[:errbit][:unicorn][:tries] = 3


default['errbit']['secret_token'] = 'b9e131c733a2672c79af5699f26e0bc5fba23a40ec51d76c9271c00097f35aa4c0993e1150f08048f0b66bd141cbcb58ab28814e35eb281c3cb2374aac160203'

7 changes: 4 additions & 3 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
"ubuntu": ">= 0.0.0"
},
"dependencies": {
"mongodb": ">= 0.0.0",
"git": ">= 0.0.0",
"unicorn": ">= 0.0.0",
"ruby_build": ">= 0.0.0",
"rbenv": ">= 0.0.0",
"apt": ">= 0.0.0",
"nginx": ">= 0.0.0",
"build-essential": ">= 0.0.0"
},
"recommendations": {
"mongodb": ">= 0.0.0"
},
"suggestions": {
},
Expand All @@ -33,4 +34,4 @@
"recipes": {
},
"version": "0.4.0"
}
}
6 changes: 4 additions & 2 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.4.0"

depends "mongodb"
depends "git"
depends "unicorn"
depends "ruby_build"
depends "rbenv"
depends "apt"
depends "nginx"
depends "build-essential"

recommends "mongodb"

supports "ubuntu"
21 changes: 0 additions & 21 deletions recipes/install_ruby.rb

This file was deleted.

52 changes: 29 additions & 23 deletions recipes/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,54 @@
# limitations under the License.
#

include_recipe "mongodb::10gen_repo"

node.set['build_essential']['compiletime'] = true
include_recipe "build-essential"

include_recipe "git"
gem_package "bundler"
include_recipe "nginx"

group node['errbit']['group']

user node['errbit']['user'] do
action :create
comment "Deployer user"
comment "Errbit user"
gid node['errbit']['group']
shell "/bin/bash"
home "/home/#{node['errbit']['user']}"
password node['errbit']['password']
supports :manage_home => true
system true
system false
end

# Exporting the SECRET_TOKEN env var
secret_token = rand(8**256).to_s(36).ljust(8,'a')[0..150]
# execute "set SECRET_TOKEN var" do
# command "echo 'export SECRET_TOKEN=#{secret_token}' >> ~/.bash_profile"
# not_if "grep SECRET_TOKEN ~/.bash_profile"
# end
file "/etc/profile.d/errbit_env.sh" do
mode "0644"
action :create_if_missing
content "export SECRET_TOKEN=#{secret_token}\nexport RAILS_ENV=production\nexport RACK_ENV=production\n"
execute "set SECRET_TOKEN var" do
user node['errbit']['user']
command "echo 'export SECRET_TOKEN=#{secret_token}' >> /home/#{node['errbit']['user']}/.bash_profile"
not_if "grep SECRET_TOKEN /home/#{node['errbit']['user']}/.bash_profile"
end

# execute "set RAILS_ENV var" do
# command "echo 'export RAILS_ENV=production' >> ~/.bash_profile"
# not_if "grep RAILS_ENV ~/.bash_profile"
# end
# setup rbenv (after git user setup)
%w{ ruby_build rbenv::user_install }.each do |requirement|
include_recipe requirement
end

# execute "set RACK_ENV var" do
# command "echo 'export RACK_ENV=production' >> ~/.bash_profile"
# not_if "grep RACK_ENV ~/.bash_profile"
# end
# Install appropriate Ruby with rbenv
rbenv_ruby node['errbit']['install_ruby'] do
action :install
user node['errbit']['user']
end

# Set as the rbenv default ruby
rbenv_global node['errbit']['install_ruby'] do
user node['errbit']['user']
end

# Install required Ruby Gems(via rbenv)
rbenv_gem "bundler" do
action :install
user node['errbit']['user']
rbenv_version node['errbit']['install_ruby']
end

execute "update sources list" do
command "apt-get update"
Expand All @@ -75,7 +82,6 @@
directory node['errbit']['deploy_to'] do
owner node['errbit']['user']
group node['errbit']['group']
mode 00755
action :create
recursive true
end
Expand Down
30 changes: 15 additions & 15 deletions recipes/unicorn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,26 @@
# limitations under the License.
#

include_recipe 'unicorn'

node.default[:unicorn][:worker_timeout] = 60
node.default[:unicorn][:worker_processes] = 2 #[node[:cpu][:total].to_i * 4, 8].min
node.default[:unicorn][:preload_app] = false
node.default[:unicorn][:tcp_nodelay] = true
node.default[:unicorn][:backlog] = 100
node.default[:unicorn][:tcp_nopush] = true
node.default[:unicorn][:tries] = 3
# node.default[:unicorn][:delay] = 100

Chef::Log.info "-" * 70
Chef::Log.info "Unicorn Config"

template "#{node['errbit']['deploy_to']}/shared/config/unicorn.conf" do
source "unicorn.conf.erb"
template "#{node['errbit']['deploy_to']}/shared/config/unicorn.rb" do
source "unicorn.rb.erb"
owner node['errbit']['user']
group node['errbit']['group']
mode 00644
end

template "/etc/init.d/unicorn_#{node['errbit']['name']}" do
source "unicorn.service.erb"
source "unicorn.init.erb"
owner "root"
group "root"
mode 00755
variables(
:user => node['errbit']['user'],
:deploy_to => node['errbit']['deploy_to'],
:env => node['errbit']['environment']
)
end

service "unicorn_#{node['errbit']['name']}" do
Expand All @@ -59,5 +53,11 @@

# Restarting the unicorn
service "unicorn_#{node['errbit']['name']}" do
action :restart
action :nothing
subscribes :restart, "template[#{node['errbit']['deploy_to']}/shared/config/config.yml]"
subscribes :restart, "template[/etc/init.d/unicorn_#{node['errbit']['name']}]"
subscribes :restart, "template[#{node['errbit']['deploy_to']}/shared/config/unicorn.rb]"
subscribes :restart, "template[#{node['errbit']['deploy_to']}/shared/config/config.yml]"
subscribes :restart, "template[#{node['errbit']['deploy_to']}/shared/config/mongoid.yml]"
subscribes :restart, "deploy_revision[#{node['errbit']['deploy_to']}]"
end
Loading