capistrano-rails-server 1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +171 -0
- data/capistrano-rails-server.gemspec +20 -0
- data/lib/capistrano-rails-server/recipes/base.rb +35 -0
- data/lib/capistrano-rails-server/recipes/check.rb +21 -0
- data/lib/capistrano-rails-server/recipes/common.rb +8 -0
- data/lib/capistrano-rails-server/recipes/key.rb +28 -0
- data/lib/capistrano-rails-server/recipes/nginx.rb +33 -0
- data/lib/capistrano-rails-server/recipes/postgresql.rb +65 -0
- data/lib/capistrano-rails-server/recipes/rbenv.rb +35 -0
- data/lib/capistrano-rails-server/recipes/templates/nginx_unicorn.erb +27 -0
- data/lib/capistrano-rails-server/recipes/templates/postgresql.yml.erb +8 -0
- data/lib/capistrano-rails-server/recipes/templates/unicorn.rb.erb +8 -0
- data/lib/capistrano-rails-server/recipes/templates/unicorn_init.erb +84 -0
- data/lib/capistrano-rails-server/recipes/unicorn.rb +34 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
N2Y1ODg0YWMzODY3MGVjMWNiODZmY2IzNWUyZjU5NDk4ODA2ZTk0NQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Yjg4M2U2M2U5YjcxYzlmYTljMGFiZGNhZWNlZjllNTA4NTI2YzdmYQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YjI3M2M0MjNmNWU2NDE1YmUwYjJkOGMyYWM4NTcwMTU5ZjkxZjU5NTkxNGI3
|
10
|
+
MmZmYWU5Mzk1M2FlMTQyOWUzYzM1YzJjOTNmODhiNzkyZjc4ZjA5YWE0MWRk
|
11
|
+
MmNkOGU0MTU2ZGY5Zjc5YWFmYmI3M2FmNTFlYmIwNDQyMTAxZmY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ODgxMzI1NmE3ZDViNzNkNzE3ZDIwYWJmZmI5Yzg5YWM3ZDgxZWM2NTAwODk0
|
14
|
+
NTRkNjU5NWRhZTQ3OTUwMGUzZWRmOTZmOWVmNTg5NTEyMWI5ZmZiNTQ4YWY3
|
15
|
+
YTMwOWZmMjMwODhiZjNjNTFhMGIxMzAyNmNiMTA3ODc4YTdhYjQ=
|
data/README.md
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
#capistrano-rails-server gem#
|
2
|
+
|
3
|
+
Capistrano-rails-server is collection of capistrano recipes for setting up production server for ROR. The current testing environment is Ubuntu 12.04LTS.
|
4
|
+
## Installation ##
|
5
|
+
Add these lines to your application's Gemfile:
|
6
|
+
|
7
|
+
gem 'capistrano'
|
8
|
+
gem 'capistrano-rails-server'
|
9
|
+
gem 'unicorn'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle install
|
14
|
+
|
15
|
+
## Using ##
|
16
|
+
|
17
|
+
### Prepare your app ###
|
18
|
+
Run `$ cap init` in your app folder (details [here](http://guides.beanstalkapp.com/deployments/deploy-with-capistrano.html)).
|
19
|
+
|
20
|
+
Than include recipes from this gem to your `deploy.conf`:
|
21
|
+
|
22
|
+
example `deploy.conf` file:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require "bundler/capistrano"
|
26
|
+
load "deploy/assets"
|
27
|
+
|
28
|
+
# uncomment this if you need non en-US locale for postgresql server
|
29
|
+
#set :postgresql_locale, "ru_RU"
|
30
|
+
#set :postgresql_rebuild, true
|
31
|
+
|
32
|
+
# uncomment this if you need another version of ruby or using another OS
|
33
|
+
#set_default :ruby_version, "2.0.0-p247"
|
34
|
+
#set_default :rbenv_bootstrap, "bootstrap-ubuntu-12-04"
|
35
|
+
|
36
|
+
set :application, "yourappuser"
|
37
|
+
|
38
|
+
server "yourapp.address", :app, :web, :db, :primary => true
|
39
|
+
|
40
|
+
set :user, "yourapp"
|
41
|
+
set :use_sudo, false
|
42
|
+
set :deploy_to, "/home/#{user}/apps/#{application}"
|
43
|
+
#set :deploy_via, :remote_cache
|
44
|
+
set :repository, "yourrepo"
|
45
|
+
set :branch, "master"
|
46
|
+
|
47
|
+
default_run_options[:pty] = true
|
48
|
+
ssh_options[:forward_agent] = true
|
49
|
+
|
50
|
+
after 'deploy:update_code', 'deploy:migrate'
|
51
|
+
set :keep_releases, 5
|
52
|
+
after 'deploy', 'deploy:cleanup'
|
53
|
+
|
54
|
+
# you can comment out any recipe if you don't need it
|
55
|
+
require "capistrano-rails-server/recipes/base"
|
56
|
+
require "capistrano-rails-server/recipes/nginx"
|
57
|
+
require "capistrano-rails-server/recipes/unicorn"
|
58
|
+
require "capistrano-rails-server/recipes/postgresql"
|
59
|
+
require "capistrano-rails-server/recipes/rbenv"
|
60
|
+
require "capistrano-rails-server/recipes/check"
|
61
|
+
# uncomment this if you need to generate deployment ssh key for private repository
|
62
|
+
# public key will be printed at the end of deploy:install task
|
63
|
+
#require "capistrano-rails-server/recipes/key"
|
64
|
+
|
65
|
+
```
|
66
|
+
### Prepare server (instructions for Ubuntu 12.04) ###
|
67
|
+
|
68
|
+
Create admin group:
|
69
|
+
|
70
|
+
# addgroup admin
|
71
|
+
|
72
|
+
Create user for deployment:
|
73
|
+
|
74
|
+
# adduser yourappuser --ingroup admin
|
75
|
+
|
76
|
+
(Optional) Edit `/etc/sudoers` file if you don't want to enter user's password several time during recipes running:
|
77
|
+
|
78
|
+
replace line
|
79
|
+
|
80
|
+
%admin ALL=(ALL) ALL
|
81
|
+
|
82
|
+
with
|
83
|
+
|
84
|
+
%admin ALL=(ALL) NOPASSWD:ALL
|
85
|
+
|
86
|
+
### Deploying ###
|
87
|
+
|
88
|
+
|
89
|
+
After that run command to install all software needed:
|
90
|
+
|
91
|
+
$ cap deploy:install
|
92
|
+
|
93
|
+
And configure it:
|
94
|
+
|
95
|
+
$ cap deploy:setup
|
96
|
+
|
97
|
+
|
98
|
+
Thats all, now you can deploy your app:
|
99
|
+
|
100
|
+
$ cap deploy
|
101
|
+
|
102
|
+
## Options ##
|
103
|
+
### Available cap tasks ###
|
104
|
+
`deploy:install` - install all software.
|
105
|
+
|
106
|
+
`deploy:setup` - configure all software.
|
107
|
+
|
108
|
+
`rbenv:install`
|
109
|
+
|
110
|
+
`nginx:install`
|
111
|
+
|
112
|
+
`nginx:setup`
|
113
|
+
|
114
|
+
`nginx:start`
|
115
|
+
|
116
|
+
`nginx:stop`
|
117
|
+
|
118
|
+
`nginx:restart`
|
119
|
+
|
120
|
+
`unicorn:setup`
|
121
|
+
|
122
|
+
`unicorn:start`
|
123
|
+
|
124
|
+
`unicorn:stop`
|
125
|
+
|
126
|
+
`unicorn:restart`
|
127
|
+
|
128
|
+
`postgresql:install`
|
129
|
+
|
130
|
+
`postgresql:setup`
|
131
|
+
|
132
|
+
`postgresql:create_database`
|
133
|
+
|
134
|
+
`postgresql:rebuild` - rebuild Postgresql cluster with given locale and encoding. WARNING! This task removes all existing databases.
|
135
|
+
|
136
|
+
`key:generate`
|
137
|
+
|
138
|
+
`key:show` - show generated deployment key.
|
139
|
+
|
140
|
+
`key:remove`
|
141
|
+
|
142
|
+
### Available options and defaults ###
|
143
|
+
You can overwrite any of these options in `deploy.conf` file.
|
144
|
+
|
145
|
+
`ruby_version`
|
146
|
+
|
147
|
+
`rbenv_bootstrap`
|
148
|
+
|
149
|
+
`postgresql_host`
|
150
|
+
|
151
|
+
`postgresql_user`
|
152
|
+
|
153
|
+
`postgresql_password`
|
154
|
+
|
155
|
+
`postgresql_database`
|
156
|
+
|
157
|
+
`postgresql_rebuild`
|
158
|
+
|
159
|
+
`postgresql_encoding` - useful only if postgresql_rebuild is true
|
160
|
+
|
161
|
+
`postgresql_locale` - useful only if postgresql_rebuild is true
|
162
|
+
|
163
|
+
`unicorn_user`
|
164
|
+
|
165
|
+
`unicorn_pid`
|
166
|
+
|
167
|
+
`unicorn_config`
|
168
|
+
|
169
|
+
`unicorn_log`
|
170
|
+
|
171
|
+
`unicorn_workers`
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'capistrano-rails-server'
|
7
|
+
s.version = '1.1'
|
8
|
+
s.date = '2013-07-04'
|
9
|
+
s.summary = "Capistrano recipes to setup Rbenv, Nginx, Unicorn and Postgresql production environment."
|
10
|
+
s.description =
|
11
|
+
"That gem includes capistrano recipes to install and configure ROR production development with Rbenv, Nginx, Unicorn and Postgresql."
|
12
|
+
s.authors = ["Drakula2k"]
|
13
|
+
s.email = 'drakula2k@gmail.com'
|
14
|
+
s.homepage = 'https://github.com/Drakula2k/capistrano-rails-server'
|
15
|
+
s.files = `git ls-files`.split($/)
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.add_dependency "capistrano"
|
18
|
+
s.add_development_dependency "rake"
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "capistrano-rails-server/recipes/common"
|
2
|
+
|
3
|
+
configuration = Capistrano::Configuration.respond_to?(:instance) ?
|
4
|
+
Capistrano::Configuration.instance(:must_exist) :
|
5
|
+
Capistrano.configuration(:must_exist)
|
6
|
+
|
7
|
+
configuration.load do
|
8
|
+
namespace :deploy do
|
9
|
+
desc "Install everything onto the server"
|
10
|
+
task :install do
|
11
|
+
run "#{sudo} apt-get -y update"
|
12
|
+
run "#{sudo} apt-get -y install python-software-properties software-properties-common"
|
13
|
+
end
|
14
|
+
|
15
|
+
# Overwrite with no sudo
|
16
|
+
desc <<-DESC
|
17
|
+
Prepares one or more servers for deployment. Before you can use any \
|
18
|
+
of the Capistrano deployment tasks with your project, you will need to \
|
19
|
+
make sure all of your servers have been prepared with `cap deploy:setup'. When \
|
20
|
+
you add a new server to your cluster, you can easily run the setup task \
|
21
|
+
on just that server by specifying the HOSTS environment variable:
|
22
|
+
|
23
|
+
$ cap HOSTS=new.server.com deploy:setup
|
24
|
+
|
25
|
+
It is safe to run this task on servers that have already been set up; it \
|
26
|
+
will not destroy any deployed revisions or data.
|
27
|
+
DESC
|
28
|
+
task :setup, :except => { :no_release => true } do
|
29
|
+
dirs = [deploy_to, releases_path, shared_path]
|
30
|
+
dirs += shared_children.map { |d| File.join(shared_path, d.split('/').last) }
|
31
|
+
run "mkdir -p #{dirs.join(' ')}"
|
32
|
+
run "chmod g+w #{dirs.join(' ')}" if fetch(:group_writable, true)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "capistrano-rails-server/recipes/common"
|
2
|
+
|
3
|
+
configuration = Capistrano::Configuration.respond_to?(:instance) ?
|
4
|
+
Capistrano::Configuration.instance(:must_exist) :
|
5
|
+
Capistrano.configuration(:must_exist)
|
6
|
+
|
7
|
+
configuration.load do
|
8
|
+
namespace :check do
|
9
|
+
desc "Make sure local git is in sync with remote."
|
10
|
+
task :revision, roles: :web do
|
11
|
+
unless `git rev-parse HEAD` == `git rev-parse origin/#{branch}`
|
12
|
+
puts "WARNING: HEAD is not the same as origin/#{branch}"
|
13
|
+
puts "Run `git push` to sync changes."
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
end
|
17
|
+
before "deploy", "check:revision"
|
18
|
+
before "deploy:migrations", "check:revision"
|
19
|
+
before "deploy:cold", "check:revision"
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "capistrano-rails-server/recipes/common"
|
2
|
+
|
3
|
+
configuration = Capistrano::Configuration.respond_to?(:instance) ?
|
4
|
+
Capistrano::Configuration.instance(:must_exist) :
|
5
|
+
Capistrano.configuration(:must_exist)
|
6
|
+
|
7
|
+
configuration.load do
|
8
|
+
namespace :key do
|
9
|
+
desc "Generate deployment key for repository"
|
10
|
+
task :generate, roles: :web do
|
11
|
+
run %Q(ssh-keygen -q -N "" -t rsa -C #{user}@#{application} -f ~/.ssh/id_rsa)
|
12
|
+
#run "ssh-add ~/.ssh/id_rsa"
|
13
|
+
end
|
14
|
+
after "deploy:install", "key:generate"
|
15
|
+
|
16
|
+
desc "Show public key"
|
17
|
+
task :show, roles: :web do
|
18
|
+
run "cat ~/.ssh/id_rsa.pub"
|
19
|
+
end
|
20
|
+
after "key:generate", "key:show"
|
21
|
+
|
22
|
+
desc "Remove key from server"
|
23
|
+
task :remove, roles: :web do
|
24
|
+
run "rm -rf ~/.ssh/id_rsa"
|
25
|
+
run "rm -rf ~/.ssh/id_rsa.pub"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "capistrano-rails-server/recipes/common"
|
2
|
+
|
3
|
+
configuration = Capistrano::Configuration.respond_to?(:instance) ?
|
4
|
+
Capistrano::Configuration.instance(:must_exist) :
|
5
|
+
Capistrano.configuration(:must_exist)
|
6
|
+
|
7
|
+
configuration.load do
|
8
|
+
namespace :nginx do
|
9
|
+
desc "Install latest stable release of nginx"
|
10
|
+
task :install, roles: :web do
|
11
|
+
run "#{sudo} add-apt-repository -y ppa:nginx/stable"
|
12
|
+
run "#{sudo} apt-get -y update"
|
13
|
+
run "#{sudo} apt-get -y install nginx"
|
14
|
+
end
|
15
|
+
after "deploy:install", "nginx:install"
|
16
|
+
|
17
|
+
desc "Setup nginx configuration for this application"
|
18
|
+
task :setup, roles: :web do
|
19
|
+
template "nginx_unicorn.erb", "/tmp/nginx_conf"
|
20
|
+
run "#{sudo} mv /tmp/nginx_conf /etc/nginx/sites-enabled/#{application}"
|
21
|
+
run "#{sudo} rm -f /etc/nginx/sites-enabled/default"
|
22
|
+
restart
|
23
|
+
end
|
24
|
+
after "deploy:setup", "nginx:setup"
|
25
|
+
|
26
|
+
%w[start stop restart].each do |command|
|
27
|
+
desc "#{command} nginx"
|
28
|
+
task command, roles: :web do
|
29
|
+
run "#{sudo} service nginx #{command}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "capistrano-rails-server/recipes/common"
|
2
|
+
|
3
|
+
configuration = Capistrano::Configuration.respond_to?(:instance) ?
|
4
|
+
Capistrano::Configuration.instance(:must_exist) :
|
5
|
+
Capistrano.configuration(:must_exist)
|
6
|
+
|
7
|
+
configuration.load do
|
8
|
+
set_default(:postgresql_host, "localhost")
|
9
|
+
set_default(:postgresql_user) { application }
|
10
|
+
set_default(:postgresql_password) { Capistrano::CLI.password_prompt "PostgreSQL Password: " }
|
11
|
+
set_default(:postgresql_database) { "#{application}_production" }
|
12
|
+
set_default(:postgresql_rebuild, false)
|
13
|
+
set_default(:postgresql_encoding, "UTF-8")
|
14
|
+
set_default(:postgresql_locale, "en_US")
|
15
|
+
|
16
|
+
namespace :postgresql do
|
17
|
+
desc "Install the latest stable release of PostgreSQL."
|
18
|
+
task :install, roles: :db, only: {primary: true} do
|
19
|
+
run "#{sudo} add-apt-repository -y ppa:pitti/postgresql"
|
20
|
+
run "#{sudo} apt-get -y update"
|
21
|
+
run "#{sudo} apt-get -y install postgresql libpq-dev"
|
22
|
+
end
|
23
|
+
after "deploy:install", "postgresql:install"
|
24
|
+
|
25
|
+
desc "Create a database for this application."
|
26
|
+
task :create_database, roles: :db, only: {primary: true} do
|
27
|
+
run %Q{#{sudo} -u postgres psql -c "create user #{postgresql_user} with password '#{postgresql_password}';"}
|
28
|
+
run %Q{#{sudo} -u postgres psql -c "create database #{postgresql_database} owner #{postgresql_user};"}
|
29
|
+
end
|
30
|
+
after "deploy:setup", "postgresql:create_database"
|
31
|
+
|
32
|
+
desc "Generate the database.yml configuration file."
|
33
|
+
task :setup, roles: :app do
|
34
|
+
run "mkdir -p #{shared_path}/config"
|
35
|
+
template "postgresql.yml.erb", "#{shared_path}/config/database.yml"
|
36
|
+
end
|
37
|
+
after "deploy:setup", "postgresql:setup"
|
38
|
+
|
39
|
+
desc "Symlink the database.yml file into latest release"
|
40
|
+
task :symlink, roles: :app do
|
41
|
+
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
|
42
|
+
end
|
43
|
+
after "deploy:finalize_update", "postgresql:symlink"
|
44
|
+
|
45
|
+
desc "Rebuild cluster with another encoding and locale. WARNING! This task will remove all databases."
|
46
|
+
task :rebuild, roles: :app do
|
47
|
+
answer =
|
48
|
+
Capistrano::CLI.ui.ask "This task will remove all existing DBs, run it only on fresh server installation!
|
49
|
+
Do you want to run this task? Otherwise this task will be skipped. (y/n):"
|
50
|
+
if %w(Y y yes).include? answer
|
51
|
+
run "#{sudo} locale-gen #{postgresql_locale}.#{postgresql_encoding}"
|
52
|
+
run "#{sudo} service postgresql stop"
|
53
|
+
run "#{sudo} pg_dropcluster --stop 9.1 main"
|
54
|
+
run "#{sudo} pg_createcluster --start --locale #{postgresql_locale}.#{postgresql_encoding} -e #{postgresql_encoding} 9.1 main"
|
55
|
+
else
|
56
|
+
Capistrano::CLI.ui.say "postgresql:rebuild task skipped."
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
if postgresql_rebuild
|
61
|
+
before "postgresql:create_database", "postgresql:rebuild"
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "capistrano-rails-server/recipes/common"
|
2
|
+
|
3
|
+
configuration = Capistrano::Configuration.respond_to?(:instance) ?
|
4
|
+
Capistrano::Configuration.instance(:must_exist) :
|
5
|
+
Capistrano.configuration(:must_exist)
|
6
|
+
|
7
|
+
configuration.load do
|
8
|
+
set_default :ruby_version, "2.0.0-p247"
|
9
|
+
set_default :rbenv_bootstrap, "bootstrap-ubuntu-12-04"
|
10
|
+
|
11
|
+
namespace :rbenv do
|
12
|
+
desc "Install rbenv, Ruby, and the Bundler gem"
|
13
|
+
task :install, roles: :app do
|
14
|
+
run "#{sudo} apt-get -y install curl git-core"
|
15
|
+
run "curl -L https://raw.github.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash"
|
16
|
+
bashrc = <<-BASHRC
|
17
|
+
if [ -d $HOME/.rbenv ]; then
|
18
|
+
export PATH="$HOME/.rbenv/bin:$PATH"
|
19
|
+
eval "$(rbenv init -)"
|
20
|
+
fi
|
21
|
+
BASHRC
|
22
|
+
put bashrc, "/tmp/rbenvrc"
|
23
|
+
run "cat /tmp/rbenvrc ~/.bashrc > ~/.bashrc.tmp"
|
24
|
+
run "mv ~/.bashrc.tmp ~/.bashrc"
|
25
|
+
run %q{export PATH="$HOME/.rbenv/bin:$PATH"}
|
26
|
+
run %q{eval "$(rbenv init -)"}
|
27
|
+
run "rbenv #{rbenv_bootstrap}"
|
28
|
+
run "rbenv install -f #{ruby_version}"
|
29
|
+
run "rbenv global #{ruby_version}"
|
30
|
+
run "gem install bundler --no-ri --no-rdoc"
|
31
|
+
run "rbenv rehash"
|
32
|
+
end
|
33
|
+
after "deploy:install", "rbenv:install"
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
upstream unicorn {
|
2
|
+
server unix:/tmp/unicorn.<%= application %>.sock fail_timeout=0;
|
3
|
+
}
|
4
|
+
|
5
|
+
server {
|
6
|
+
listen 80 default deferred;
|
7
|
+
# server_name example.com;
|
8
|
+
root <%= current_path %>/public;
|
9
|
+
|
10
|
+
location ^~ /assets/ {
|
11
|
+
gzip_static on;
|
12
|
+
expires max;
|
13
|
+
add_header Cache-Control public;
|
14
|
+
}
|
15
|
+
|
16
|
+
try_files $uri/index.html $uri @unicorn;
|
17
|
+
location @unicorn {
|
18
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
19
|
+
proxy_set_header Host $http_host;
|
20
|
+
proxy_redirect off;
|
21
|
+
proxy_pass http://unicorn;
|
22
|
+
}
|
23
|
+
|
24
|
+
error_page 500 502 503 504 /500.html;
|
25
|
+
client_max_body_size 4G;
|
26
|
+
keepalive_timeout 10;
|
27
|
+
}
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
### BEGIN INIT INFO
|
3
|
+
# Provides: unicorn
|
4
|
+
# Required-Start: $remote_fs $syslog
|
5
|
+
# Required-Stop: $remote_fs $syslog
|
6
|
+
# Default-Start: 2 3 4 5
|
7
|
+
# Default-Stop: 0 1 6
|
8
|
+
# Short-Description: Manage unicorn server
|
9
|
+
# Description: Start, stop, restart unicorn server for a specific application.
|
10
|
+
### END INIT INFO
|
11
|
+
set -e
|
12
|
+
|
13
|
+
# Feel free to change any of the following variables for your app:
|
14
|
+
TIMEOUT=${TIMEOUT-60}
|
15
|
+
APP_ROOT=<%= current_path %>
|
16
|
+
PID=<%= unicorn_pid %>
|
17
|
+
CMD="cd <%= current_path %>; bundle exec unicorn -D -c <%= unicorn_config %> -E production"
|
18
|
+
AS_USER=<%= unicorn_user %>
|
19
|
+
set -u
|
20
|
+
|
21
|
+
OLD_PIN="$PID.oldbin"
|
22
|
+
|
23
|
+
sig () {
|
24
|
+
test -s "$PID" && kill -$1 `cat $PID`
|
25
|
+
}
|
26
|
+
|
27
|
+
oldsig () {
|
28
|
+
test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
|
29
|
+
}
|
30
|
+
|
31
|
+
run () {
|
32
|
+
if [ "$(id -un)" = "$AS_USER" ]; then
|
33
|
+
eval $1
|
34
|
+
else
|
35
|
+
su -c "$1" - $AS_USER
|
36
|
+
fi
|
37
|
+
}
|
38
|
+
|
39
|
+
case "$1" in
|
40
|
+
start)
|
41
|
+
sig 0 && echo >&2 "Already running" && exit 0
|
42
|
+
run "$CMD"
|
43
|
+
;;
|
44
|
+
stop)
|
45
|
+
sig QUIT && exit 0
|
46
|
+
echo >&2 "Not running"
|
47
|
+
;;
|
48
|
+
force-stop)
|
49
|
+
sig TERM && exit 0
|
50
|
+
echo >&2 "Not running"
|
51
|
+
;;
|
52
|
+
restart|reload)
|
53
|
+
sig HUP && echo reloaded OK && exit 0
|
54
|
+
echo >&2 "Couldn't reload, starting '$CMD' instead"
|
55
|
+
run "$CMD"
|
56
|
+
;;
|
57
|
+
upgrade)
|
58
|
+
if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
|
59
|
+
then
|
60
|
+
n=$TIMEOUT
|
61
|
+
while test -s $OLD_PIN && test $n -ge 0
|
62
|
+
do
|
63
|
+
printf '.' && sleep 1 && n=$(( $n - 1 ))
|
64
|
+
done
|
65
|
+
echo
|
66
|
+
|
67
|
+
if test $n -lt 0 && test -s $OLD_PIN
|
68
|
+
then
|
69
|
+
echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
|
70
|
+
exit 1
|
71
|
+
fi
|
72
|
+
exit 0
|
73
|
+
fi
|
74
|
+
echo >&2 "Couldn't upgrade, starting '$CMD' instead"
|
75
|
+
run "$CMD"
|
76
|
+
;;
|
77
|
+
reopen-logs)
|
78
|
+
sig USR1
|
79
|
+
;;
|
80
|
+
*)
|
81
|
+
echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
|
82
|
+
exit 1
|
83
|
+
;;
|
84
|
+
esac
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "capistrano-rails-server/recipes/common"
|
2
|
+
|
3
|
+
configuration = Capistrano::Configuration.respond_to?(:instance) ?
|
4
|
+
Capistrano::Configuration.instance(:must_exist) :
|
5
|
+
Capistrano.configuration(:must_exist)
|
6
|
+
|
7
|
+
configuration.load do
|
8
|
+
set_default(:unicorn_user) { user }
|
9
|
+
set_default(:unicorn_pid) { "#{current_path}/tmp/pids/unicorn.pid" }
|
10
|
+
set_default(:unicorn_config) { "#{shared_path}/config/unicorn.rb" }
|
11
|
+
set_default(:unicorn_log) { "#{shared_path}/log/unicorn.log" }
|
12
|
+
set_default(:unicorn_workers, 2)
|
13
|
+
|
14
|
+
namespace :unicorn do
|
15
|
+
desc "Setup Unicorn initializer and app configuration"
|
16
|
+
task :setup, roles: :app do
|
17
|
+
run "mkdir -p #{shared_path}/config"
|
18
|
+
template "unicorn.rb.erb", unicorn_config
|
19
|
+
template "unicorn_init.erb", "/tmp/unicorn_init"
|
20
|
+
run "chmod +x /tmp/unicorn_init"
|
21
|
+
run "#{sudo} mv /tmp/unicorn_init /etc/init.d/unicorn_#{application}"
|
22
|
+
run "#{sudo} update-rc.d -f unicorn_#{application} defaults"
|
23
|
+
end
|
24
|
+
after "deploy:setup", "unicorn:setup"
|
25
|
+
|
26
|
+
%w[start stop restart].each do |command|
|
27
|
+
desc "#{command} unicorn"
|
28
|
+
task command, roles: :app do
|
29
|
+
run "service unicorn_#{application} #{command}"
|
30
|
+
end
|
31
|
+
after "deploy:#{command}", "unicorn:#{command}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-rails-server
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Drakula2k
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capistrano
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: That gem includes capistrano recipes to install and configure ROR production
|
42
|
+
development with Rbenv, Nginx, Unicorn and Postgresql.
|
43
|
+
email: drakula2k@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- README.md
|
49
|
+
- capistrano-rails-server.gemspec
|
50
|
+
- lib/capistrano-rails-server/recipes/base.rb
|
51
|
+
- lib/capistrano-rails-server/recipes/check.rb
|
52
|
+
- lib/capistrano-rails-server/recipes/common.rb
|
53
|
+
- lib/capistrano-rails-server/recipes/key.rb
|
54
|
+
- lib/capistrano-rails-server/recipes/nginx.rb
|
55
|
+
- lib/capistrano-rails-server/recipes/postgresql.rb
|
56
|
+
- lib/capistrano-rails-server/recipes/rbenv.rb
|
57
|
+
- lib/capistrano-rails-server/recipes/templates/nginx_unicorn.erb
|
58
|
+
- lib/capistrano-rails-server/recipes/templates/postgresql.yml.erb
|
59
|
+
- lib/capistrano-rails-server/recipes/templates/unicorn.rb.erb
|
60
|
+
- lib/capistrano-rails-server/recipes/templates/unicorn_init.erb
|
61
|
+
- lib/capistrano-rails-server/recipes/unicorn.rb
|
62
|
+
homepage: https://github.com/Drakula2k/capistrano-rails-server
|
63
|
+
licenses: []
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.0.3
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Capistrano recipes to setup Rbenv, Nginx, Unicorn and Postgresql production
|
85
|
+
environment.
|
86
|
+
test_files: []
|