capistrano3-unicorn-nginx 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/Rakefile +2 -0
- data/capistrano3-unicorn-nginx.gemspec +29 -0
- data/lib/capistrano3-unicorn-nginx.rb +0 -0
- data/lib/capistrano3/tasks/unicorn.rake +135 -0
- data/lib/capistrano3/unicorn_nginx.rb +1 -0
- data/lib/capistrano3/unicorn_nginx/helpers.rb +55 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d55dee8485c471078acbb4146442732922fe01f7
|
4
|
+
data.tar.gz: 71e2d5d0f0342286caa5ac9e87d44f7772260aaa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 544c89dbb5260b6b7c20850e36b785e337764e41344de731d73c082d47b02be4812e94d53024aef68f8b7594e019fd0907272f3c5dd1bd8898bf2bbf0df1fa17
|
7
|
+
data.tar.gz: 4b6de54167fdba5dd50fbe1ab2c023ce62fe634c9ffed4645cb0a37e97dce54f9be625b24447dce4a0a925a43b12b167d0bcfadb589f4f7ca37584189b7881c9
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
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 = 'capistrano3-unicorn-nginx'
|
7
|
+
s.version = '0.0.1'
|
8
|
+
s.date = '2019-02-01'
|
9
|
+
s.summary = "Capistrano tasks for automatic and sensible unicorn configuration"
|
10
|
+
s.description = <<-EOF.gsub(/^\s+/, '')
|
11
|
+
Capistrano tasks for automatic and sensible unicorn configuration
|
12
|
+
Work *only* with Capistrano 3+
|
13
|
+
Enable Zero downtime deployments of rails application.
|
14
|
+
Support for Ubuntu server and Centos, EC2... server same fedora, .
|
15
|
+
This gem customize from https://github.com/bruno-/capistrano-unicorn-nginx
|
16
|
+
EOF
|
17
|
+
s.authors = ["truongkma"]
|
18
|
+
s.email = 'nd.truong1902@gmail.com'
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.require_paths = ['lib']
|
21
|
+
s.homepage = 'https://github.com/truongkma/capistrano3-unicorn-nginx'
|
22
|
+
s.license = 'MIT'
|
23
|
+
|
24
|
+
s.add_runtime_dependency 'capistrano', '~> 3.1'
|
25
|
+
s.add_runtime_dependency 'sshkit', '~> 1.2'
|
26
|
+
|
27
|
+
s.add_development_dependency 'rake', '~> 0'
|
28
|
+
end
|
29
|
+
|
File without changes
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'capistrano3/unicorn_nginx/helpers'
|
2
|
+
include Capistrano3::UnicornNginx::Helpers
|
3
|
+
|
4
|
+
namespace :load do
|
5
|
+
task :defaults do
|
6
|
+
set :unicorn_service, -> { "unicorn_#{fetch(:application)}" }
|
7
|
+
set :user_home_path, -> { "/home/#{fetch(:user)}" }
|
8
|
+
set :unicorn_config_path, -> { unicorn_config_path }
|
9
|
+
set :unicorn_pid_path, -> { unicorn_pid_path }
|
10
|
+
set :unicorn_sock_path, -> { unicorn_sock_path }
|
11
|
+
set :unicorn_stdout_path, -> { unicorn_log_file }
|
12
|
+
set :unicorn_stderr_path, -> { unicorn_error_log_file }
|
13
|
+
set :unicorn_roles, -> { :app }
|
14
|
+
set :unicorn_restart_sleep_time, 3
|
15
|
+
set :unicorn_options, -> { '' }
|
16
|
+
set :unicorn_env, -> { fetch(:rails_env) || 'deployment' }
|
17
|
+
set :ruby_version, -> { fetch(:rvm_ruby_version) || fetch(:rbenv_ruby) }
|
18
|
+
set :unicorn_worker_processes, 2
|
19
|
+
set :unicorn_timeout, 30
|
20
|
+
|
21
|
+
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
namespace :unicorn do
|
26
|
+
desc "Start Unicorn"
|
27
|
+
task :start do
|
28
|
+
on roles(fetch(:unicorn_roles)) do
|
29
|
+
within current_path do
|
30
|
+
if test("[ -e #{fetch(:unicorn_pid_path)} ] && kill -0 #{pid}")
|
31
|
+
info "unicorn is running..."
|
32
|
+
else
|
33
|
+
with rails_env: fetch(:rails_env) do
|
34
|
+
execute :bundle, "exec unicorn", "-c", fetch(:unicorn_config_path), "-E", fetch(:unicorn_env), "-D", fetch(:unicorn_options)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Stop Unicorn (QUIT)"
|
42
|
+
task :stop do
|
43
|
+
on roles(fetch(:unicorn_roles)) do
|
44
|
+
within current_path do
|
45
|
+
if test("[ -e #{fetch(:unicorn_pid_path)} ]")
|
46
|
+
if test("kill -0 #{pid}")
|
47
|
+
info "stopping unicorn..."
|
48
|
+
execute :kill, "-s QUIT", pid
|
49
|
+
else
|
50
|
+
info "cleaning up dead unicorn pid..."
|
51
|
+
execute :rm, fetch(:unicorn_pid_path)
|
52
|
+
end
|
53
|
+
else
|
54
|
+
info "unicorn is not running..."
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
desc "Reload Unicorn (HUP); use this when preload_app: false"
|
61
|
+
task :reload do
|
62
|
+
invoke "unicorn:start"
|
63
|
+
on roles(fetch(:unicorn_roles)) do
|
64
|
+
within current_path do
|
65
|
+
info "reloading..."
|
66
|
+
execute :kill, "-s HUP", pid
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
desc "Restart Unicorn (USR2); use this when preload_app: true"
|
72
|
+
task :restart do
|
73
|
+
invoke "unicorn:start"
|
74
|
+
on roles(fetch(:unicorn_roles)) do
|
75
|
+
within current_path do
|
76
|
+
info "unicorn restarting..."
|
77
|
+
execute :kill, "-s USR2", pid
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
desc "Duplicate Unicorn; alias of unicorn:restart"
|
83
|
+
task :duplicate do
|
84
|
+
invoke "unicorn:restart"
|
85
|
+
end
|
86
|
+
|
87
|
+
desc "Legacy Restart (USR2 + QUIT); use this when preload_app: true and oldbin pid needs cleanup"
|
88
|
+
task :legacy_restart do
|
89
|
+
invoke "unicorn:restart"
|
90
|
+
on roles(fetch(:unicorn_roles)) do
|
91
|
+
within current_path do
|
92
|
+
execute :sleep, fetch(:unicorn_restart_sleep_time)
|
93
|
+
if test("[ -e #{fetch(:unicorn_pid_path)}.oldbin ]")
|
94
|
+
execute :kill, "-s QUIT", pid_oldbin
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
desc "Add a worker (TTIN)"
|
101
|
+
task :add_worker do
|
102
|
+
on roles(fetch(:unicorn_roles)) do
|
103
|
+
within current_path do
|
104
|
+
info "adding worker"
|
105
|
+
execute :kill, "-s TTIN", pid
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
desc "Remove a worker (TTOU)"
|
111
|
+
task :remove_worker do
|
112
|
+
on roles(fetch(:unicorn_roles)) do
|
113
|
+
within current_path do
|
114
|
+
info "removing worker"
|
115
|
+
execute :kill, "-s TTOU", pid
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
desc "Unicorn generate config file"
|
121
|
+
task :init_config do
|
122
|
+
on roles(fetch(:unicorn_roles)) do
|
123
|
+
execute(:mkdir, '-pv', File.dirname(fetch(:unicorn_config_path))) unless file_exists?(fetch(:unicorn_config_file))
|
124
|
+
upload! template('unicorn.rb.erb'), fetch(:unicorn_config_path)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def pid
|
130
|
+
"`cat #{fetch(:unicorn_pid_path)}`"
|
131
|
+
end
|
132
|
+
|
133
|
+
def pid_oldbin
|
134
|
+
"`cat #{fetch(:unicorn_pid_path)}.oldbin`"
|
135
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path("../tasks/unicorn.rake", __FILE__)
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "erb"
|
2
|
+
|
3
|
+
module Capistrano3
|
4
|
+
module UnicornNginx
|
5
|
+
module Helpers
|
6
|
+
def sudo_upload!(from, to)
|
7
|
+
filename = File.basename(to)
|
8
|
+
to_dir = File.dirname(to)
|
9
|
+
tmp_file = "/tmp/#{filename}"
|
10
|
+
upload! from, tmp_file
|
11
|
+
sudo :mv, tmp_file, to_dir
|
12
|
+
end
|
13
|
+
|
14
|
+
def file_exists?(path)
|
15
|
+
test "[ -e #{path} ]"
|
16
|
+
end
|
17
|
+
|
18
|
+
def deploy_user
|
19
|
+
capture :id, '-un'
|
20
|
+
end
|
21
|
+
|
22
|
+
def os_is_ubuntu?
|
23
|
+
capture(:cat, "/etc/*-release").include? "ubuntu"
|
24
|
+
end
|
25
|
+
|
26
|
+
def nginx_config_file
|
27
|
+
if os_is_ubuntu?
|
28
|
+
"/etc/nginx/sites-available/#{fetch(:nginx_config_name)}.conf"
|
29
|
+
else
|
30
|
+
"/etc/nginx/conf.d/#{fetch(:nginx_config_name)}.conf"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def unicorn_sock_path
|
35
|
+
shared_path.join("tmp", "unicorn.sock")
|
36
|
+
end
|
37
|
+
|
38
|
+
def unicorn_config_path
|
39
|
+
shared_path.join("config", "unicorn.rb")
|
40
|
+
end
|
41
|
+
|
42
|
+
def unicorn_pid_path
|
43
|
+
shared_path.join("tmp", "pids", "unicorn.pid")
|
44
|
+
end
|
45
|
+
|
46
|
+
def unicorn_error_log_file
|
47
|
+
shared_path.join("log", "unicorn.stderr.log")
|
48
|
+
end
|
49
|
+
|
50
|
+
def unicorn_log_file
|
51
|
+
shared_path.join("log", "unicorn.stdout.log")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano3-unicorn-nginx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- truongkma
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-01 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: '3.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sshkit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: |
|
56
|
+
Capistrano tasks for automatic and sensible unicorn configuration
|
57
|
+
Work *only* with Capistrano 3+
|
58
|
+
Enable Zero downtime deployments of rails application.
|
59
|
+
Support for Ubuntu server and Centos, EC2... server same fedora, .
|
60
|
+
This gem customize from https://github.com/bruno-/capistrano-unicorn-nginx
|
61
|
+
email: nd.truong1902@gmail.com
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- Gemfile
|
67
|
+
- Rakefile
|
68
|
+
- capistrano3-unicorn-nginx.gemspec
|
69
|
+
- lib/capistrano3-unicorn-nginx.rb
|
70
|
+
- lib/capistrano3/tasks/unicorn.rake
|
71
|
+
- lib/capistrano3/unicorn_nginx.rb
|
72
|
+
- lib/capistrano3/unicorn_nginx/helpers.rb
|
73
|
+
homepage: https://github.com/truongkma/capistrano3-unicorn-nginx
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.6.14
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Capistrano tasks for automatic and sensible unicorn configuration
|
97
|
+
test_files: []
|