app-deploy 0.7.1 → 0.7.2

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.
data/CHANGES CHANGED
@@ -1,5 +1,11 @@
1
1
  = app-deploy changes history
2
2
 
3
+ == app-deploy 0.7.2 / 2009-12-21
4
+ * fixed timeout, call to_i on timeout argument.
5
+ * fixed signal:reload taking args
6
+ * moved timeout to be last argument.
7
+ * added AppDeploy.invoke to wrap Task#invoke
8
+
3
9
  == app-deploy 0.7.1 / 2009-12-17
4
10
  * a way better task dependency management
5
11
  * fixed that every task can be only invoked once,
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{app-deploy}
5
- s.version = "0.7.1"
5
+ s.version = "0.7.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Lin Jen-Shin (aka godfat 真常)"]
9
- s.date = %q{2009-12-17}
9
+ s.date = %q{2009-12-21}
10
10
  s.description = %q{ rake tasks for deployment}
11
11
  s.email = %q{godfat (XD) godfat.org}
12
12
  s.extra_rdoc_files = ["CHANGES", "README", "Rakefile", "TODO", "app-deploy.gemspec", "example/Rakefile", "example/bin/install.sh", "example/bin/remote_install.sh", "example/bin/remote_update.sh", "example/bin/start.sh", "example/bin/update.sh", "example/daemon_cluster.yaml", "example/rack_cluster.yaml", "lib/app-deploy/daemon.rake", "lib/app-deploy/deploy.rake", "lib/app-deploy/deprecated/merb.rake", "lib/app-deploy/deprecated/mongrel.rake", "lib/app-deploy/gem.rake", "lib/app-deploy/git.rake", "lib/app-deploy/install.rake", "lib/app-deploy/nginx.rake", "lib/app-deploy/rack.rake", "lib/app-deploy/server.rake", "lib/app-deploy/signal.rake", "lib/app-deploy/thin.rake", "lib/app-deploy/unicorn.rake"]
@@ -83,9 +83,25 @@ namespace :app do
83
83
  [:start, :stop, :restart, :reload].each{ |cmd|
84
84
  desc "#{cmd} nginx(passenger)"
85
85
  task cmd do
86
- Rake::Task["app:nginx:#{cmd}"].invoke(
87
- '/home/app/config/nginx.conf',
88
- '/home/app/nginx/sbin/nginx')
86
+ task = Rake::Task["app:nginx:#{cmd}"]
87
+ args = task.arg_names.map{ |name|
88
+ case name
89
+ when :config; '/home/app/config/nginx.conf'
90
+ when :nginx; '/home/app/nginx/sbin/nginx'
91
+ else; nil
92
+ end
93
+ }
94
+ task.invoke(args)
95
+
96
+ # or
97
+ AppDeploy.invoke("app:nginx:#{cmd}",
98
+ :config => '/home/app/config/nginx.conf',
99
+ :nginx => '/home/app/nginx/sbin/nginx')
100
+
101
+ # or
102
+ ENV['config'] = '/home/app/config/nginx.conf'
103
+ ENV['nginx'] = '/home/app/nginx/sbin/nginx'
104
+ Rake::Task["app:nginx:#{cmd}"].invoke
89
105
  end
90
106
  }
91
107
  end
@@ -0,0 +1,63 @@
1
+
2
+ namespace :app do
3
+ namespace :remote do
4
+ task :default, [:hosts, :git, :cd, :branch, :script] do |t, args|
5
+ unless [args[:hosts], args[:git]].all?
6
+ puts 'please fill your arguments like:'
7
+ puts " > rake app:install:remote[#{args.names.join(',').upcase}]"
8
+ exit(1)
9
+ end
10
+
11
+ cd = args[:cd] || '~'
12
+ branch = args[:branch] || 'master'
13
+ tmp = "app-deploy-#{Time.now.to_i}"
14
+
15
+ chdir = "cd #{cd}"
16
+ clone = "git clone #{args[:git]} /tmp/#{tmp}"
17
+ setup = "find /tmp/#{tmp} -maxdepth 1 '!' -name #{tmp} -exec mv -f '{}' #{cd} ';'"
18
+ rmdir = "rmdir /tmp/#{tmp}"
19
+ check = "git checkout #{branch}"
20
+
21
+ script = "#{chdir}; #{clone}; #{setup}; #{rmdir}; #{check}; #{args[:script]}"
22
+ Rake::Task['app:install:remote:sh'].invoke(args[:hosts], script)
23
+ end
24
+
25
+ desc 'invoke a shell script on remote machines'
26
+ task :sh, [:hosts, :script] do |t, args|
27
+ args[:hosts].split(',').map{ |host|
28
+ script = args[:script].gsub('"', '\\"')
29
+ Thread.new{ sh "ssh #{host} \"#{script}\"" }
30
+ }.each(&:join)
31
+ end
32
+
33
+ desc 'upload a file to remote machines'
34
+ task :upload, [:file, :hosts, :path] do |t, args|
35
+ args[:hosts].split(',').each{ |host|
36
+ sh "scp #{args[:file]} #{host}:#{args[:path]}"
37
+ }
38
+ end
39
+
40
+ desc 'create a user on remote machines'
41
+ task :useradd, [:user, :hosts, :script] do |t, args|
42
+ useradd = "sudo useradd -m #{args[:user]}"
43
+ args[:hosts].split(',').each{ |host|
44
+ script = "#{useradd}; #{args[:script]}".gsub('"', '\\"')
45
+ sh "ssh #{host} \"#{script}\""
46
+ }
47
+ end
48
+
49
+ desc 'upload a tarball and untar to user home, then useradd'
50
+ task :setup, [:user, :file, :hosts, :script] do |t, args|
51
+ path = "/tmp/app-deploy-#{Time.now.to_i}"
52
+ Rake::Task['app:install:remote:upload'].invoke(
53
+ args[:file], args[:hosts], path)
54
+
55
+ script = "sudo -u #{args[:user]} tar -zxf #{path}" +
56
+ " -C /home/#{args[:user]};" +
57
+ " rm #{path}; #{args[:script]}"
58
+ Rake::Task['app:install:remote:useradd'].invoke(
59
+ args[:user], args[:hosts], script)
60
+ end
61
+
62
+ end # of remote
63
+ end
@@ -12,16 +12,16 @@ ns = namespace :app do
12
12
  end
13
13
 
14
14
  desc 'terminate a process with a pidfile'
15
- task :stop, [:pidfile, :timeout, :name] do |t, args|
15
+ task :stop, [:pidfile, :name, :timeout] do |t, args|
16
16
  # sh "kill -TERM `cat tmp/pids/nginx.pid`"
17
17
  AppDeploy.term(args[:pidfile], args[:name], args[:timeout] || 5)
18
18
  end
19
19
 
20
20
  desc 'restart a process with a pidfile'
21
- task :restart, [:script, :pidfile, :timeout, :name] => [:stop, :start]
21
+ task :restart, [:script, :pidfile, :name, :timeout] => [:stop, :start]
22
22
 
23
23
  desc 'send HUP to a process with a pidfile'
24
- task :reload, [:pidfile, :name] do
24
+ task :reload, [:pidfile, :name] do |t, args|
25
25
  # sh 'kill -HUP `cat tmp/pids/nginx.pid`'
26
26
  AppDeploy.kill_pidfile('HUP', args[:pidfile], args[:name])
27
27
  end
@@ -1,6 +1,13 @@
1
1
 
2
2
  module AppDeploy
3
3
  module_function
4
+ # wrap Rake::Task#invoke for named arguments
5
+ def invoke task_name, hash
6
+ task = Rake::Task[task_name]
7
+ args = task.arg_names.map{ |name| hash[name] }
8
+ task.invoke(*args)
9
+ end
10
+
4
11
  def always_reenable tasks
5
12
  tasks.each{ |t| t.enhance{ |tt| tt.reenable } }
6
13
  end
@@ -152,7 +159,7 @@ module AppDeploy
152
159
  def term pid_path, name = nil, limit = 5, wait = 0.1
153
160
  require 'timeout'
154
161
  pid = AppDeploy.kill_pidfile('TERM', pid_path, name)
155
- timeout(limit){
162
+ Timeout.timeout(limit.to_i){
156
163
  if pid
157
164
  while true
158
165
  Process.kill('TERM', pid)
@@ -1,4 +1,4 @@
1
1
 
2
2
  module AppDeploy
3
- VERSION = '0.7.1'
3
+ VERSION = '0.7.2'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Lin Jen-Shin (aka godfat \xE7\x9C\x9F\xE5\xB8\xB8)"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-17 00:00:00 +08:00
12
+ date: 2009-12-21 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -51,6 +51,7 @@ extra_rdoc_files:
51
51
  - lib/app-deploy/install.rake
52
52
  - lib/app-deploy/nginx.rake
53
53
  - lib/app-deploy/rack.rake
54
+ - lib/app-deploy/remote.rake
54
55
  - lib/app-deploy/server.rake
55
56
  - lib/app-deploy/signal.rake
56
57
  - lib/app-deploy/thin.rake
@@ -82,6 +83,7 @@ files:
82
83
  - lib/app-deploy/nginx.rake
83
84
  - lib/app-deploy/rack.rake
84
85
  - lib/app-deploy/rack_cluster.rb
86
+ - lib/app-deploy/remote.rake
85
87
  - lib/app-deploy/server.rake
86
88
  - lib/app-deploy/signal.rake
87
89
  - lib/app-deploy/thin.rake