capsum 0.8.8 → 0.9.0

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: 474181d7fcc90d4c85d4f958e6f0280693dc9497
4
- data.tar.gz: 7e7873cfafb18e5d9179368225b5074ea8ab1306
3
+ metadata.gz: ec67b573af714877258fb710ad60c5a71ae75744
4
+ data.tar.gz: 3a6eb08c0689f689d62245b40c4ca54455326cd4
5
5
  SHA512:
6
- metadata.gz: 618c907205af578f7532c3063d297be84bf180b96608258610ef86ae8f9cd32fca3b10609768b776c20921832446e8010865f1561deeb52c16223ac40341d8b6
7
- data.tar.gz: 909ed7705e5b31604b8b9801170941f3df025224b02ee3803cbff59c8f2160a0f4eb31f012c63c2d6e751b32c0c49e093d1317377ac08219dd50fd8ef89b1416
6
+ metadata.gz: 6ac3efa87dd7875444a0b3e84867504ad0093d57803df51447192f6ef454fcefa4f4311e8d0d1a48fdda97a856466dc0baff767d770591c50c5bba27883bace7
7
+ data.tar.gz: e1cc5be6b0ff43510bd2ba7c51d23b73f9b9425cd3d22ab896d907e3a02ce1709d50dc1438ac926c5a914844962776627758c5f60fe832902ca232d0a6d947e1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.8
1
+ 0.9.0
@@ -0,0 +1,44 @@
1
+ require File.expand_path("../../capsum.rb", __FILE__)
2
+ require File.expand_path("../whenever.rb", __FILE__)
3
+
4
+ Capistrano::Configuration.instance(true).load do
5
+
6
+ _cset(:autostart_server_commands, {})
7
+ _cset(:autostart_schedule_file) { "schedule.daemons.rb" }
8
+ _cset(:autostart_identifier) { "#{deploy_to}#daemons" }
9
+ _cset(:autostart_whenever_update_command) { "#{whenever_command} --update-crontab #{autostart_identifier} --load-file #{autostart_schedule_file}" }
10
+ _cset(:autostart_whenever_clear_command) { "#{whenever_command} --clear-crontab #{autostart_identifier} --load-file /dev/null; true" }
11
+ _cset(:autostart_whenever_command) { "if [ -e #{autostart_schedule_file} ]; then #{autostart_whenever_update_command}; else #{autostart_whenever_clear_command}; fi" }
12
+
13
+ namespace :autostart do
14
+ task :update_crontab do
15
+ on_rollback do
16
+ if fetch(:previous_release)
17
+ run "cd #{previous_release} && #{autostart_whenever_command}"
18
+ else
19
+ run "cd #{release_path} && #{autostart_whenever_clear_command}"
20
+ end
21
+ end
22
+
23
+ autostart_server_commands.each_pair do |server, commands|
24
+ next if commands.empty?
25
+ schedule_content=<<-EOF
26
+ every(:reboot) do
27
+ #{commands.map{ |cmd| " command #{cmd.inspect}" }.join("\n")}
28
+ end
29
+ EOF
30
+
31
+ top.put schedule_content, File.join(release_path, autostart_schedule_file), hosts: server.host
32
+ end
33
+ run "cd #{release_path} && #{autostart_whenever_command}"
34
+ end
35
+
36
+ task :rollback do
37
+ run "cd #{previous_release} && #{autostart_whenever_command}"
38
+ end
39
+ end
40
+
41
+ before "deploy:finalize_update", "autostart:update_crontab"
42
+ after "deploy:rollback", "autostart:rollback"
43
+ end
44
+
@@ -1,4 +1,5 @@
1
1
  require File.expand_path("../../capsum.rb", __FILE__)
2
+ require File.expand_path("../autostart.rb", __FILE__)
2
3
 
3
4
  Capistrano::Configuration.instance(true).load do
4
5
 
@@ -27,48 +28,19 @@ Capistrano::Configuration.instance(true).load do
27
28
  daemons.start
28
29
  end
29
30
 
30
- desc "install daemons to cron"
31
- task :update_cron, :roles => :app do
31
+ desc "setup daemons to autostart"
32
+ task :setup_autostart, :roles => :app do
33
+ autostart_server_commands = fetch(:autostart_server_commands)
34
+
32
35
  find_servers(:roles => :app).each do |server|
36
+ autostart_server_commands[server] ||= []
33
37
 
34
- identifier = "#{deploy_to}#daemons"
35
- schedule_file_path = "%{schedule_dir}/schedule.daemons.rb"
36
-
37
- whenever_clear_command = "if [ type whenever > /dev/null 2>&1 ]; then whenever --clear-crontab #{identifier} --load-file /dev/null; fi"
38
- whenever_update_command = "whenever --update-crontab #{identifier} --load-file #{schedule_file_path}"
39
-
40
- command = "if [ -e #{schedule_file_path} ]; then #{whenever_update_command}; else #{whenever_clear_command}; fi"
41
-
42
- # on_rollback do
43
- # schedule_dir = fetch(:previous_release) || release_path
44
- # run (command % { :schedule_dir => schedule_dir }), :hosts => server.host
45
- # end
46
-
47
- matcher = server.options[:daemons]
48
- daemon_commands = daemon_list.map do |daemon|
49
- "cd #{current_path}; #{daemon[:start]}" if match(matcher, daemon)
50
- end.compact
51
-
52
- if !daemon_commands.empty?
53
- schedule_content=<<-EOF
54
- every(:reboot) do
55
- #{daemon_commands.map{ |cmd| " command #{cmd.inspect}" }.join("\n")}
56
- end
57
- EOF
58
- top.put schedule_content, (schedule_file_path % { :schedule_dir => release_path }), :hosts => server.host
38
+ daemon_list.each do |daemon|
39
+ autostart_server_commands[server] << "cd #{current_path}; #{daemon[:start]}" if match(matcher, daemon)
59
40
  end
60
-
61
- run (command % { :schedule_dir => release_path }), :hosts => server.host
62
41
  end
63
42
  end
64
43
 
65
- after "deploy:create_symlink", "daemons:update_cron"
66
- after "deploy:rollback", "daemons:update_cron"
67
-
68
- after "deploy:start", "daemons:start"
69
- after "deploy:stop", "daemons:stop"
70
- after "deploy:restart", "daemons:restart"
71
-
72
44
  def match(matcher, daemon)
73
45
  return matcher.call(daemon[:name]) if matcher.respond_to?(:call)
74
46
  return matcher.match(daemon[:name]) if matcher.respond_to?(:match)
@@ -109,5 +81,10 @@ EOF
109
81
  end
110
82
  end
111
83
 
84
+ before "autostart:update_crontab", "daemons:setup_autostart"
85
+
86
+ after "deploy:start", "daemons:start"
87
+ after "deploy:stop", "daemons:stop"
88
+ after "deploy:restart", "daemons:restart"
112
89
  end
113
90
 
@@ -0,0 +1,23 @@
1
+ require File.expand_path("../../capsum.rb", __FILE__)
2
+ require File.expand_path("../autostart.rb", __FILE__)
3
+ require 'sidekiq/capistrano'
4
+
5
+
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 &"
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ before "autostart:update_crontab", "sidekiq:setup_autostart"
23
+ end
@@ -1,38 +1,13 @@
1
1
  require File.expand_path("../../capsum.rb", __FILE__)
2
2
 
3
- Capistrano::Configuration.instance(true).load do
4
- namespace :whenever do
5
- desc 'Update the crontab'
6
- task :update do
7
- identifier = fetch(:whenever_identifier, deploy_to)
8
- find_servers(:roles => :app).each do |server|
9
- whenever_settings = server.options[:whenever]
10
- if whenever_settings
11
- variables = whenever_settings.to_s
12
- if whenever_settings.is_a?(Hash)
13
- variables = whenever_settings.map{ |key, value| "#{key}=#{value}" }.join("&")
14
- end
15
-
16
- command = "if [ -e #{current_path}/config/schedule.rb ]; then cd #{current_path}; RAILS_ENV=#{rails_env} #{whenever_bin} --update-crontab #{identifier} --set \"environment=#{rails_env}&%s\"; fi"
17
- run (command % variables), :hosts => server.host
18
- end
19
- end
20
- end
21
-
22
- desc 'Cleanup the crontab'
23
- task :cleanup, :roles => :app do
24
- identifier = fetch(:whenever_identifier, deploy_to)
25
- run "if [ -e #{current_path}/config/schedule.rb ]; then cd #{current_path}; RAILS_ENV=#{rails_env} #{whenever_bin} --update-crontab #{identifier} --load-file /dev/null; fi"
26
- end
3
+ begin
4
+ require "whenever/capistrano"
5
+ rescue LoadError => e
6
+ # skip
7
+ end
27
8
 
28
- def whenever_bin
29
- if fetch(:use_bundle, false)
30
- "bundle exec whenever"
31
- else
32
- "whenever"
33
- end
34
- end
35
- end
36
-
37
- after "deploy:create_symlink", "whenever:update"
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 }
38
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capsum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.8
4
+ version: 0.9.0
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-11 00:00:00.000000000 Z
11
+ date: 2013-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -81,6 +81,7 @@ files:
81
81
  - VERSION
82
82
  - capsum.gemspec
83
83
  - lib/capsum.rb
84
+ - lib/capsum/autostart.rb
84
85
  - lib/capsum/bundler.rb
85
86
  - lib/capsum/cache.rb
86
87
  - lib/capsum/daemons.rb
@@ -89,6 +90,7 @@ files:
89
90
  - lib/capsum/passenger.rb
90
91
  - lib/capsum/setup.rb
91
92
  - lib/capsum/shared.rb
93
+ - lib/capsum/sidekiq.rb
92
94
  - lib/capsum/typical.rb
93
95
  - lib/capsum/whenever.rb
94
96
  homepage: http://github.com/sunteya/capsum