capistrano-psw 1.0.0.pre
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/.gitignore +17 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +23 -0
- data/README.md +136 -0
- data/Rakefile +1 -0
- data/capistrano-psw.gemspec +29 -0
- data/lib/capistrano/psw/task_loader.rb +28 -0
- data/lib/capistrano/psw/version.rb +15 -0
- data/lib/capistrano/psw.rb +7 -0
- data/resources/lib/capistrano/tasks/psw-repo.cap +90 -0
- data/resources/lib/capistrano/tasks/psw-sidekiq.cap +158 -0
- data/spec/psw-repo_spec.rb +55 -0
- data/spec/psw-sidekiq_spec.rb +50 -0
- data/spec/spec_helper.rb +20 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b991623b4a7789e1034988c7d39b318267eff92b
|
4
|
+
data.tar.gz: dbc39ef418ae63156d3a7abcbf84078f43413e99
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e08e05a041c913af3817399f948478efc7e2ae6651f6263ff2d1c8f881f504fcc7e113c2ca842533f7a82fe3ba3c14238e9cccdf917cceb4c549bdfaa498bc21
|
7
|
+
data.tar.gz: 402deb45f5e1c85a43667331574f012f909fb54ff5ce1589338645ba9b31600b9ef511fc2a9037c5e6792c6a7bac6c3cd0168406057c8ba53a9972985c7f7098
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p247
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2013 Lexmark International Technology S.A. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions are met:
|
5
|
+
* Redistributions of source code must retain the above copyright
|
6
|
+
notice, this list of conditions and the following disclaimer.
|
7
|
+
* Redistributions in binary form must reproduce the above copyright
|
8
|
+
notice, this list of conditions and the following disclaimer in the
|
9
|
+
documentation and/or other materials provided with the distribution.
|
10
|
+
* Neither the name of Lexmark International Technology S.A. nor the
|
11
|
+
names of its contributors may be used to endorse or promote products
|
12
|
+
derived from this software without specific prior written permission.
|
13
|
+
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
15
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
16
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
17
|
+
DISCLAIMED. IN NO EVENT SHALL Lexmark International Technology S.A. BE LIABLE FOR ANY
|
18
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
19
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
20
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
21
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
22
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
23
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
# Capistrano::Psw
|
2
|
+
|
3
|
+
This capistrano-psw gem contains code deployment and system management tasks that can be utilized
|
4
|
+
with Capistrano v3.
|
5
|
+
|
6
|
+
Until Capistrano v3 becomes available on RubyGems, it's not possible to specify a gemspec dependency on
|
7
|
+
it; however the v3 branch is a requirement for using these tasks.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'capistrano-psw'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install capistrano-psw
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
``` shell
|
26
|
+
$ cap -vT
|
27
|
+
|
28
|
+
$ cap staging deploy
|
29
|
+
$ cap production deploy
|
30
|
+
|
31
|
+
$ cap production deploy --dry-run
|
32
|
+
$ cap production deploy --prereqs
|
33
|
+
$ cap production deploy --trace
|
34
|
+
```
|
35
|
+
|
36
|
+
``` ruby
|
37
|
+
# Capfile
|
38
|
+
|
39
|
+
# Capfile Prereqs:
|
40
|
+
require 'capistrano/setup'
|
41
|
+
require 'capistrano/deploy'
|
42
|
+
|
43
|
+
# Gem include(s):
|
44
|
+
require 'capistrano/psw'
|
45
|
+
|
46
|
+
# or require just what you need
|
47
|
+
require 'capistrano/psw/task_loader'
|
48
|
+
```
|
49
|
+
|
50
|
+
``` ruby
|
51
|
+
# config/deploy.rb
|
52
|
+
|
53
|
+
namespace :deploy do
|
54
|
+
|
55
|
+
desc 'Release restart...'
|
56
|
+
task :restart do
|
57
|
+
invoke :'deploy:internal_restart'
|
58
|
+
end
|
59
|
+
|
60
|
+
desc '[internal] Restart logic...'
|
61
|
+
task :internal_restart do
|
62
|
+
on roles(:all) do |host|
|
63
|
+
|
64
|
+
info "Stopping nginx on remote server #{host}..."
|
65
|
+
sudo :service, 'nginx', 'stop'
|
66
|
+
|
67
|
+
info "Restarting sidekiq on remote server #{host}..."
|
68
|
+
#force a re-execution (the stop was done as a pre-hook)
|
69
|
+
Rake::Task['psw_sidekiq:start'].reenable
|
70
|
+
invoke :'psw_sidekiq:start'
|
71
|
+
|
72
|
+
info "Starting nginx on remote server #{host}..."
|
73
|
+
sudo :service, 'nginx', 'start'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
#Before we start deploying any code, we need to stop any existing sidekiq servers
|
78
|
+
before :starting, 'psw_sidekiq:stop'
|
79
|
+
|
80
|
+
#Before we start deploying any code, we need to upload the github code
|
81
|
+
before :starting, 'psw_repo:default'
|
82
|
+
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
86
|
+
## Github-related Tasks
|
87
|
+
|
88
|
+
### psw_repo:local_clone_repo
|
89
|
+
In situations where the githb repo is behind a VPN or firewall, the code must
|
90
|
+
be downloaded behind the VPN firewall and copied to the remote server. This task
|
91
|
+
will manage the download.
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
#set psw_repo preferences
|
95
|
+
before :'psw_repo:local_clone_repo', :set_repo_options do
|
96
|
+
set :psw_repo_url, 'git@github.private.com:workspace/repo.git'
|
97
|
+
end
|
98
|
+
```
|
99
|
+
|
100
|
+
### psw_repo:upload_repo
|
101
|
+
In situations where the githb repo is behind a VPN or firewall, the code must
|
102
|
+
be downloaded behind the VPN firewall and copied to the remote server. This
|
103
|
+
task will manage the upload to the remote server.
|
104
|
+
|
105
|
+
### psw_repo:default
|
106
|
+
Executes the following tasks: local_clone_repo, upload_repo
|
107
|
+
|
108
|
+
## Sidekiq-related Tasks
|
109
|
+
The standard sidekiq/capistrano integration (https://github.com/mperham/sidekiq/wiki/Deployment)
|
110
|
+
doesn't work with Capistrano v3 (https://github.com/cramerdev/capistrano-chef/issues/22),
|
111
|
+
so this implmenetation bridges the gap.
|
112
|
+
|
113
|
+
These tasks require rbenv be installed and the capistrano-rbenv (https://github.com/yyuu/capistrano-rbenv)
|
114
|
+
gem be installed.
|
115
|
+
|
116
|
+
### psw_sidekiq:start
|
117
|
+
Starts a specified number of sidekiq servers.
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
before :'psw_sidekiq:stop', :set_sidekiq_options do
|
121
|
+
set :psw_sidekiq_bundle_cmd, "#{fetch(:rbenv_bundle_cmd)}"
|
122
|
+
set :psw_sidekiq_instance_cnt, "2"
|
123
|
+
end
|
124
|
+
```
|
125
|
+
|
126
|
+
### psw_sidekiq:stop
|
127
|
+
Stops all known sidekiq servers (by reviewing the PID files in the 'current' deployment). It
|
128
|
+
should be noted that this task should run as a'before' hook, so that the 'current' directory
|
129
|
+
still points to the last run (otherwise the PID files won't exist)
|
130
|
+
|
131
|
+
### psw_sidekiq:restart
|
132
|
+
Executes the following tasks: stop, start
|
133
|
+
|
134
|
+
## License
|
135
|
+
|
136
|
+
2013 Lexmark International Technology S.A. All rights reserved.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capistrano/psw/version'
|
5
|
+
require 'rake'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "capistrano-psw"
|
9
|
+
spec.version = Capistrano::Psw::VERSION
|
10
|
+
spec.authors = ["Lexmark International Technology S.A"]
|
11
|
+
spec.email = ["matt.sawka@perceptivesoftware.com"]
|
12
|
+
spec.description = %q{This gem contains code deployment and system management tasks that can be utilized with Capistrano v3}
|
13
|
+
spec.summary = %q{Contains Capistrano v3 Deployment Tasks}
|
14
|
+
spec.homepage = "http://www.perceptivesoftware.com/"
|
15
|
+
spec.license = "3-Clause BSD"
|
16
|
+
|
17
|
+
spec.files = FileList['lib/capistrano/psw/psw.rb',
|
18
|
+
'lib/capistrano/psw/*',
|
19
|
+
'resources/lib/capistrano/tasks/*'].to_a
|
20
|
+
|
21
|
+
spec.files = `git ls-files`.split($/)
|
22
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
24
|
+
spec.require_paths = ["lib", "resources/lib/capistrano/tasks"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "rspec"
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# == task_loader.rb
|
2
|
+
#
|
3
|
+
# This module provides a generic Capistrano task loader (*.cap files). Tasks that are
|
4
|
+
# found in a directory ending with 'resources/lib/capistrano/tasks' will be loaded and
|
5
|
+
# made available to Capistrano v3.
|
6
|
+
#
|
7
|
+
# == Contact
|
8
|
+
#
|
9
|
+
# Author:: Lexmark International Technology S.A.
|
10
|
+
# Copyright:: 2013 Lexmark International Technology S.A. All rights reserved.
|
11
|
+
# License:: 3-Clause BSD
|
12
|
+
|
13
|
+
module Capistrano
|
14
|
+
module Psw
|
15
|
+
puts "Loading Capistrano V3 tasks..."
|
16
|
+
|
17
|
+
$LOAD_PATH.each do |dir|
|
18
|
+
if (dir.end_with?("resources/lib/capistrano/tasks"))
|
19
|
+
Dir.foreach(dir) do |task|
|
20
|
+
if (task.end_with?(".cap"))
|
21
|
+
puts "Loading task #{task}..."
|
22
|
+
load task
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# == task_loader.rb
|
2
|
+
#
|
3
|
+
# This module represents the gem version
|
4
|
+
#
|
5
|
+
# == Contact
|
6
|
+
#
|
7
|
+
# Author:: Lexmark International Technology S.A.
|
8
|
+
# Copyright:: 2013 Lexmark International Technology S.A. All rights reserved.
|
9
|
+
# License:: 3-Clause BSD
|
10
|
+
|
11
|
+
module Capistrano
|
12
|
+
module Psw
|
13
|
+
VERSION = "1.0.0.pre"
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# == psw-repo.cap
|
2
|
+
#
|
3
|
+
# Contains the capistrano tasks needed to deploy a rails project from a github
|
4
|
+
# repository behind a VPN or firewall.
|
5
|
+
#
|
6
|
+
# == Configuration
|
7
|
+
# The following configuration options may be set (should be set before the
|
8
|
+
# 'local_clone_repo' task is executed):
|
9
|
+
#
|
10
|
+
# before :'psw_repo:local_clone_repo', :set_repo_options do
|
11
|
+
# set :psw_repo_url, 'git@github..com:myRepo.git'
|
12
|
+
# set :branch, 'build'
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# * psw_repo_url
|
16
|
+
# ** The github location
|
17
|
+
# * branch
|
18
|
+
# ** (Optional) The branch of the github location to use; default is master
|
19
|
+
# * psw_repo_debug
|
20
|
+
# ** (Optional) Boolean that will enable debug logging
|
21
|
+
#
|
22
|
+
# == Tasks
|
23
|
+
#
|
24
|
+
# === psw_repo:local_clone_repo
|
25
|
+
# In situations where the githb repo is behind a VPN or firewall, the code must
|
26
|
+
# be downloaded behind the VPN firewall and copied to the remote server.
|
27
|
+
# This task will manage the download.
|
28
|
+
#
|
29
|
+
# === psw_repo:upload_repo
|
30
|
+
# In situations where the githb repo is behind a VPN or firewall, the code must
|
31
|
+
# be downloaded behind the VPN firewall and copied to the remote server. This
|
32
|
+
# task will manage the upload to the remote server.
|
33
|
+
#
|
34
|
+
# === psw_repo:default
|
35
|
+
# Executes the following tasks: local_clone_repo, upload_repo
|
36
|
+
#
|
37
|
+
# == Contact
|
38
|
+
#
|
39
|
+
# Author:: Lexmark International Technology S.A.
|
40
|
+
# Copyright:: 2013 Lexmark International Technology S.A. All rights reserved.
|
41
|
+
# License:: 3-Clause BSD
|
42
|
+
|
43
|
+
require 'find'
|
44
|
+
|
45
|
+
namespace :psw_repo do
|
46
|
+
|
47
|
+
desc 'Download private repository locally (firewall issues)'
|
48
|
+
task :local_clone_repo do
|
49
|
+
set :local_repo_dir, "#{fetch(:tmp_dir)}/#{fetch(:application)}"
|
50
|
+
|
51
|
+
puts "Downloading private repository to #{fetch(:local_repo_dir)}"
|
52
|
+
%x[rm -rf #{fetch(:local_repo_dir)}]
|
53
|
+
|
54
|
+
git_cmd = "git clone --mirror #{fetch(:psw_repo_url)} #{fetch(:local_repo_dir)}"
|
55
|
+
puts "Executing download command: #{git_cmd}"
|
56
|
+
%x[#{git_cmd}]
|
57
|
+
end
|
58
|
+
|
59
|
+
desc 'Upload private repository to remote server (firewall issues)'
|
60
|
+
task :upload_repo do
|
61
|
+
on roles(:all) do |host|
|
62
|
+
set :repo_url, "file:///tmp/#{fetch(:application)}"
|
63
|
+
set :remote_repo_dir, "#{fetch(:repo_url).gsub('file://', '')}"
|
64
|
+
set :local_repo_dir, "#{fetch(:tmp_dir)}/#{fetch(:application)}"
|
65
|
+
|
66
|
+
info "Uploading #{fetch(:local_repo_dir)} (local) to #{fetch(:remote_repo_dir)} on remote server #{host}..."
|
67
|
+
|
68
|
+
execute :rm, '-rf', "#{fetch(:remote_repo_dir)}"
|
69
|
+
execute :mkdir, '-p', "#{fetch(:remote_repo_dir)}"
|
70
|
+
func_file_upload = lambda { |file|
|
71
|
+
rel_file = "#{file.gsub("#{fetch(:local_repo_dir)}", '')}"
|
72
|
+
rel_file = rel_file[1..-1] if rel_file[0] == '/'
|
73
|
+
|
74
|
+
if (fetch(:psw_repo_debug))
|
75
|
+
debug "Inspecting: #{rel_file}"
|
76
|
+
end
|
77
|
+
if File.directory?(file)
|
78
|
+
execute :mkdir, '-p', "#{fetch(:remote_repo_dir)}/#{rel_file}"
|
79
|
+
elsif rel_file.gsub(/\s+/, "") != "" and rel_file != '.' and rel_file != '..'
|
80
|
+
upload! "#{fetch(:local_repo_dir)}/#{rel_file}", "#{fetch(:remote_repo_dir)}/#{rel_file}"
|
81
|
+
end
|
82
|
+
}
|
83
|
+
Find.find("#{fetch(:local_repo_dir)}").each &func_file_upload
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
desc "Deploy private repository to remote server(s)"
|
88
|
+
task default: [:'local_clone_repo', :'upload_repo'] do
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
# == psw-sidekiq.cap
|
2
|
+
#
|
3
|
+
# The standard sidekiq/capistrano integration (https://github.com/mperham/sidekiq/wiki/Deployment)
|
4
|
+
# doesn't work with Capistrano v3 (https://github.com/cramerdev/capistrano-chef/issues/22),
|
5
|
+
# so this implmenetation bridges the gap.
|
6
|
+
#
|
7
|
+
# == Configuration
|
8
|
+
# The following configuration options may be set (should be set before the 'stop' task is executed):
|
9
|
+
#
|
10
|
+
# before :'psw_sidekiq:stop', :set_sidekiq_options do
|
11
|
+
# set :psw_sidekiq_bundle_cmd, "#{fetch(:rbenv_bundle_cmd)}"
|
12
|
+
# set :psw_sidekiq_instance_cnt, "2"
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# * psw_sidekiq_bundle_cmd
|
16
|
+
# ** Because the 'bundle' command may elsewhere (i.e. rbenv/...), provide the location of the
|
17
|
+
# executable to use
|
18
|
+
# * psw_sidekiq_instance_cnt
|
19
|
+
# ** The number of sidekiq servers to start
|
20
|
+
#
|
21
|
+
# == Tasks
|
22
|
+
#
|
23
|
+
# === psw_sidekiq:start
|
24
|
+
# Starts a specified number of sidekiq servers.
|
25
|
+
#
|
26
|
+
# === psw_sidekiq:stop
|
27
|
+
# Stops all known sidekiq servers (by reviewing the PID files in the 'current' deployment). It
|
28
|
+
# should be noted that this task should run as a'before' hook, so that the 'current' directory
|
29
|
+
# still points to the last run (otherwise the PID files won't exist)
|
30
|
+
#
|
31
|
+
# === psw_sidekiq:restart
|
32
|
+
# Executes the following tasks: stop, start
|
33
|
+
#
|
34
|
+
# == Contact
|
35
|
+
#
|
36
|
+
# Author:: Lexmark International Technology S.A.
|
37
|
+
# Copyright:: 2013 Lexmark International Technology S.A. All rights reserved.
|
38
|
+
# License:: 3-Clause BSD
|
39
|
+
|
40
|
+
require 'find'
|
41
|
+
|
42
|
+
namespace :psw_sidekiq do
|
43
|
+
|
44
|
+
def create_sidekiq_pid_filenames(instance_cnt)
|
45
|
+
|
46
|
+
base_pid_dir="#{fetch(:current_path)}/pids"
|
47
|
+
info "Verifying that directory #{base_pid_dir} exists..."
|
48
|
+
execute :mkdir, '-p', "#{base_pid_dir}"
|
49
|
+
|
50
|
+
info "Requesting #{instance_cnt} sidekiq servers..."
|
51
|
+
pid_file_names = Array.new
|
52
|
+
for idx in 0..(instance_cnt.to_i-1)
|
53
|
+
file_name = get_pid_filename_for_index(idx)
|
54
|
+
info "Adding PID filename: #{file_name}"
|
55
|
+
pid_file_names.push file_name
|
56
|
+
end
|
57
|
+
|
58
|
+
info "Created the following PID filenames: #{pid_file_names}"
|
59
|
+
pid_file_names
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_pid_filename_for_index(idx)
|
63
|
+
base_pid_dir="#{fetch(:current_path)}/pids"
|
64
|
+
"#{base_pid_dir}/sidekiq-#{idx}.pid"
|
65
|
+
end
|
66
|
+
|
67
|
+
desc "Start sidekiq server(s)..."
|
68
|
+
task :start do
|
69
|
+
on roles(:all) do |host|
|
70
|
+
info "Preparing to start sidekiq server(s)..."
|
71
|
+
|
72
|
+
pid_file_names = create_sidekiq_pid_filenames("#{fetch(:psw_sidekiq_instance_cnt, 1)}")
|
73
|
+
|
74
|
+
sidekiq_config_dir="#{fetch(:current_path)}/config"
|
75
|
+
execute :mkdir, '-p', "#{sidekiq_config_dir}"
|
76
|
+
sidekiq_config_file="#{sidekiq_config_dir}/sidekiq.yml"
|
77
|
+
info "Creating configuration file (#{sidekiq_config_file})..."
|
78
|
+
execute :touch, "", "#{sidekiq_config_file}"
|
79
|
+
|
80
|
+
sidekiq_log_dir="#{fetch(:current_path)}/log"
|
81
|
+
execute :mkdir, '-p', "#{sidekiq_log_dir}"
|
82
|
+
sidekiq_log_file="#{sidekiq_log_dir}/sidekiq.log"
|
83
|
+
info "Creating log file (#{sidekiq_log_file})..."
|
84
|
+
execute :rm, '-rf', "#{sidekiq_log_file}"
|
85
|
+
execute :touch, "", "#{sidekiq_log_file}"
|
86
|
+
|
87
|
+
idx = 0
|
88
|
+
for pid_file in pid_file_names do
|
89
|
+
info "Starting sidekiq server (#{pid_file})..."
|
90
|
+
execute :touch, "", "#{pid_file}"
|
91
|
+
|
92
|
+
sidekiq_command="#{fetch(:psw_sidekiq_bundle_cmd)} exec sidekiq"
|
93
|
+
rails_env = fetch(:rails_env, "production")
|
94
|
+
start_command="cd #{current_path} && nohup #{sidekiq_command} -d -e #{rails_env} -i #{idx} -P #{pid_file} -L #{sidekiq_log_file} >> #{sidekiq_log_file} 2>&1"
|
95
|
+
info "Executing command: #{start_command}"
|
96
|
+
|
97
|
+
execute :cd, "#{current_path}", "&& sudo nohup #{sidekiq_command} -d -e #{rails_env} -i #{idx} -P #{pid_file} -L #{sidekiq_log_file} >> #{sidekiq_log_file} 2>&1"
|
98
|
+
|
99
|
+
idx = idx + 1
|
100
|
+
end
|
101
|
+
|
102
|
+
info "Finished starting all sidekiq server(s)"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
desc "Stop sidekiq server(s)..."
|
107
|
+
task :stop do
|
108
|
+
on roles(:all) do |host|
|
109
|
+
info "Looking for any running sidekiq server(s)..."
|
110
|
+
|
111
|
+
#shouldn't possibly have more than 50 sidekiqs running...
|
112
|
+
continue_pid_search = true
|
113
|
+
idx = 0
|
114
|
+
while continue_pid_search
|
115
|
+
begin
|
116
|
+
pid_file = get_pid_filename_for_index(idx)
|
117
|
+
if test("[ -f #{pid_file} ]")
|
118
|
+
info "Stopping sidekiq server for PID file #{pid_file}..."
|
119
|
+
execute :cat, "", "#{pid_file}"
|
120
|
+
|
121
|
+
begin
|
122
|
+
sudo :kill, "-0", "$(cat #{pid_file})"
|
123
|
+
sidekiq_command="#{fetch(:psw_sidekiq_bundle_cmd)} exec sidekiqctl"
|
124
|
+
execute :cd, "#{current_path}", "&& sudo #{sidekiq_command} stop #{pid_file} 10"
|
125
|
+
rescue
|
126
|
+
info "An error occurred stopping #{pid_file}. Cleaning up remaining artifacts..."
|
127
|
+
end
|
128
|
+
|
129
|
+
execute :rm, "-rf", "#{pid_file}"
|
130
|
+
else
|
131
|
+
#if the next file in the PID sequence doesn't exist, we're done
|
132
|
+
continue_pid_search = false
|
133
|
+
end
|
134
|
+
|
135
|
+
#fail-safe
|
136
|
+
if idx >= 50
|
137
|
+
continue_pid_search = false
|
138
|
+
end
|
139
|
+
ensure
|
140
|
+
idx = idx + 1
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
info "Finished stopping all sidekiq server(s)"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
desc "Restart any sidekiq server(s)..."
|
149
|
+
task :restart do
|
150
|
+
#force a re-execution
|
151
|
+
Rake::Task['psw_sidekiq:stop'].reenable
|
152
|
+
invoke :'psw_sidekiq:stop'
|
153
|
+
|
154
|
+
#force a re-execution
|
155
|
+
Rake::Task['psw_sidekiq:start'].reenable
|
156
|
+
invoke :'psw_sidekiq:start'
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "rake"
|
2
|
+
require File.expand_path('../spec_helper.rb', __FILE__)
|
3
|
+
|
4
|
+
|
5
|
+
describe "psw_repo:" do
|
6
|
+
describe "default" do
|
7
|
+
let(:rake) { Rake::Application.new }
|
8
|
+
subject { rake["psw_repo:default"] }
|
9
|
+
|
10
|
+
before do
|
11
|
+
Rake.application = rake
|
12
|
+
Rake.application.add_import("./resources/lib/capistrano/tasks/psw-repo.cap")
|
13
|
+
Rake.application.load_imports()
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has 'local_clone_repo' as a prerequisite" do
|
17
|
+
subject.prerequisites.should include('local_clone_repo')
|
18
|
+
#subject.invoke
|
19
|
+
end
|
20
|
+
|
21
|
+
it "has 'upload_repo' as a prerequisite" do
|
22
|
+
subject.prerequisites.should include('upload_repo')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "local_clone_repo" do
|
27
|
+
let(:rake) { Rake::Application.new }
|
28
|
+
subject { rake["psw_repo:local_clone_repo"] }
|
29
|
+
|
30
|
+
before do
|
31
|
+
Rake.application = rake
|
32
|
+
Rake.application.add_import("./resources/lib/capistrano/tasks/psw-repo.cap")
|
33
|
+
Rake.application.load_imports()
|
34
|
+
end
|
35
|
+
|
36
|
+
it "has 'no prerequisites" do
|
37
|
+
subject.prerequisites.should be_empty
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "upload_repo" do
|
42
|
+
let(:rake) { Rake::Application.new }
|
43
|
+
subject { rake["psw_repo:upload_repo"] }
|
44
|
+
|
45
|
+
before do
|
46
|
+
Rake.application = rake
|
47
|
+
Rake.application.add_import("./resources/lib/capistrano/tasks/psw-repo.cap")
|
48
|
+
Rake.application.load_imports()
|
49
|
+
end
|
50
|
+
|
51
|
+
it "has 'no prerequisites" do
|
52
|
+
subject.prerequisites.should be_empty
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "rake"
|
2
|
+
require File.expand_path('../spec_helper.rb', __FILE__)
|
3
|
+
|
4
|
+
|
5
|
+
describe "psw_sidekiq:" do
|
6
|
+
describe "restart" do
|
7
|
+
let(:rake) { Rake::Application.new }
|
8
|
+
subject { rake["psw_sidekiq:restart"] }
|
9
|
+
|
10
|
+
before do
|
11
|
+
Rake.application = rake
|
12
|
+
Rake.application.add_import("./resources/lib/capistrano/tasks/psw-sidekiq.cap")
|
13
|
+
Rake.application.load_imports()
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has 'no prerequisites" do
|
17
|
+
subject.prerequisites.should be_empty
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "start" do
|
22
|
+
let(:rake) { Rake::Application.new }
|
23
|
+
subject { rake["psw_sidekiq:start"] }
|
24
|
+
|
25
|
+
before do
|
26
|
+
Rake.application = rake
|
27
|
+
Rake.application.add_import("./resources/lib/capistrano/tasks/psw-sidekiq.cap")
|
28
|
+
Rake.application.load_imports()
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has 'no prerequisites" do
|
32
|
+
subject.prerequisites.should be_empty
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "stop" do
|
37
|
+
let(:rake) { Rake::Application.new }
|
38
|
+
subject { rake["psw_sidekiq:stop"] }
|
39
|
+
|
40
|
+
before do
|
41
|
+
Rake.application = rake
|
42
|
+
Rake.application.add_import("./resources/lib/capistrano/tasks/psw-sidekiq.cap")
|
43
|
+
Rake.application.load_imports()
|
44
|
+
end
|
45
|
+
|
46
|
+
it "has 'no prerequisites" do
|
47
|
+
subject.prerequisites.should be_empty
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
class Object
|
2
|
+
def fetch(key, default=nil)
|
3
|
+
@env_vars = Hash.new unless @env_vars != nil
|
4
|
+
@env_vars[key]
|
5
|
+
end
|
6
|
+
|
7
|
+
def set(key, value)
|
8
|
+
@env_vars = Hash.new unless @env_vars != nil
|
9
|
+
@env_vars[key] = value
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
#module SharedTestMethods
|
14
|
+
# def get_auth_header
|
15
|
+
|
16
|
+
# expiration = Time.now.to_i + 1000
|
17
|
+
# peppr_token = PepprAuthToken.build_token_from_oauth_provider("access_token=1/fFBGRNJru1FQd44AzqT3Zg&email=matt.sawka@perceptivesoftware.com&expiration=#{expiration}")
|
18
|
+
# "OAuth #{peppr_token.get_token_string}"
|
19
|
+
# end
|
20
|
+
#end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-psw
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.pre
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lexmark International Technology S.A
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
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: This gem contains code deployment and system management tasks that can
|
56
|
+
be utilized with Capistrano v3
|
57
|
+
email:
|
58
|
+
- matt.sawka@perceptivesoftware.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- .ruby-version
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- capistrano-psw.gemspec
|
70
|
+
- lib/capistrano/psw.rb
|
71
|
+
- lib/capistrano/psw/task_loader.rb
|
72
|
+
- lib/capistrano/psw/version.rb
|
73
|
+
- resources/lib/capistrano/tasks/psw-repo.cap
|
74
|
+
- resources/lib/capistrano/tasks/psw-sidekiq.cap
|
75
|
+
- spec/psw-repo_spec.rb
|
76
|
+
- spec/psw-sidekiq_spec.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
homepage: http://www.perceptivesoftware.com/
|
79
|
+
licenses:
|
80
|
+
- 3-Clause BSD
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
- resources/lib/capistrano/tasks
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>'
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.3.1
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.0.3
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Contains Capistrano v3 Deployment Tasks
|
103
|
+
test_files:
|
104
|
+
- spec/psw-repo_spec.rb
|
105
|
+
- spec/psw-sidekiq_spec.rb
|
106
|
+
- spec/spec_helper.rb
|