capsum 0.9.1 → 1.0.0.alpha1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b848587f332b5fcfe34feb23a40bb34270f8715
4
- data.tar.gz: c9cedc10c9ba1c672e8eb1abd052bd342edba794
3
+ metadata.gz: a5b60107345d838c120162111e8a6dd611ba65cd
4
+ data.tar.gz: b8386fe0edcb617f99a9923939feb2650adc8c79
5
5
  SHA512:
6
- metadata.gz: 20f28f834d76f3aa3cdde02e4b4841fb5046c167080e19f4cc7ad245a499703101aee5df4dfce41f90dc475bb91e723986b4824e1f4aebaf8231ad1a8d8ddf4f
7
- data.tar.gz: ee653434d63d97dc4ab89e760c7efcb76b20c40381918c335881f521881724d8b7b1481b23a771607714595b82bd9cc0abbd88ee3a582ea0213b8f8a95e01079
6
+ metadata.gz: b9140dc0624a5401dcceab5b1eed05cd24e1e9bdbb3064d143f9f9709416237f5a37a649d73f49d949ad5cbbecef0ca3a0c3e5ed0d4495c7dd342525afca1268
7
+ data.tar.gz: feb0892470f529e79d7dcd4a0d54e33999709f6ffe990fde2df47f0fc453a7f5f79b2957386ba96a434b5616778260715b9ae4d4e8f7cbb8183903e32003914d
data/CHANGELOG.md CHANGED
@@ -1,12 +1,24 @@
1
1
  ## TODO:
2
-
3
- ## v0.6.0:
4
2
 
5
- - bundler only run on exist gemfile
6
- - add rails cache clear recipe
3
+ ## v1.0:
4
+ - upgrade capistrano to v3, v2 is not compatible
7
5
 
8
- ## v0.5.0:
6
+ ## v0.9:
7
+ - use the official whenever recipe
8
+ - add sidekiq recipe support autostart
9
9
 
10
- - add git recipe, support use current project's branch
11
- - change typical recipe, now set :deploy_via, :copy
12
-
10
+ ## v0.8:
11
+ - auto detect git setting by project git config
12
+ - always invoke deploy:cleanup after deploy:update
13
+ - support http_proxy variables
14
+
15
+ ## v0.7:
16
+ - add daemons recipe
17
+
18
+ ## v0.6:
19
+ - bundler only run on exist gemfile
20
+ - add rails cache clear recipe
21
+
22
+ ## v0.5:
23
+ - add git recipe, support use current project's branch
24
+ - change typical recipe, now set :deploy_via, :copy
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.1
1
+ 1.0.0.alpha1
data/capsum.gemspec CHANGED
@@ -14,10 +14,14 @@ Gem::Specification.new do |s|
14
14
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
15
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
16
  s.require_paths = ["lib"]
17
-
17
+ s.license = 'MIT'
18
18
 
19
19
  # Dependency Gems
20
- s.add_dependency "capistrano", "~> 2.15.3"
20
+ s.add_dependency "capistrano", "~> 3.1"
21
+ # s.add_dependency "capistrano-rsync", "~> 1.0.2" # broken, wait update
22
+ s.add_dependency "capistrano-rails", "~> 1.1.1"
23
+ s.add_development_dependency "capistrano-sidekiq", "~> 0.1.3" # optional
24
+
21
25
  # s.add_dependency "capistrano-helpers", "~> 0.7.1"
22
26
  # s.add_dependency "cap-recipes", "~> 0.3.36"
23
27
  # https://github.com/rubaidh/rubaidhstrano
@@ -0,0 +1,98 @@
1
+ # NOTE: Please don't depend on tasks without a description (`desc`) as they
2
+ # might change between minor or patch version releases. They make up the
3
+ # private API and internals of Capistrano::Rsync. If you think something should
4
+ # be public for extending and hooking, please let me know!
5
+
6
+ rsync_cache = lambda do
7
+ cache = fetch(:rsync_cache)
8
+ cache = deploy_to + "/" + cache if cache && cache !~ /^\//
9
+ cache
10
+ end
11
+
12
+ # PATCH https://github.com/moll/capistrano-rsync/pull/13
13
+ # Use cap3's load:defaults to set default vars so that they can be overridden.
14
+ namespace :load do
15
+ task :defaults do
16
+ set :rsync_options, %w[--recursive --delete --delete-excluded --exclude .git*]
17
+ set :rsync_copy, "rsync --archive --acls --xattrs"
18
+
19
+ # Stage is used on your local machine for rsyncing from.
20
+ set :rsync_stage, "tmp/deploy"
21
+
22
+ # Cache is used on the server to copy files to from to the release
23
+ # directory. Saves you rsyncing your whole app folder each time. If you nil
24
+ # rsync_cache, Capistrano::Rsync will sync straight to the release path.
25
+ set :rsync_cache, "shared/deploy"
26
+ end
27
+ end
28
+
29
+
30
+ Rake::Task["deploy:check"].enhance ["rsync:hook_scm"]
31
+ Rake::Task["deploy:updating"].enhance ["rsync:hook_scm"]
32
+
33
+ desc "Stage and rsync to the server (or its cache)."
34
+ task :rsync => %w[rsync:stage] do
35
+ roles(:all).each do |role|
36
+ user = role.user + "@" if !role.user.nil?
37
+
38
+ rsync = %w[rsync]
39
+ rsync.concat fetch(:rsync_options)
40
+ rsync << fetch(:rsync_stage) + "/"
41
+ rsync << "#{user}#{role.hostname}:#{rsync_cache.call || release_path}"
42
+
43
+ Kernel.system *rsync
44
+ end
45
+ end
46
+
47
+ namespace :rsync do
48
+ task :hook_scm do
49
+ Rake::Task.define_task("#{scm}:check") do
50
+ invoke "rsync:check"
51
+ end
52
+
53
+ Rake::Task.define_task("#{scm}:create_release") do
54
+ invoke "rsync:release"
55
+ end
56
+ end
57
+
58
+ task :check do
59
+ # Everything's a-okay inherently!
60
+ end
61
+
62
+ task :create_stage do
63
+ next if File.directory?(fetch(:rsync_stage))
64
+
65
+ clone = %W[git clone]
66
+ clone << fetch(:repo_url, ".")
67
+ clone << fetch(:rsync_stage)
68
+ run_locally { execute *clone }
69
+ end
70
+
71
+ desc "Stage the repository in a local directory."
72
+ task :stage => %w[create_stage] do
73
+ Dir.chdir fetch(:rsync_stage) do
74
+ update = %W[git fetch --quiet --all --prune]
75
+ run_locally { execute *update }
76
+
77
+ checkout = %W[git reset --hard origin/#{fetch(:branch)}]
78
+ run_locally { execute *checkout }
79
+
80
+ # PATCH https://github.com/moll/capistrano-rsync/pull/8
81
+ set :current_revision, "#{`git rev-parse --short HEAD`}".chomp
82
+ end
83
+ end
84
+
85
+ desc "Copy the code to the releases directory."
86
+ task :release => %w[rsync] do
87
+ # Skip copying if we've already synced straight to the release directory.
88
+ next if !fetch(:rsync_cache)
89
+
90
+ copy = %(#{fetch(:rsync_copy)} "#{rsync_cache.call}/" "#{release_path}/")
91
+ on roles(:all).each do execute copy end
92
+ end
93
+
94
+ # Matches the naming scheme of git tasks.
95
+ # Plus was part of the public API in Capistrano::Rsync <= v0.2.1.
96
+ task :create_release => %w[release]
97
+ end
98
+
data/lib/capsum.rb CHANGED
@@ -1,31 +1,31 @@
1
- require "capistrano"
1
+ # require "capistrano"
2
2
 
3
3
  module Capsum
4
4
  VERSION = open(File.expand_path("../../VERSION", __FILE__)).read.chomp
5
5
  end
6
6
 
7
- Capistrano::Configuration.instance(true).load do
7
+ # Capistrano::Configuration.instance(true).load do
8
8
 
9
- def self.unbefore(task_name, name)
10
- options = { :only => [ task_name ] }
11
- unon :before, name, options
12
- end
9
+ # def self.unbefore(task_name, name)
10
+ # options = { :only => [ task_name ] }
11
+ # unon :before, name, options
12
+ # end
13
13
 
14
- def self.unafter(task_name, name)
15
- options = { :only => [ task_name ] }
16
- unon :after, name, options
17
- end
14
+ # def self.unafter(task_name, name)
15
+ # options = { :only => [ task_name ] }
16
+ # unon :after, name, options
17
+ # end
18
18
 
19
- def self.unon(event, name, options)
20
- self.callbacks[event].delete_if do |callback|
21
- do_delete = false
22
- if callback.respond_to?(:source)
23
- do_delete = (name == callback.source)
24
- do_delete &&= (options[:only] && options[:only] == callback.only)
25
- end
19
+ # def self.unon(event, name, options)
20
+ # self.callbacks[event].delete_if do |callback|
21
+ # do_delete = false
22
+ # if callback.respond_to?(:source)
23
+ # do_delete = (name == callback.source)
24
+ # do_delete &&= (options[:only] && options[:only] == callback.only)
25
+ # end
26
26
 
27
- do_delete
28
- end
29
- end
27
+ # do_delete
28
+ # end
29
+ # end
30
30
 
31
- end
31
+ # end
@@ -1,9 +1,19 @@
1
- require File.expand_path("../../capsum.rb", __FILE__)
2
- require "bundler/capistrano"
1
+ require "capistrano/bundler"
3
2
 
4
- Capistrano::Configuration.instance(true).load do
5
- set :bundle_dir, nil
6
- set :bundle_flags, "--quiet"
3
+ namespace :load do
4
+ task :defaults do
5
+ set :bundle_flags, '--quiet'
6
+ set :bundle_env_variables, {}
7
7
 
8
- set :use_bundle, true
8
+ bundle_env_variables[:http_proxy] = ENV["bundle_http_proxy"] if ENV["bundle_http_proxy"]
9
+ bundle_env_variables[:https_proxy] = ENV["bundle_https_proxy"] if ENV["bundle_https_proxy"]
10
+ end
11
+ end
12
+
13
+ module Capistrano
14
+ module DSL
15
+ def bundle_env_variables
16
+ fetch(:bundle_env_variables)
17
+ end
18
+ end
9
19
  end
@@ -1,91 +1,152 @@
1
1
  require File.expand_path("../../capsum.rb", __FILE__)
2
- require File.expand_path("../autostart.rb", __FILE__)
2
+ # require File.expand_path("../autostart.rb", __FILE__)
3
3
 
4
- Capistrano::Configuration.instance(true).load do
5
-
6
- namespace :daemons do
7
- desc "Start daemons process"
8
- task :start, :roles => :app do
9
- find_servers(:roles => :app).each do |server|
10
- matcher = server.options[:daemons]
11
- daemon_list.each do |daemon|
12
- run "cd #{current_path}; #{daemon[:start]}", :pty => (daemon[:pty] || false), :hosts => server.host if match(matcher, daemon)
13
- end
4
+ namespace :load do
5
+ task :defaults do
6
+ set :daemons, []
7
+ set :daemon_list, []
8
+ end
9
+ end
10
+
11
+
12
+ namespace :daemons do
13
+ task :prepare do
14
+ # TODO: covert daemons to daemon_list
15
+ end
16
+
17
+ task upload_daemons: [ :prepare ] do
18
+ fetch(:daemon_list).each do |daemon|
19
+ script_path = release_path.join("daemons", daemon[:name])
20
+ content = convert_daemon_script(daemon)
21
+
22
+ on roles (daemon[:role] || :all) do |host|
23
+ execute :mkdir, "-pv", script_path.dirname
24
+ upload! StringIO.new(content), script_path
25
+ execute :chmod, "+x", script_path
14
26
  end
15
27
  end
28
+ end
29
+
30
+ def convert_daemon_script(daemon)
31
+ strip_heredoc <<-EOF
32
+ #!/usr/bin/env bash
33
+
34
+ start(){
35
+ #{daemon[:start]}
36
+ }
37
+
38
+ stop(){
39
+ #{daemon[:stop]}
40
+ }
41
+
42
+ usage(){
43
+ echo "Usage: $(basename $0) {stop|stop}"
44
+ }
45
+
46
+ command=${1:-usage}
47
+ shift
48
+ case "$command" in
49
+ start) start $@ ;;
50
+ stop) stop $@ ;;
51
+ *) usage ;;
52
+ esac
53
+ EOF
54
+ end
55
+
56
+ def strip_heredoc(str)
57
+ indent = (str.scan(/^[ \t]*(?=\S)/).min || "").size
58
+ str.gsub(/^[ \t]{#{indent}}/, '')
59
+ end
60
+
61
+ after 'deploy:updated', :upload_daemons
62
+ end
63
+
64
+
65
+ # Capistrano::Configuration.instance(true).load do
66
+
67
+ # namespace :daemons do
68
+ # desc "Start daemons process"
69
+ # task :start, :roles => :app do
70
+ # find_servers(:roles => :app).each do |server|
71
+ # matcher = server.options[:daemons]
72
+ # daemon_list.each do |daemon|
73
+ # run "cd #{current_path}; #{daemon[:start]}", :pty => (daemon[:pty] || false), :hosts => server.host if match(matcher, daemon)
74
+ # end
75
+ # end
76
+ # end
16
77
 
17
- desc "Stop daemons process"
18
- task :stop, :roles => :app do
19
- daemon_list.each do |daemon|
20
- run "cd #{current_path}; #{daemon[:stop]}"
21
- end
22
- end
78
+ # desc "Stop daemons process"
79
+ # task :stop, :roles => :app do
80
+ # daemon_list.each do |daemon|
81
+ # run "cd #{current_path}; #{daemon[:stop]}"
82
+ # end
83
+ # end
23
84
 
24
- desc "Restart daemons process"
25
- task :restart, :roles => :app do
26
- daemons.stop
27
- sleep(3)
28
- daemons.start
29
- end
85
+ # desc "Restart daemons process"
86
+ # task :restart, :roles => :app do
87
+ # daemons.stop
88
+ # sleep(3)
89
+ # daemons.start
90
+ # end
30
91
 
31
- desc "setup daemons to autostart"
32
- task :setup_autostart, :roles => :app do
33
- autostart_server_commands = fetch(:autostart_server_commands)
92
+ # desc "setup daemons to autostart"
93
+ # task :setup_autostart, :roles => :app do
94
+ # autostart_server_commands = fetch(:autostart_server_commands)
34
95
 
35
- find_servers(:roles => :app).each do |server|
36
- matcher = server.options[:daemons]
37
- autostart_server_commands[server] ||= []
96
+ # find_servers(:roles => :app).each do |server|
97
+ # matcher = server.options[:daemons]
98
+ # autostart_server_commands[server] ||= []
38
99
 
39
- daemon_list.each do |daemon|
40
- autostart_server_commands[server] << "cd #{current_path}; #{daemon[:start]}" if match(matcher, daemon)
41
- end
42
- end
43
- end
100
+ # daemon_list.each do |daemon|
101
+ # autostart_server_commands[server] << "cd #{current_path}; #{daemon[:start]}" if match(matcher, daemon)
102
+ # end
103
+ # end
104
+ # end
44
105
 
45
- def match(matcher, daemon)
46
- return matcher.call(daemon[:name]) if matcher.respond_to?(:call)
47
- return matcher.match(daemon[:name]) if matcher.respond_to?(:match)
106
+ # def match(matcher, daemon)
107
+ # return matcher.call(daemon[:name]) if matcher.respond_to?(:call)
108
+ # return matcher.match(daemon[:name]) if matcher.respond_to?(:match)
48
109
 
49
- !!matcher # to boolean
50
- end
110
+ # !!matcher # to boolean
111
+ # end
51
112
 
52
- def daemon_list
53
- settings = fetch(:daemons, [])
113
+ # def daemon_list
114
+ # settings = fetch(:daemons, [])
54
115
 
55
- case settings
56
- when Array
57
- settings.map { |setting| parse_daemon(setting) }
58
- when Hash
59
- settings.map { |pair| parse_daemon(pair[1], :name => pair[0] )}
60
- else
61
- [ parse_daemon(settings) ]
62
- end
63
- end
116
+ # case settings
117
+ # when Array
118
+ # settings.map { |setting| parse_daemon(setting) }
119
+ # when Hash
120
+ # settings.map { |pair| parse_daemon(pair[1], :name => pair[0] )}
121
+ # else
122
+ # [ parse_daemon(settings) ]
123
+ # end
124
+ # end
64
125
 
65
- def parse_daemon(source, options = {})
66
- daemon = {}
126
+ # def parse_daemon(source, options = {})
127
+ # daemon = {}
67
128
 
68
- case source
69
- when Array
70
- daemon[:start] = source.first
71
- daemon[:stop] = source.last
72
- when Hash
73
- daemon = options.merge(source)
74
- else
75
- command = source.to_s
76
- daemon[:start] = command.gsub("%{command}", "start")
77
- daemon[:stop] = command.gsub("%{command}", "stop")
78
- end
129
+ # case source
130
+ # when Array
131
+ # daemon[:start] = source.first
132
+ # daemon[:stop] = source.last
133
+ # when Hash
134
+ # daemon = options.merge(source)
135
+ # else
136
+ # command = source.to_s
137
+ # daemon[:start] = command.gsub("%{command}", "start")
138
+ # daemon[:stop] = command.gsub("%{command}", "stop")
139
+ # end
79
140
 
80
- daemon[:name] = daemon[:start] if daemon[:name].nil?
81
- daemon
82
- end
83
- end
141
+ # daemon[:name] = daemon[:start] if daemon[:name].nil?
142
+ # daemon
143
+ # end
144
+ # end
84
145
 
85
- before "autostart:update_crontab", "daemons:setup_autostart"
146
+ # before "autostart:update_crontab", "daemons:setup_autostart"
86
147
 
87
- after "deploy:start", "daemons:start"
88
- after "deploy:stop", "daemons:stop"
89
- after "deploy:restart", "daemons:restart"
90
- end
148
+ # after "deploy:start", "daemons:start"
149
+ # after "deploy:stop", "daemons:stop"
150
+ # after "deploy:restart", "daemons:restart"
151
+ # end
91
152
 
@@ -1,17 +1,29 @@
1
1
  require File.expand_path("../../capsum.rb", __FILE__)
2
- require "capistrano/ext/multistage"
3
- require File.expand_path("../setup.rb", __FILE__)
4
2
  require File.expand_path("../git.rb", __FILE__)
5
3
  require File.expand_path("../shared.rb", __FILE__)
4
+ require "capistrano/rsync"
6
5
 
7
- Capistrano::Configuration.instance(true).load do
8
- set :use_sudo, false
6
+ namespace :load do
7
+ task :defaults do
8
+ if spec = Gem.loaded_specs["capistrano-rsync"]
9
+ raise "capsum don't compatible 'capistrano-rsync' gem, please remove capistrano-rsync depend. because it uses a modified version of capistrano-rsync script. "
10
+ end
9
11
 
10
- set :deploy_via, :copy
11
- set :copy_strategy, :export
12
- set :copy_compression, :bz2
13
-
14
- default_environment["http_proxy"] = fetch("http_proxy") if exists?("http_proxy")
15
- default_environment["https_proxy"] = fetch("https_proxy") if exists?("https_proxy")
16
- after "deploy:update", "deploy:cleanup"
12
+ fetch(:linked_files) { set :linked_files, [] }
13
+ fetch(:linked_dirs) { set :linked_dirs, [] }
14
+
15
+ set :scm, :rsync
16
+ set :rsync_options, %w[--recursive --delete]
17
+
18
+ default_env[:http_proxy] = ENV["http_proxy"] if ENV["http_proxy"]
19
+ default_env[:https_proxy] = ENV["https_proxy"] if ENV["https_proxy"]
20
+ end
21
+ end
22
+
23
+ module Capistrano
24
+ module DSL
25
+ def default_env
26
+ fetch(:default_env)
27
+ end
28
+ end
17
29
  end
data/lib/capsum/git.rb CHANGED
@@ -1,18 +1,18 @@
1
- require File.expand_path("../../capsum.rb", __FILE__)
1
+ # require File.expand_path("../../capsum.rb", __FILE__)
2
2
 
3
- Capistrano::Configuration.instance(true).load do
4
-
5
- set :scm, "git"
6
-
7
- # use current branch
8
- set(:branch) { `git describe --contains --all HEAD | tr -d '\n'` }
3
+ namespace :load do
4
+ task :defaults do
5
+ # use current branch
6
+ set :branch, -> { `git describe --contains --all HEAD | tr -d '\n'` }
9
7
 
10
- # use current remote
11
- set(:repository) do
12
- remote = `git config --get branch.#{self.branch}.remote | tr -d '\n'`
13
- `git config --get remote.#{remote}.url | tr -d '\n'`
8
+ # use current remote
9
+ set :repo_url, -> {
10
+ remote = `git config --get branch.#{fetch(:branch)}.remote | tr -d '\n'`
11
+ `git config --get remote.#{remote}.url | tr -d '\n'`
12
+ }
13
+
14
+ set :repo_url, ENV['repo_url'] if ENV['repo_url']
15
+
16
+ # TODO: set :scm_verbose, true
14
17
  end
15
-
16
- set :scm_verbose, true
17
-
18
- end
18
+ end
@@ -1,20 +1,13 @@
1
1
  require File.expand_path("../../capsum.rb", __FILE__)
2
2
 
3
- Capistrano::Configuration.instance(true).load do
4
- namespace :deploy do
5
- desc 'Restart passenger'
6
- task :restart, :roles => :app do
7
- run "touch #{current_path}/tmp/restart.txt"
8
- end
9
-
10
- desc 'Start passenger'
11
- task :start, :roles => :app do
12
- # do nothing
13
- end
14
-
15
- desc 'Stop passenger'
16
- task :stop, :roles => :app do
17
- # do nothing
3
+ namespace :deploy do
4
+ desc 'Restart passenger'
5
+ task :restart do
6
+ on roles(:app), in: :sequence, wait: 5 do
7
+ execute :mkdir, '-pv', release_path.join('tmp')
8
+ execute :touch, release_path.join('tmp/restart.txt')
18
9
  end
19
10
  end
20
- end
11
+
12
+ after :publishing, :restart
13
+ end
data/lib/capsum/shared.rb CHANGED
@@ -1,21 +1,9 @@
1
- require File.expand_path("../../capsum.rb", __FILE__)
2
-
3
- Capistrano::Configuration.instance(true).load do
4
-
5
- namespace :deploy do
6
- desc 'Replace named files with a symlink to their counterparts in shared/'
7
- task :symlink_shared do
8
- if !exists?(:shared)
9
- abort 'You must specify which files to symlink using the "set :shared" command.'
10
- end
11
- shared.each do |path|
12
- if release_path.nil? || release_path.empty? || path.nil? || path.empty?
13
- raise "Release path or path are nil!"
14
- end
15
- run "rm -rf #{release_path}/#{path} && ln -nfs #{shared_path}/#{path} #{release_path}/#{path}"
16
- end
1
+ namespace :capsum do
2
+ task :symlink_shared_deprecated do
3
+ if fetch(:shared)
4
+ raise "set :shared is deprecated. use :linked_files or :linked_dirs instead."
17
5
  end
18
6
  end
19
-
20
- before "deploy:finalize_update", "deploy:symlink_shared"
21
7
  end
8
+
9
+ Rake::Task["deploy:check"].enhance ["capsum:symlink_shared_deprecated"]
@@ -1,23 +1,86 @@
1
1
  require File.expand_path("../../capsum.rb", __FILE__)
2
- require File.expand_path("../autostart.rb", __FILE__)
3
- require 'sidekiq/capistrano'
2
+ require File.expand_path("../daemons.rb", __FILE__)
3
+ require 'capistrano/sidekiq'
4
4
 
5
+ namespace :sidekiq do
6
+ task :update_daemon_list do
7
+ scripts = []
8
+ sidekiq_role = fetch(:sidekiq_role)
9
+ on (roles sidekiq_role || []).first do |host|
10
+ return if host.nil?
11
+ for_each_process do |pid_file, idx|
12
+ start_scripts = SimpleScriptRecord.new do
13
+ start_sidekiq(pid_file)
14
+ end
5
15
 
6
- Capistrano::Configuration.instance(true).load do
7
- namespace :sidekiq do
8
-
9
- desc "setup sidekiq daemon to autostart"
10
- task :setup_autostart do
11
- autostart_server_commands = fetch(:autostart_server_commands)
12
- rails_env = fetch(:rails_env, "production")
13
- find_servers(roles: fetch(:sidekiq_role)).each do |server|
14
- autostart_server_commands[server] ||= []
15
- for_each_process do |pid_file, idx|
16
- autostart_server_commands[server] << "cd #{current_path} ; nohup #{fetch(:sidekiq_cmd)} -e #{rails_env} -C #{current_path}/config/sidekiq.yml -i #{idx} -P #{pid_file} >> #{current_path}/log/sidekiq.log 2>&1 &"
16
+ stop_scripts = SimpleScriptRecord.new do
17
+ stop_sidekiq(pid_file)
17
18
  end
19
+
20
+ scripts << {
21
+ start: start_scripts.to_bash,
22
+ stop: stop_scripts.to_bash,
23
+ pid_file: pid_file
24
+ }
18
25
  end
19
26
  end
27
+
28
+ scripts.each do |script|
29
+ script[:role] = sidekiq_role
30
+ script[:name] = File.basename(script[:pid_file], ".pid") if script[:pid_file]
31
+ end
32
+
33
+ fetch(:daemon_list).concat scripts
20
34
  end
21
35
 
22
- before "autostart:update_crontab", "sidekiq:setup_autostart"
36
+ after 'daemons:prepare', :update_daemon_list
23
37
  end
38
+
39
+ namespace :load do
40
+ task :defaults do
41
+ set :sidekiq_options, "--config config/sidekiq.yml"
42
+ set :sidekiq_role, [ :db, filter: :sidekiq ]
43
+ end
44
+ end
45
+
46
+ class SimpleScriptRecord < SSHKit::Backend::Printer
47
+ attr_accessor :result
48
+
49
+ def initialize(&block)
50
+ @result = []
51
+ @block = block
52
+ self.run
53
+ end
54
+
55
+ def within(directory, &block)
56
+ (@pwd ||= []).push directory.to_s
57
+ yield
58
+ ensure
59
+ @pwd.pop
60
+ end
61
+
62
+ def to_bash
63
+ result.map do |args|
64
+ cmd = []
65
+ options = args.extract_options!
66
+ cmd << "cd #{options[:in]} && " if options[:in]
67
+ cmd << args.join(" ")
68
+
69
+ cmd.join
70
+ end.join("\n")
71
+ end
72
+
73
+ def execute(*args)
74
+ options = args.extract_options!
75
+ options.merge!(in: @pwd.nil? ? nil : File.join(@pwd), env: @env, host: @host, user: @user, group: @group)
76
+ @result << [ *args, options ]
77
+ end
78
+
79
+ def test(*args)
80
+ raise SSHKit::Backend::MethodUnavailableError
81
+ end
82
+
83
+ def command(*args)
84
+ raise SSHKit::Backend::MethodUnavailableError
85
+ end
86
+ end
@@ -1,11 +1,20 @@
1
1
  require File.expand_path("../foundation.rb", __FILE__)
2
2
 
3
3
  require File.expand_path("../bundler.rb", __FILE__)
4
+ require 'capistrano/rails'
5
+
4
6
  require File.expand_path("../passenger.rb", __FILE__)
5
7
  require File.expand_path("../whenever.rb", __FILE__)
6
- require File.expand_path("../daemons.rb", __FILE__)
7
- require File.expand_path("../cache.rb", __FILE__)
8
+ # require File.expand_path("../daemons.rb", __FILE__)
9
+ # require File.expand_path("../cache.rb", __FILE__)
10
+
11
+ namespace :load do
12
+ task :defaults do
13
+ set :rails_env, "production"
8
14
 
9
- Capistrano::Configuration.instance(true).load do
10
- set :rails_env, "production"
11
- end
15
+ fetch(:linked_dirs).concat %w[
16
+ log
17
+ tmp/pids
18
+ ]
19
+ end
20
+ end
@@ -6,8 +6,24 @@ rescue LoadError => e
6
6
  # skip
7
7
  end
8
8
 
9
- Capistrano::Configuration.instance(true).load do
10
- set(:whenever_command) { fetch(:use_bundle, false) ? "#{fetch(:bundle_cmd, 'bundle')} exec whenever" : "whenever" }
11
- set(:whenever_options) { { roles: fetch(:whenever_roles), only: { whenever: true } } }
12
- set(:whenever_identifier) { deploy_to }
9
+ namespace :load do
10
+ task :defaults do
11
+ set(:whenever_identifier, -> { fetch :deploy_to })
12
+ set(:whenever_roles, [ :db, filter: :whenever ])
13
+ end
13
14
  end
15
+
16
+ namespace :whenever do
17
+ def setup_whenever_task(*args, &block)
18
+ args = Array(fetch(:whenever_command)) + args
19
+ on roles fetch(:whenever_roles) do |host|
20
+ return if host.nil?
21
+ host_args = Array(yield(host))
22
+ within release_path do
23
+ with fetch(:whenever_command_environment_variables) do
24
+ execute *(args + host_args)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,69 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capsum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 1.0.0.alpha1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sunteya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-17 00:00:00.000000000 Z
11
+ date: 2014-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.15.3
19
+ version: '3.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.15.3
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: capistrano-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: capistrano-sidekiq
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.3
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rake
29
57
  requirement: !ruby/object:Gem::Requirement
30
58
  requirements:
31
- - - '>='
59
+ - - ">="
32
60
  - !ruby/object:Gem::Version
33
61
  version: '0'
34
62
  type: :development
35
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: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: bundler
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
- - - '>='
73
+ - - ">="
46
74
  - !ruby/object:Gem::Version
47
75
  version: '0'
48
76
  type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
- - - '>='
80
+ - - ">="
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: version
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
- - - '>='
87
+ - - ">="
60
88
  - !ruby/object:Gem::Version
61
89
  version: '0'
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
- - - '>='
94
+ - - ">="
67
95
  - !ruby/object:Gem::Version
68
96
  version: '0'
69
97
  description: Collect gems and recipes related capistrano.
@@ -73,13 +101,14 @@ executables: []
73
101
  extensions: []
74
102
  extra_rdoc_files: []
75
103
  files:
76
- - .gitignore
104
+ - ".gitignore"
77
105
  - CHANGELOG.md
78
106
  - Gemfile
79
107
  - README.md
80
108
  - Rakefile
81
109
  - VERSION
82
110
  - capsum.gemspec
111
+ - lib/capistrano/rsync.rb
83
112
  - lib/capsum.rb
84
113
  - lib/capsum/autostart.rb
85
114
  - lib/capsum/bundler.rb
@@ -88,13 +117,13 @@ files:
88
117
  - lib/capsum/foundation.rb
89
118
  - lib/capsum/git.rb
90
119
  - lib/capsum/passenger.rb
91
- - lib/capsum/setup.rb
92
120
  - lib/capsum/shared.rb
93
121
  - lib/capsum/sidekiq.rb
94
122
  - lib/capsum/typical.rb
95
123
  - lib/capsum/whenever.rb
96
124
  homepage: http://github.com/sunteya/capsum
97
- licenses: []
125
+ licenses:
126
+ - MIT
98
127
  metadata: {}
99
128
  post_install_message:
100
129
  rdoc_options: []
@@ -102,17 +131,17 @@ require_paths:
102
131
  - lib
103
132
  required_ruby_version: !ruby/object:Gem::Requirement
104
133
  requirements:
105
- - - '>='
134
+ - - ">="
106
135
  - !ruby/object:Gem::Version
107
136
  version: '0'
108
137
  required_rubygems_version: !ruby/object:Gem::Requirement
109
138
  requirements:
110
- - - '>='
139
+ - - ">"
111
140
  - !ruby/object:Gem::Version
112
- version: '0'
141
+ version: 1.3.1
113
142
  requirements: []
114
143
  rubyforge_project:
115
- rubygems_version: 2.0.3
144
+ rubygems_version: 2.2.0
116
145
  signing_key:
117
146
  specification_version: 4
118
147
  summary: Collect gems and recipes related capistrano.
data/lib/capsum/setup.rb DELETED
@@ -1,18 +0,0 @@
1
- require File.expand_path("../../capsum.rb", __FILE__)
2
-
3
- Capistrano::Configuration.instance(true).load do
4
- namespace :capsum do
5
- desc 'upload example files to server on deploy:setup'
6
- task :setup do
7
- Dir["**/*.example", "**/*.sample"].each do |source|
8
- target_dir = File.join(shared_path, File.dirname(source))
9
- target_file = File.basename(source, ".*")
10
-
11
- run "mkdir -p '#{target_dir}'"
12
- top.upload(source, File.join(target_dir, target_file))
13
- end
14
- end
15
- end
16
-
17
- after "deploy:setup", "capsum:setup"
18
- end