capistrano-sneakers 0.0.1 → 0.1.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 +5 -13
- data/CHANGELOG.md +15 -0
- data/README.md +21 -11
- data/capistrano-sneakers.gemspec +10 -6
- data/lib/capistrano/sneakers/monit.rb +2 -0
- data/lib/capistrano/sneakers/version.rb +1 -1
- data/lib/capistrano/sneakers.rb +1 -11
- data/lib/capistrano/tasks/monit.rake +108 -0
- data/lib/capistrano/tasks/sneakers.rake +225 -0
- data/lib/generators/capistrano/sneakers/monit/template_generator.rb +24 -0
- data/lib/generators/capistrano/sneakers/monit/templates/sneakers_monit.conf.erb +7 -0
- metadata +54 -20
- data/lib/capistrano/tasks/sneakers.rb +0 -242
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
YjhjNDI0MjIyOWJiZWYzOTU4YjcyOTRmOTVkZDc0NWU5YWE5NGMxMg==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2f27762c256ad0cf936ee3b7b9f8d164fa902030
|
4
|
+
data.tar.gz: fa03efb4683745483ce07a6ecb3cd74de14965f6
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZTIxNjJjNjQxZjE5MWE5MDVlNDE0NWQ2ZGM4ZmZkODdmNGJjM2EzYjU3OGVm
|
11
|
-
NWI3OTRmMTdlMTM1ZTM5ZDdmNWU2NjViZWEwNTk4OTljZDNkMTY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZWY2ZThlNDY0ZjdhMmY5ZmQ5ODUwZDJkNzdmNjNkODI4N2Q1Yzc2OGJhZWFj
|
14
|
-
YTM4ZTIxOGI2M2U3NTUzMTBhNjBiYTRkN2UzMzk0NjMzZjkzODI5MzkzN2Iw
|
15
|
-
ODU2MjVlMTNkMjI4NThiMDAzYTQzOGIyZjA5Yzg2ZGZiMjg0Njc=
|
6
|
+
metadata.gz: 9c880d4f8aab9f96aaea8f4e505c8d04d1d684b5547005406a86e885f207b2a02e80101062af5452e116d4fed824b64dbad8e32f00417653d9410565d6e9774e
|
7
|
+
data.tar.gz: cde49c7a7a6dceea52bad443b22dceb0dd15e6fa202aec60944de22380ac1a7424b06db46fffb2558d365eb0272fd7a9b7e870ff1c107efbaa19fee9d522efdd
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.1.1
|
4
|
+
- GemFury handover @inventionLabsSydney
|
5
|
+
- Version bump for gemfury @inventionLabsSydney
|
6
|
+
|
7
|
+
## 0.1.0
|
8
|
+
|
9
|
+
- Mimicry capistrano-sidekiq @Tensho
|
10
|
+
- Add sneakers_monit_templates_path @Tensho
|
11
|
+
|
12
|
+
## 0.0.2
|
13
|
+
|
14
|
+
- Use new capistrano DSL for reenable tasks @Tensho
|
15
|
+
- Make sneakers:stop task perpetually callable @Tensho
|
data/README.md
CHANGED
@@ -1,39 +1,49 @@
|
|
1
1
|
# Capistrano::Sneakers
|
2
2
|
|
3
|
-
[Sneakers](https://github.com/jondot/sneakers) integration
|
3
|
+
[Sneakers](https://github.com/jondot/sneakers) integration **only** for Capistrano 3
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
|
10
|
-
gem 'capistrano-sneakers'
|
11
|
-
```
|
9
|
+
gem 'capistrano-sneakers', github: 'inventionlabsSydney/capistrano-sneakers'
|
12
10
|
|
13
11
|
And then execute:
|
14
12
|
|
15
13
|
$ bundle
|
16
14
|
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install capistrano-sneakers
|
20
|
-
|
21
15
|
## Usage
|
22
16
|
|
23
|
-
## Usage
|
24
17
|
```ruby
|
25
18
|
# Capfile
|
26
|
-
|
27
19
|
require 'capistrano/sneakers'
|
20
|
+
require 'capistrano/sneakers/monit' # optional, to require monit tasks
|
21
|
+
```
|
22
|
+
|
23
|
+
Configurable options, shown here with defaults:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
:sneakers_default_hooks => true
|
27
|
+
:sneakers_pid => File.join(shared_path, 'tmp', 'pids', 'sneakers.pid') # ensure this path exists in production before deploying
|
28
|
+
:sneakers_env => fetch(:rack_env, fetch(:rails_env, fetch(:stage)))
|
29
|
+
:sneakers_log => File.join(shared_path, 'log', 'sneakers.log')
|
30
|
+
:sneakers_roles => :app
|
31
|
+
:sneakers_processes => 1
|
32
|
+
# sneakers monit
|
33
|
+
:sneakers_monit_conf_dir => '/etc/monit/conf.d'
|
34
|
+
:sneakers_monit_use_sudo => true
|
35
|
+
:monit_bin => '/usr/bin/monit'
|
36
|
+
:sneakers_monit_templates_path => 'config/deploy/templates'
|
28
37
|
```
|
29
38
|
|
30
39
|
## Contributors
|
31
40
|
|
41
|
+
- [Andrew Babichev](https://github.com/Tensho)
|
32
42
|
- [NaixSpirit](https://github.com/NaixSpirit)
|
33
43
|
|
34
44
|
## Contributing
|
35
45
|
|
36
|
-
1. Fork it (
|
46
|
+
1. Fork it (https://github.com/inventionlabsSydney/capistrano-sneakers)
|
37
47
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
48
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
49
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/capistrano-sneakers.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'capistrano/sneakers/version'
|
@@ -6,11 +5,11 @@ require 'capistrano/sneakers/version'
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
6
|
spec.name = "capistrano-sneakers"
|
8
7
|
spec.version = Capistrano::Sneakers::VERSION
|
9
|
-
spec.authors = ["
|
10
|
-
spec.email = ["neverlandxy.naix@gmail.com"]
|
11
|
-
spec.summary = %q{Sneakers integration
|
12
|
-
spec.description = %q{Sneakers integration
|
13
|
-
spec.homepage = "https://github.com/
|
8
|
+
spec.authors = ["Karl Kloppenborg, Andrew Babichev, NaixSpirit"]
|
9
|
+
spec.email = ["k@rl.ag", "andrew.babichev@gmail.com", "neverlandxy.naix@gmail.com"]
|
10
|
+
spec.summary = %q{Sneakers integration for Capistrano}
|
11
|
+
spec.description = %q{Sneakers integration for Capistrano}
|
12
|
+
spec.homepage = "https://github.com/inventionlabsSydney/capistrano-sneakers"
|
14
13
|
spec.license = "MIT"
|
15
14
|
|
16
15
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -18,6 +17,11 @@ Gem::Specification.new do |spec|
|
|
18
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
18
|
spec.require_paths = ["lib"]
|
20
19
|
|
20
|
+
spec.required_ruby_version = '>= 2.0.0'
|
21
|
+
|
22
|
+
spec.add_dependency 'capistrano', '>= 3.9.0'
|
23
|
+
spec.add_dependency 'sneakers'
|
24
|
+
|
21
25
|
spec.add_development_dependency "bundler", "~> 1.7"
|
22
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
27
|
end
|
data/lib/capistrano/sneakers.rb
CHANGED
@@ -1,11 +1 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
cap_version = Gem::Specification.find_by_name('capistrano').version
|
4
|
-
if cap_version >= Gem::Version.new('3.0.0')
|
5
|
-
#
|
6
|
-
# Load Tasks from sneakers "cap" file
|
7
|
-
#
|
8
|
-
load File.expand_path('../tasks/sneakers.rb', __FILE__)
|
9
|
-
else
|
10
|
-
raise Gem::LoadError, "Capistrano-Sneakers requires capistrano version 3.0.0 or greater, version detected: #{cap_version}"
|
11
|
-
end
|
1
|
+
load File.expand_path('../tasks/sneakers.rake', __FILE__)
|
@@ -0,0 +1,108 @@
|
|
1
|
+
namespace :load do
|
2
|
+
task :defaults do
|
3
|
+
set :monit_bin, '/usr/bin/monit'
|
4
|
+
set :sneakers_monit_default_hooks, true
|
5
|
+
set :sneakers_monit_conf_dir, -> { '/etc/monit/conf.d' }
|
6
|
+
set :sneakers_monit_use_sudo, true
|
7
|
+
set :sneakers_monit_templates_path, 'config/deploy/templates'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
namespace :deploy do
|
12
|
+
before :starting, :check_sneakers_monit_hooks do
|
13
|
+
if fetch(:sneakers_default_hooks) && fetch(:sneakers_monit_default_hooks)
|
14
|
+
invoke 'sneakers:monit:add_default_hooks'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
namespace :sneakers do
|
20
|
+
namespace :monit do
|
21
|
+
task :add_default_hooks do
|
22
|
+
before 'deploy:updating', 'sneakers:monit:unmonitor'
|
23
|
+
after 'deploy:published', 'sneakers:monit:monitor'
|
24
|
+
end
|
25
|
+
|
26
|
+
desc 'Config Sneakers monit-service'
|
27
|
+
task :config do
|
28
|
+
on roles(fetch(:sneakers_roles)) do |role|
|
29
|
+
@role = role
|
30
|
+
upload_sneakers_template 'sneakers_monit', "#{fetch(:tmp_dir)}/monit.conf", @role
|
31
|
+
|
32
|
+
mv_command = "mv #{fetch(:tmp_dir)}/monit.conf #{fetch(:sneakers_monit_conf_dir)}/#{sneakers_service_name}.conf"
|
33
|
+
sudo_if_needed mv_command
|
34
|
+
|
35
|
+
sudo_if_needed "#{fetch(:monit_bin)} reload"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'Monitor Sneakers monit-service'
|
40
|
+
task :monitor do
|
41
|
+
on roles(fetch(:sneakers_roles)) do
|
42
|
+
sudo_if_needed "#{fetch(:monit_bin)} monitor #{sneakers_service_name}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
desc 'Unmonitor Sneakers monit-service'
|
47
|
+
task :unmonitor do
|
48
|
+
on roles(fetch(:sneakers_roles)) do
|
49
|
+
sudo_if_needed "#{fetch(:monit_bin)} unmonitor #{sneakers_service_name}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
desc 'Start Sneakers monit-service'
|
54
|
+
task :start do
|
55
|
+
on roles(fetch(:sneakers_roles)) do
|
56
|
+
sudo_if_needed "#{fetch(:monit_bin)} start #{sneakers_service_name}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
desc 'Stop Sneakers monit-service'
|
61
|
+
task :stop do
|
62
|
+
on roles(fetch(:sneakers_roles)) do
|
63
|
+
sudo_if_needed "#{fetch(:monit_bin)} stop #{sneakers_service_name}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
desc 'Restart Sneakers monit-service'
|
68
|
+
task :restart do
|
69
|
+
on roles(fetch(:sneakers_roles)) do
|
70
|
+
sudo_if_needed "#{fetch(:monit_bin)} restart #{sneakers_service_name}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def sneakers_service_name
|
75
|
+
fetch(:sneakers_service_name, "sneakers_#{fetch(:application)}_#{fetch(:sneakers_env)}")
|
76
|
+
end
|
77
|
+
|
78
|
+
def sudo_if_needed(command)
|
79
|
+
fetch(:sneakers_monit_use_sudo) ? sudo(command) : execute(command)
|
80
|
+
end
|
81
|
+
|
82
|
+
def upload_sneakers_template(from, to, role)
|
83
|
+
template = sneakers_template(from, role)
|
84
|
+
upload!(StringIO.new(ERB.new(template).result(binding)), to)
|
85
|
+
end
|
86
|
+
|
87
|
+
def sneakers_template(name, role)
|
88
|
+
local_template_directory = fetch(:sneakers_monit_templates_path)
|
89
|
+
|
90
|
+
search_paths = [
|
91
|
+
"#{name}-#{role.hostname}-#{fetch(:stage)}.erb",
|
92
|
+
"#{name}-#{role.hostname}.erb",
|
93
|
+
"#{name}-#{fetch(:stage)}.erb",
|
94
|
+
"#{name}.erb"
|
95
|
+
].map { |filename| File.join(local_template_directory, filename) }
|
96
|
+
|
97
|
+
global_search_path = File.expand_path(
|
98
|
+
File.join(*%w[.. .. .. generators capistrano sneakers monit templates], "#{name}.conf.erb"),
|
99
|
+
__FILE__
|
100
|
+
)
|
101
|
+
|
102
|
+
search_paths << global_search_path
|
103
|
+
|
104
|
+
template_path = search_paths.detect { |path| File.file?(path) }
|
105
|
+
File.read(template_path)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,225 @@
|
|
1
|
+
namespace :load do
|
2
|
+
task :defaults do
|
3
|
+
set :sneakers_default_hooks, true
|
4
|
+
|
5
|
+
set :sneakers_pid, -> { File.join(shared_path, 'tmp', 'pids', 'sneakers.pid') }
|
6
|
+
set :sneakers_env, -> { fetch(:rack_env, fetch(:rails_env, fetch(:stage))) }
|
7
|
+
set :sneakers_log, -> { File.join(shared_path, 'log', 'sneakers.log') }
|
8
|
+
# set :sneakers_timeout, -> 10
|
9
|
+
# TODO: Rename to plural
|
10
|
+
set :sneakers_roles, [:app]
|
11
|
+
set :sneakers_processes, 1
|
12
|
+
set :sneakers_workers, false # if this is false it will cause Capistrano to exit
|
13
|
+
# rename to sneakers_config
|
14
|
+
set :sneakers_run_config, true # if this is true sneakers will run with preconfigured /config/initializers/sneakers.rb
|
15
|
+
# Rbenv and RVM integration
|
16
|
+
set :rbenv_map_bins, fetch(:rbenv_map_bins).to_a.concat(%w(sneakers))
|
17
|
+
set :rvm_map_bins, fetch(:rvm_map_bins).to_a.concat(%w(sneakers))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
namespace :deploy do
|
22
|
+
before :starting, :check_sneakers_hooks do
|
23
|
+
invoke 'sneakers:add_default_hooks' if fetch(:sneakers_default_hooks)
|
24
|
+
end
|
25
|
+
|
26
|
+
after :publishing, :restart_sneakers do
|
27
|
+
invoke 'sneakers:restart' if fetch(:sneakers_default_hooks)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
namespace :sneakers do
|
32
|
+
task :add_default_hooks do
|
33
|
+
after 'deploy:starting', 'sneakers:quiet'
|
34
|
+
after 'deploy:updated', 'sneakers:stop'
|
35
|
+
after 'deploy:reverted', 'sneakers:stop'
|
36
|
+
after 'deploy:published', 'sneakers:start'
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'Quiet sneakers (stop processing new tasks)'
|
40
|
+
task :quiet do
|
41
|
+
on roles fetch(:sneakers_roles) do |role|
|
42
|
+
switch_user(role) do
|
43
|
+
if test("[ -d #{current_path} ]")
|
44
|
+
each_process_with_index(true) do |pid_file, idx|
|
45
|
+
if pid_file_exists?(pid_file) && process_exists?(pid_file)
|
46
|
+
quiet_sneakers(pid_file)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
desc 'Stop sneakers'
|
55
|
+
task :stop do
|
56
|
+
on roles fetch(:sneakers_roles) do |role|
|
57
|
+
switch_user(role) do
|
58
|
+
if test("[ -d #{current_path} ]")
|
59
|
+
each_process_with_index(true) do |pid_file, idx|
|
60
|
+
if pid_file_exists?(pid_file) && process_exists?(pid_file)
|
61
|
+
stop_sneakers(pid_file)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
desc 'Start sneakers'
|
70
|
+
task :start do
|
71
|
+
on roles fetch(:sneakers_roles) do |role|
|
72
|
+
switch_user(role) do
|
73
|
+
each_process_with_index do |pid_file, idx|
|
74
|
+
unless pid_file_exists?(pid_file) && process_exists?(pid_file)
|
75
|
+
start_sneakers(pid_file, idx)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
desc 'Restart sneakers'
|
83
|
+
task :restart do
|
84
|
+
invoke! 'sneakers:stop'
|
85
|
+
# It takes some time to stop serverengine processes and cleanup pidfiles.
|
86
|
+
# We should wait until pidfiles will be removed.
|
87
|
+
sleep 5
|
88
|
+
invoke 'sneakers:start'
|
89
|
+
end
|
90
|
+
|
91
|
+
desc 'Rolling-restart sneakers'
|
92
|
+
task :rolling_restart do
|
93
|
+
on roles fetch(:sneakers_roles) do |role|
|
94
|
+
switch_user(role) do
|
95
|
+
each_process_with_index(true) do |pid_file, idx|
|
96
|
+
if pid_file_exists?(pid_file) && process_exists?(pid_file)
|
97
|
+
stop_sneakers(pid_file)
|
98
|
+
end
|
99
|
+
start_sneakers(pid_file, idx)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# Delete any pid file not in use
|
106
|
+
task :cleanup do
|
107
|
+
on roles fetch(:sneakers_roles) do |role|
|
108
|
+
switch_user(role) do
|
109
|
+
each_process_with_index do |pid_file, idx|
|
110
|
+
unless process_exists?(pid_file)
|
111
|
+
if pid_file_exists?(pid_file)
|
112
|
+
execute "rm #{pid_file}"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# TODO : Don't start if all proccess are off, raise warning.
|
121
|
+
desc 'Respawn missing sneakers proccesses'
|
122
|
+
task :respawn do
|
123
|
+
invoke 'sneakers:cleanup'
|
124
|
+
on roles fetch(:sneakers_roles) do |role|
|
125
|
+
switch_user(role) do
|
126
|
+
each_process_with_index do |pid_file, idx|
|
127
|
+
unless pid_file_exists?(pid_file)
|
128
|
+
start_sneakers(pid_file, idx)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def each_process_with_index(reverse = false, &block)
|
136
|
+
_pid_files = pid_files
|
137
|
+
_pid_files.reverse! if reverse
|
138
|
+
_pid_files.each_with_index do |pid_file, idx|
|
139
|
+
within release_path do
|
140
|
+
yield(pid_file, idx)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def pid_files
|
146
|
+
sneakers_roles = Array(fetch(:sneakers_roles))
|
147
|
+
sneakers_roles.select! { |role| host.roles.include?(role) }
|
148
|
+
sneakers_roles.flat_map do |role|
|
149
|
+
processes = fetch(:sneakers_processes)
|
150
|
+
if processes == 1
|
151
|
+
fetch(:sneakers_pid)
|
152
|
+
else
|
153
|
+
Array.new(processes) { |idx| fetch(:sneakers_pid).gsub(/\.pid$/, "-#{idx}.pid") }
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def pid_file_exists?(pid_file)
|
159
|
+
test(*("[ -f #{pid_file} ]").split(' '))
|
160
|
+
end
|
161
|
+
|
162
|
+
def process_exists?(pid_file)
|
163
|
+
test(*("kill -0 $( cat #{pid_file} )").split(' '))
|
164
|
+
end
|
165
|
+
|
166
|
+
def quiet_sneakers(pid_file)
|
167
|
+
if fetch(:sneakers_use_signals) || fetch(:sneakers_run_config)
|
168
|
+
execute :kill, "-USR1 `cat #{pid_file}`"
|
169
|
+
else
|
170
|
+
begin
|
171
|
+
execute :bundle, :exec, :sneakersctl, 'quiet', "#{pid_file}"
|
172
|
+
rescue SSHKit::Command::Failed
|
173
|
+
# If gems are not installed eq(first deploy) and sneakers_default_hooks as active
|
174
|
+
warn 'sneakersctl not found (ignore if this is the first deploy)'
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def stop_sneakers(pid_file)
|
180
|
+
if fetch(:sneakers_run_config) == true
|
181
|
+
execute :kill, "-SIGTERM `cat #{pid_file}`"
|
182
|
+
else
|
183
|
+
if fetch(:stop_sneakers_in_background, fetch(:sneakers_run_in_background))
|
184
|
+
if fetch(:sneakers_use_signals)
|
185
|
+
background :kill, "-TERM `cat #{pid_file}`"
|
186
|
+
else
|
187
|
+
background :bundle, :exec, :sneakersctl, 'stop', "#{pid_file}", fetch(:sneakers_timeout)
|
188
|
+
end
|
189
|
+
else
|
190
|
+
execute :bundle, :exec, :sneakersctl, 'stop', "#{pid_file}", fetch(:sneakers_timeout)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def start_sneakers(pid_file, idx = 0)
|
196
|
+
if fetch(:sneakers_run_config) == true
|
197
|
+
# Use sneakers configuration prebuilt in
|
198
|
+
raise "[ set :workers, ['worker1', 'workerN'] ] not configured properly, please configure the workers you wish to use" if fetch(:sneakers_workers).nil? or fetch(:sneakers_workers) == false or !fetch(:sneakers_workers).kind_of? Array
|
199
|
+
|
200
|
+
workers = fetch(:sneakers_workers).compact.join(',')
|
201
|
+
|
202
|
+
info "Starting the sneakers processes"
|
203
|
+
|
204
|
+
with rails_env: fetch(:sneakers_env), workers: workers do
|
205
|
+
rake 'sneakers:run'
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def switch_user(role, &block)
|
211
|
+
user = sneakers_user(role)
|
212
|
+
if user == role.user
|
213
|
+
block.call
|
214
|
+
else
|
215
|
+
as user do
|
216
|
+
block.call
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
def sneakers_user(role)
|
222
|
+
properties = role.properties
|
223
|
+
properties.fetch(:sneakers_user) || fetch(:sneakers_user) || properties.fetch(:run_as) || role.user
|
224
|
+
end
|
225
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module Sneakers
|
5
|
+
module Monit
|
6
|
+
module Generators
|
7
|
+
class TemplateGenerator < Rails::Generators::Base
|
8
|
+
|
9
|
+
namespace "capistrano:sneakers:monit:template"
|
10
|
+
desc "Create local monitrc.erb, and erb files for monitored processes for customization"
|
11
|
+
source_root File.expand_path('../templates', __FILE__)
|
12
|
+
argument :templates_path, type: :string,
|
13
|
+
default: "config/deploy/templates",
|
14
|
+
banner: "path to templates"
|
15
|
+
|
16
|
+
def copy_template
|
17
|
+
copy_file "sneakers_monit.conf.erb", "#{templates_path}/sneakers_monit.erb"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Monit configuration for Sneakers
|
2
|
+
# Service name: <%= sneakers_service_name %>
|
3
|
+
#
|
4
|
+
check process <%= sneakers_service_name %>
|
5
|
+
with pidfile "<%= fetch(:sneakers_pid) %>"
|
6
|
+
start program = "/usr/bin/sudo -iu <%= sneakers_user(@role) %> /bin/bash -c 'cd <%= current_path %> && RAILS_ENV=<%= fetch(:sneakers_env) %> WORKERS=<%= fetch(:sneakers_workers).join(',') %> <%= SSHKit.config.command_map[:rake] %> sneakers:run'"
|
7
|
+
stop program = "/usr/bin/sudo -iu <%= sneakers_user(@role) %> /bin/bash -c 'kill -SIGTERM `cat <%= fetch(:sneakers_pid) %>`'"
|
metadata
CHANGED
@@ -1,51 +1,82 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-sneakers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Karl Kloppenborg, Andrew Babichev, NaixSpirit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
|
14
|
+
name: capistrano
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.9.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.9.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sneakers
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
15
35
|
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
16
42
|
name: bundler
|
17
43
|
requirement: !ruby/object:Gem::Requirement
|
18
44
|
requirements:
|
19
|
-
- - ~>
|
45
|
+
- - "~>"
|
20
46
|
- !ruby/object:Gem::Version
|
21
47
|
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
22
50
|
version_requirements: !ruby/object:Gem::Requirement
|
23
51
|
requirements:
|
24
|
-
- - ~>
|
52
|
+
- - "~>"
|
25
53
|
- !ruby/object:Gem::Version
|
26
54
|
version: '1.7'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
|
-
type: :development
|
29
|
-
prerelease: false
|
30
56
|
name: rake
|
31
57
|
requirement: !ruby/object:Gem::Requirement
|
32
58
|
requirements:
|
33
|
-
- - ~>
|
59
|
+
- - "~>"
|
34
60
|
- !ruby/object:Gem::Version
|
35
61
|
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
36
64
|
version_requirements: !ruby/object:Gem::Requirement
|
37
65
|
requirements:
|
38
|
-
- - ~>
|
66
|
+
- - "~>"
|
39
67
|
- !ruby/object:Gem::Version
|
40
68
|
version: '10.0'
|
41
|
-
description: Sneakers integration
|
69
|
+
description: Sneakers integration for Capistrano
|
42
70
|
email:
|
71
|
+
- k@rl.ag
|
72
|
+
- andrew.babichev@gmail.com
|
43
73
|
- neverlandxy.naix@gmail.com
|
44
74
|
executables: []
|
45
75
|
extensions: []
|
46
76
|
extra_rdoc_files: []
|
47
77
|
files:
|
48
|
-
- .gitignore
|
78
|
+
- ".gitignore"
|
79
|
+
- CHANGELOG.md
|
49
80
|
- Gemfile
|
50
81
|
- LICENSE.txt
|
51
82
|
- README.md
|
@@ -53,9 +84,13 @@ files:
|
|
53
84
|
- capistrano-sneakers.gemspec
|
54
85
|
- lib/capistrano-sneakers.rb
|
55
86
|
- lib/capistrano/sneakers.rb
|
87
|
+
- lib/capistrano/sneakers/monit.rb
|
56
88
|
- lib/capistrano/sneakers/version.rb
|
57
|
-
- lib/capistrano/tasks/
|
58
|
-
|
89
|
+
- lib/capistrano/tasks/monit.rake
|
90
|
+
- lib/capistrano/tasks/sneakers.rake
|
91
|
+
- lib/generators/capistrano/sneakers/monit/template_generator.rb
|
92
|
+
- lib/generators/capistrano/sneakers/monit/templates/sneakers_monit.conf.erb
|
93
|
+
homepage: https://github.com/inventionlabsSydney/capistrano-sneakers
|
59
94
|
licenses:
|
60
95
|
- MIT
|
61
96
|
metadata: {}
|
@@ -65,19 +100,18 @@ require_paths:
|
|
65
100
|
- lib
|
66
101
|
required_ruby_version: !ruby/object:Gem::Requirement
|
67
102
|
requirements:
|
68
|
-
- -
|
103
|
+
- - ">="
|
69
104
|
- !ruby/object:Gem::Version
|
70
|
-
version:
|
105
|
+
version: 2.0.0
|
71
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
107
|
requirements:
|
73
|
-
- -
|
108
|
+
- - ">="
|
74
109
|
- !ruby/object:Gem::Version
|
75
110
|
version: '0'
|
76
111
|
requirements: []
|
77
112
|
rubyforge_project:
|
78
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.5.2
|
79
114
|
signing_key:
|
80
115
|
specification_version: 4
|
81
|
-
summary: Sneakers integration
|
116
|
+
summary: Sneakers integration for Capistrano
|
82
117
|
test_files: []
|
83
|
-
has_rdoc:
|
@@ -1,242 +0,0 @@
|
|
1
|
-
namespace :load do
|
2
|
-
|
3
|
-
task :defaults do
|
4
|
-
set :sneakers_default_hooks, -> { true }
|
5
|
-
|
6
|
-
set :sneakers_pid, -> { File.join(shared_path, 'tmp', 'pids', 'sneakers.pid') }
|
7
|
-
set :sneakers_env, -> { fetch(:rack_env, fetch(:rails_env, fetch(:stage))) }
|
8
|
-
set :sneakers_log, -> { File.join(shared_path, 'log', 'sneakers.log') }
|
9
|
-
# set :sneakers_timeout, -> { 10 }
|
10
|
-
set :sneakers_role, -> { :app }
|
11
|
-
set :sneakers_processes, -> { 1 }
|
12
|
-
set :sneakers_workers, -> { false } # if this is false it will cause Capistrano to exit
|
13
|
-
set :sneakers_run_config, -> { false } # if this is true sneakers will run with preconfigured /config/initializers/sneakers.rb
|
14
|
-
set :sneakers_boot_file, -> { false } # Needed for booting daemons dynamically
|
15
|
-
# Rbenv and RVM integration
|
16
|
-
set :rbenv_map_bins, fetch(:rbenv_map_bins).to_a.concat(%w(sneakers))
|
17
|
-
set :rvm_map_bins, fetch(:rvm_map_bins).to_a.concat(%w(sneakers))
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
namespace :deploy do
|
23
|
-
|
24
|
-
before :starting, :check_sneakers_hooks do
|
25
|
-
invoke 'sneakers:add_default_hooks' if fetch(:sneakers_default_hooks)
|
26
|
-
end
|
27
|
-
|
28
|
-
after :publishing, :restart_sneakers do
|
29
|
-
invoke 'sneakers:restart' if fetch(:sneakers_default_hooks)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
namespace :sneakers do
|
34
|
-
|
35
|
-
def for_each_sneakers_process(reverse = false, &block)
|
36
|
-
pids = processes_sneakers_pids
|
37
|
-
pids.reverse! if reverse
|
38
|
-
pids.each_with_index do |pid_file, idx|
|
39
|
-
within current_path do
|
40
|
-
yield(pid_file, idx)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def processes_sneakers_pids
|
46
|
-
pids = []
|
47
|
-
raise "sneaker_processes is nil class, cannot continue, please [set :sneaker_processes]" if fetch(:sneakers_processes).nil?
|
48
|
-
fetch(:sneakers_processes).times do |idx|
|
49
|
-
pids.push (idx.zero? && fetch(:sneakers_processes) <= 1) ?
|
50
|
-
fetch(:sneakers_pid) :
|
51
|
-
fetch(:sneakers_pid).gsub(/\.pid$/, "-#{idx}.pid")
|
52
|
-
|
53
|
-
end
|
54
|
-
pids
|
55
|
-
end
|
56
|
-
|
57
|
-
def sneakers_pid_process_exists?(pid_file)
|
58
|
-
sneakers_pid_file_exists?(pid_file) and test(*("kill -0 $( cat #{pid_file} )").split(' '))
|
59
|
-
end
|
60
|
-
|
61
|
-
def sneakers_pid_file_exists?(pid_file)
|
62
|
-
test(*("[ -f #{pid_file} ]").split(' '))
|
63
|
-
end
|
64
|
-
|
65
|
-
def stop_sneakers(pid_file)
|
66
|
-
if fetch(:sneakers_run_config) == true
|
67
|
-
execute "kill -SIGTERM `cat #{pid_file}`"
|
68
|
-
else
|
69
|
-
if fetch(:stop_sneakers_in_background, fetch(:sneakers_run_in_background))
|
70
|
-
if fetch(:sneakers_use_signals)
|
71
|
-
background "kill -TERM `cat #{pid_file}`"
|
72
|
-
else
|
73
|
-
background :bundle, :exec, :sneakersctl, 'stop', "#{pid_file}", fetch(:sneakers_timeout)
|
74
|
-
end
|
75
|
-
else
|
76
|
-
execute :bundle, :exec, :sneakersctl, 'stop', "#{pid_file}", fetch(:sneakers_timeout)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def quiet_sneakers(pid_file)
|
82
|
-
if fetch(:sneakers_use_signals) || fetch(:sneakers_run_config)
|
83
|
-
background "kill -USR1 `cat #{pid_file}`"
|
84
|
-
else
|
85
|
-
begin
|
86
|
-
execute :bundle, :exec, :sneakersctl, 'quiet', "#{pid_file}"
|
87
|
-
rescue SSHKit::Command::Failed
|
88
|
-
# If gems are not installed eq(first deploy) and sneakers_default_hooks as active
|
89
|
-
warn 'sneakersctl not found (ignore if this is the first deploy)'
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def start_sneakers(pid_file, idx = 0)
|
95
|
-
if fetch(:sneakers_run_config) == true
|
96
|
-
# Use sneakers configuration prebuilt in
|
97
|
-
raise "[ set :workers, ['worker1', 'workerN'] ] not configured properly, please configure the workers you wish to use" if fetch(:sneakers_workers).nil? or fetch(:sneakers_workers) == false or !fetch(:sneakers_workers).kind_of? Array
|
98
|
-
|
99
|
-
workers = fetch(:sneakers_workers).compact.join(',')
|
100
|
-
|
101
|
-
#run "cmd", env: { 'WORKERS' => workers } #export this to environmental variable
|
102
|
-
info "Starting the sneakers processes"
|
103
|
-
#workers.each do |worker|
|
104
|
-
|
105
|
-
with rails_env: fetch(:sneakers_env), workers: workers do
|
106
|
-
rake 'sneakers:run'
|
107
|
-
end
|
108
|
-
#execute :bundle, :exec, :sneakers, args.compact.join(' ')
|
109
|
-
else
|
110
|
-
# Using custom sneakers setup
|
111
|
-
args.push "--index #{idx}"
|
112
|
-
args.push "--pidfile #{pid_file}"
|
113
|
-
args.push "--environment #{fetch(:sneakers_env)}"
|
114
|
-
args.push "--logfile #{fetch(:sneakers_log)}" if fetch(:sneakers_log)
|
115
|
-
args.push "--require #{fetch(:sneakers_require)}" if fetch(:sneakers_require)
|
116
|
-
args.push "--tag #{fetch(:sneakers_tag)}" if fetch(:sneakers_tag)
|
117
|
-
Array(fetch(:sneakers_queue)).each do |queue|
|
118
|
-
args.push "--queue #{queue}"
|
119
|
-
end
|
120
|
-
args.push "--config #{fetch(:sneakers_config)}" if fetch(:sneakers_config)
|
121
|
-
args.push "--concurrency #{fetch(:sneakers_concurrency)}" if fetch(:sneakers_concurrency)
|
122
|
-
# use sneakers_options for special options
|
123
|
-
args.push fetch(:sneakers_options) if fetch(:sneakers_options)
|
124
|
-
|
125
|
-
if defined?(JRUBY_VERSION)
|
126
|
-
args.push '>/dev/null 2>&1 &'
|
127
|
-
warn 'Since JRuby doesn\'t support Process.daemon, sneakers will not be running as a daemon.'
|
128
|
-
else
|
129
|
-
args.push '--daemon'
|
130
|
-
end
|
131
|
-
|
132
|
-
if fetch(:start_sneakers_in_background, fetch(:sneakers_run_in_background))
|
133
|
-
background :bundle, :exec, :sneakers, args.compact.join(' ')
|
134
|
-
else
|
135
|
-
execute :bundle, :exec, :sneakers, args.compact.join(' ')
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
task :add_default_hooks do
|
141
|
-
after 'deploy:starting', 'sneakers:quiet'
|
142
|
-
after 'deploy:updated', 'sneakers:stop'
|
143
|
-
after 'deploy:reverted', 'sneakers:stop'
|
144
|
-
after 'deploy:published', 'sneakers:start'
|
145
|
-
end
|
146
|
-
|
147
|
-
desc 'Quiet sneakers (stop processing new tasks)'
|
148
|
-
task :quiet do
|
149
|
-
on roles fetch(:sneakers_role) do
|
150
|
-
if test("[ -d #{current_path} ]") # fixes #11
|
151
|
-
for_each_sneakers_process(true) do |pid_file, idx|
|
152
|
-
if sneakers_pid_process_exists?(pid_file)
|
153
|
-
quiet_sneakers(pid_file)
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
desc 'Stop sneakers'
|
161
|
-
task :stop do
|
162
|
-
on roles fetch(:sneakers_role) do
|
163
|
-
if test("[ -d #{current_path} ]")
|
164
|
-
for_each_sneakers_process(true) do |pid_file, idx|
|
165
|
-
if sneakers_pid_process_exists?(pid_file)
|
166
|
-
stop_sneakers(pid_file)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
desc 'Start sneakers'
|
174
|
-
task :start do
|
175
|
-
on roles fetch(:sneakers_role) do
|
176
|
-
for_each_sneakers_process do |pid_file, idx|
|
177
|
-
start_sneakers(pid_file, idx) unless sneakers_pid_process_exists?(pid_file)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
desc 'Restart sneakers'
|
183
|
-
task :restart do
|
184
|
-
invoke 'sneakers:stop'
|
185
|
-
invoke 'sneakers:start'
|
186
|
-
end
|
187
|
-
|
188
|
-
desc 'Rolling-restart sneakers'
|
189
|
-
task :rolling_restart do
|
190
|
-
on roles fetch(:sneakers_role) do
|
191
|
-
for_each_sneakers_process(true) do |pid_file, idx|
|
192
|
-
if sneakers_pid_process_exists?(pid_file)
|
193
|
-
stop_sneakers(pid_file)
|
194
|
-
end
|
195
|
-
start_sneakers(pid_file, idx)
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
# Delete any pid file not in use
|
201
|
-
task :cleanup do
|
202
|
-
on roles fetch(:sneakers_role) do
|
203
|
-
for_each_sneakers_process do |pid_file, idx|
|
204
|
-
if sneakers_pid_file_exists?(pid_file)
|
205
|
-
execute "rm #{pid_file}" unless sneakers_pid_process_exists?(pid_file)
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
# TODO : Don't start if all proccess are off, raise warning.
|
212
|
-
desc 'Respawn missing sneakers proccesses'
|
213
|
-
task :respawn do
|
214
|
-
invoke 'sneakers:cleanup'
|
215
|
-
on roles fetch(:sneakers_role) do
|
216
|
-
for_each_sneakers_process do |pid_file, idx|
|
217
|
-
unless sneakers_pid_file_exists?(pid_file)
|
218
|
-
start_sneakers(pid_file, idx)
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
def template_sneakers(from, to, role)
|
225
|
-
[
|
226
|
-
File.join('lib', 'capistrano', 'templates', "#{from}-#{role.hostname}-#{fetch(:stage)}.rb"),
|
227
|
-
File.join('lib', 'capistrano', 'templates', "#{from}-#{role.hostname}.rb"),
|
228
|
-
File.join('lib', 'capistrano', 'templates', "#{from}-#{fetch(:stage)}.rb"),
|
229
|
-
File.join('lib', 'capistrano', 'templates', "#{from}.rb.erb"),
|
230
|
-
File.join('lib', 'capistrano', 'templates', "#{from}.rb"),
|
231
|
-
File.join('lib', 'capistrano', 'templates', "#{from}.erb"),
|
232
|
-
File.expand_path("../../templates/#{from}.rb.erb", __FILE__),
|
233
|
-
File.expand_path("../../templates/#{from}.erb", __FILE__)
|
234
|
-
].each do |path|
|
235
|
-
if File.file?(path)
|
236
|
-
erb = File.read(path)
|
237
|
-
upload! StringIO.new(ERB.new(erb).result(binding)), to
|
238
|
-
break
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|