joekhoobyar-capistrano-extensions 0.0.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.
- data/README +0 -0
- data/Rakefile +40 -0
- data/VERSION.yml +4 -0
- data/lib/capistrano_extensions/files.rb +18 -0
- data/lib/capistrano_extensions/files/local.rb +40 -0
- data/lib/capistrano_extensions/files/remote.rb +189 -0
- data/lib/capistrano_extensions/service.rb +109 -0
- data/lib/jk_capistrano_extensions.rb +8 -0
- metadata +60 -0
data/README
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
require 'rake/testtask'
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'jeweler'
|
9
|
+
Jeweler::Tasks.new do |s|
|
10
|
+
s.name = "capistrano-extensions"
|
11
|
+
s.homepage = "http://github.com/joekhoobyar/capistrano-extensions"
|
12
|
+
s.summary = "Joe Khoobyar's Capistrano Extensions"
|
13
|
+
s.description = %Q{Joe Khoobyar's Capistrano Extensions}
|
14
|
+
|
15
|
+
s.authors = ["Joe Khoobyar"]
|
16
|
+
s.email = "joe@ankhcraft.com"
|
17
|
+
end
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
20
|
+
end
|
21
|
+
|
22
|
+
# --------- RDoc Documentation ---------
|
23
|
+
desc "Generate RDoc documentation"
|
24
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
25
|
+
rdoc.options << '--line-numbers' << '--inline-source' <<
|
26
|
+
'--main' << 'README' <<
|
27
|
+
'--title' << "Joe Khoobyar's Capistrano Extensions" <<
|
28
|
+
'--charset' << 'utf-8'
|
29
|
+
rdoc.rdoc_dir = "doc"
|
30
|
+
rdoc.rdoc_files.include 'README'
|
31
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
32
|
+
end
|
33
|
+
|
34
|
+
Rake::TestTask.new do |t|
|
35
|
+
t.libs << "test"
|
36
|
+
t.libs << "lib"
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :package
|
40
|
+
|
data/VERSION.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), %w(files local.rb))
|
2
|
+
require File.join(File.dirname(__FILE__), %w(files remote.rb))
|
3
|
+
|
4
|
+
module CapistranoExtensions::Files
|
5
|
+
class_eval(Local.public_instance_methods(false).map do |m|
|
6
|
+
"def #{m}(*f) send(_via.to_s + '_files').#{m}(*f) end"
|
7
|
+
end.join("\n"))
|
8
|
+
|
9
|
+
def _via
|
10
|
+
if ! @config.exists?(:files_via) or @config.files_via != :local then
|
11
|
+
:remote
|
12
|
+
else
|
13
|
+
:local
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Capistrano.plugin :files, CapistranoExtensions::Files
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module CapistranoExtensions
|
4
|
+
module Files
|
5
|
+
module Local
|
6
|
+
|
7
|
+
def tail_f(file, n=10)
|
8
|
+
unless defined? File::Tail::Logfile
|
9
|
+
gem 'file-tail'
|
10
|
+
require 'file/tail'
|
11
|
+
end
|
12
|
+
File::Tail::Logfile.tail(file, :backward=>n) do |line| puts line end
|
13
|
+
end
|
14
|
+
|
15
|
+
def upload(from, to)
|
16
|
+
cp(from, to)
|
17
|
+
end
|
18
|
+
|
19
|
+
def download(from, to)
|
20
|
+
cp(from, to)
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
include FileUtils::Verbose
|
25
|
+
|
26
|
+
public *FileUtils::Verbose.methods(false)
|
27
|
+
private *%w(copy_entry copy_file copy_stream
|
28
|
+
remove_entry remove_entry_secure remove_file
|
29
|
+
compare_file compare_stream
|
30
|
+
uptodate?)
|
31
|
+
|
32
|
+
class_eval(%w(exists? directory? executable?).map do |m|
|
33
|
+
"def #{m}(f) File.#{m}(f) end"
|
34
|
+
end.join("\n"))
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Capistrano.plugin :local_files, CapistranoExtensions::Files::Local
|
@@ -0,0 +1,189 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module CapistranoExtensions
|
4
|
+
module Files
|
5
|
+
module Remote
|
6
|
+
|
7
|
+
def tail_f(file, n=10)
|
8
|
+
cmd = "tail -n #{n} -f #{_q file}"
|
9
|
+
_via == :system ? system(cmd) : stream(cmd)
|
10
|
+
end
|
11
|
+
|
12
|
+
def upload(*args)
|
13
|
+
_via == :system ? cp(*args) : upload(*args)
|
14
|
+
end
|
15
|
+
|
16
|
+
def download(*args)
|
17
|
+
_via == :system ? cp(*args) : download(*args)
|
18
|
+
end
|
19
|
+
|
20
|
+
def cd(dir, options={})
|
21
|
+
if block_given?
|
22
|
+
dir, dir2 = pwd, dir
|
23
|
+
_r 'cd', dir2
|
24
|
+
yield
|
25
|
+
end
|
26
|
+
_r 'cd', dir
|
27
|
+
end
|
28
|
+
|
29
|
+
def pwd
|
30
|
+
capture("pwd", :via => _via)
|
31
|
+
end
|
32
|
+
|
33
|
+
def mkdir(*args)
|
34
|
+
options = args.pop if Hash === args.last
|
35
|
+
_r 'mkdir', args
|
36
|
+
end
|
37
|
+
|
38
|
+
def mkdir_p(*args)
|
39
|
+
options = args.pop if Hash === args.last
|
40
|
+
_r 'mkdir -p', args
|
41
|
+
end
|
42
|
+
|
43
|
+
def rmdir(*args)
|
44
|
+
options = args.pop if Hash === args.last
|
45
|
+
_r 'rmdir', args
|
46
|
+
end
|
47
|
+
|
48
|
+
def ln(*args)
|
49
|
+
options = args.pop if Hash === args.last
|
50
|
+
_r 'ln', args, 2
|
51
|
+
end
|
52
|
+
|
53
|
+
def ln_s(*args)
|
54
|
+
options = args.pop if Hash === args.last
|
55
|
+
_r 'ln -s', args, 2
|
56
|
+
end
|
57
|
+
|
58
|
+
def ln_sf(*args)
|
59
|
+
options = args.pop if Hash === args.last
|
60
|
+
_r 'ln -sf', args, 2
|
61
|
+
end
|
62
|
+
|
63
|
+
def cp(*args)
|
64
|
+
options = args.pop if Hash === args.last
|
65
|
+
_r 'cp', args
|
66
|
+
end
|
67
|
+
|
68
|
+
def cp_r(*args)
|
69
|
+
options = args.pop if Hash === args.last
|
70
|
+
_r 'cp -r', args
|
71
|
+
end
|
72
|
+
|
73
|
+
def mv(*args)
|
74
|
+
options = args.pop if Hash === args.last
|
75
|
+
_r 'mv', args, 2
|
76
|
+
end
|
77
|
+
|
78
|
+
def rm(*args)
|
79
|
+
options = args.pop if Hash === args.last
|
80
|
+
_r 'rm', args
|
81
|
+
end
|
82
|
+
|
83
|
+
def rm_r(*args)
|
84
|
+
options = args.pop if Hash === args.last
|
85
|
+
_r 'rm -r', args
|
86
|
+
end
|
87
|
+
|
88
|
+
def rm_rf(*args)
|
89
|
+
options = args.pop if Hash === args.last
|
90
|
+
_r 'rm -rf', args
|
91
|
+
end
|
92
|
+
|
93
|
+
def install(*args)
|
94
|
+
options = args.pop if Hash === args.last
|
95
|
+
_r 'install', args, 2
|
96
|
+
end
|
97
|
+
|
98
|
+
def chmod(*args)
|
99
|
+
options = args.pop if Hash === args.last
|
100
|
+
_r 'chmod', args
|
101
|
+
end
|
102
|
+
|
103
|
+
def chmod_R(*args)
|
104
|
+
options = args.pop if Hash === args.last
|
105
|
+
_r 'chmod -R', args
|
106
|
+
end
|
107
|
+
|
108
|
+
def chown(*args)
|
109
|
+
options = args.pop if Hash === args.last
|
110
|
+
_r 'chown', args
|
111
|
+
end
|
112
|
+
|
113
|
+
def chown_R(*args)
|
114
|
+
options = args.pop if Hash === args.last
|
115
|
+
_r 'chown -R', args
|
116
|
+
end
|
117
|
+
|
118
|
+
def touch(*args)
|
119
|
+
options = args.pop if Hash === args.last
|
120
|
+
_r 'touch', args
|
121
|
+
end
|
122
|
+
|
123
|
+
def exists?(a, options={:verbose=>false})
|
124
|
+
silence!(options) { _r "[ -f #{_q a} ]" }
|
125
|
+
end
|
126
|
+
|
127
|
+
def directory?(a, options={:verbose=>false})
|
128
|
+
silence!(options) { _r "[ -d #{_q a} ]" }
|
129
|
+
end
|
130
|
+
|
131
|
+
def executable?(a, options={:verbose=>false})
|
132
|
+
silence!(options) { _r "[ -x #{_q a} ]" }
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
def silence!(quiet=false)
|
139
|
+
quiet = (FalseClass===quiet[:verbose]) if Hash === quiet
|
140
|
+
orig_quiet, @quiet = @quiet, quiet
|
141
|
+
yield
|
142
|
+
ensure
|
143
|
+
@quiet = orig_quiet
|
144
|
+
end
|
145
|
+
|
146
|
+
def _r(cmd, args=nil, min=nil)
|
147
|
+
case args
|
148
|
+
when NilClass
|
149
|
+
raise ArgumentError unless min.nil? or min.zero?
|
150
|
+
when Array
|
151
|
+
args = args.flatten
|
152
|
+
raise ArgumentError if (min || 1) > args.length
|
153
|
+
cmd = "#{cmd} #{_q(*args)}" if args.any?
|
154
|
+
else
|
155
|
+
raise ArgumentError if min.nil? or min < 1
|
156
|
+
cmd = "#{cmd} #{_q args}"
|
157
|
+
end
|
158
|
+
|
159
|
+
case (v = _via)
|
160
|
+
when :system
|
161
|
+
@quiet or $stderr.puts cmd
|
162
|
+
system cmd
|
163
|
+
when :sudo
|
164
|
+
sudo cmd, :as => @config.fetch(:runner, 'app')
|
165
|
+
else
|
166
|
+
invoke_command cmd, :via => v
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def _q(*list)
|
171
|
+
list.map { |l| "'#{l.gsub("'", "\\'")}'" }.join ' '
|
172
|
+
end
|
173
|
+
|
174
|
+
def _via
|
175
|
+
case (v = files_via)
|
176
|
+
when :local
|
177
|
+
:system
|
178
|
+
when :remote, NilClass
|
179
|
+
:runner
|
180
|
+
else
|
181
|
+
v
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
Capistrano.plugin :remote_files, CapistranoExtensions::Files::Remote
|
@@ -0,0 +1,109 @@
|
|
1
|
+
module CapistranoExtensions
|
2
|
+
module Service
|
3
|
+
|
4
|
+
LSB_DEFAULT_ACTIONS = %w(status start stop restart)
|
5
|
+
|
6
|
+
CRM_DEFAULT_ACTIONS = [ [ :status, '-W' ],
|
7
|
+
[ :summary, "-x | awk '/^raw xml:/ { exit }; { print }'" ],
|
8
|
+
[ :start, "--meta -d 'target_role'" ],
|
9
|
+
[ :stop, "--meta -p 'target_role' -v 'stopped'" ] ]
|
10
|
+
|
11
|
+
CRM_OCF_DEFAULT_ACTIONS = [ [ :validate, '-c -C' ],
|
12
|
+
[ :monitor, '-c -m' ] ]
|
13
|
+
|
14
|
+
SVC_ACTION_CAPTIONS = Hash.new do |h,k|
|
15
|
+
h[k] = "#{k.to_s.capitalize} Service"
|
16
|
+
end
|
17
|
+
SVC_ACTION_CAPTIONS.update :status => 'Check Status', :check => 'Check Config', :summary => 'Status Summary'
|
18
|
+
|
19
|
+
def crm(id,*args)
|
20
|
+
svc_desc = next_description(:reset)
|
21
|
+
svc_cmd = "/usr/sbin/crm_resource -r #{id.to_s.split(':').last}"
|
22
|
+
svc_actions = CRM_DEFAULT_ACTIONS
|
23
|
+
|
24
|
+
if Hash === args.last
|
25
|
+
options = args.pop
|
26
|
+
svc_desc = id.to_s.capitalize unless svc_desc or options.delete(:hide)
|
27
|
+
svc_actions += args.shift if Array === args.first
|
28
|
+
else
|
29
|
+
options = {}
|
30
|
+
end
|
31
|
+
|
32
|
+
namespace id do
|
33
|
+
desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[:status]}" if svc_desc
|
34
|
+
task :default, options do
|
35
|
+
sudo "#{svc_cmd} -W"
|
36
|
+
end
|
37
|
+
|
38
|
+
svc_actions.each do |svc_action,svc_args|
|
39
|
+
svc_action = svc_action.intern unless Symbol===svc_action
|
40
|
+
desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[svc_action]}" if svc_desc
|
41
|
+
task svc_action, options do
|
42
|
+
sudo "#{svc_cmd} #{svc_args}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
instance_eval { yield } if block_given?
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def crm_ocf(id,*args)
|
51
|
+
svc_desc = next_description(:reset)
|
52
|
+
svc_cmd = "ocf_resource -g #{id.to_s.split(':').last}"
|
53
|
+
svc_actions = CRM_OCF_DEFAULT_ACTIONS
|
54
|
+
|
55
|
+
if Hash === args.last
|
56
|
+
options = args.pop
|
57
|
+
svc_desc = id.to_s.capitalize unless svc_desc or options.delete(:hide)
|
58
|
+
svc_actions += args.shift if Array === args.first
|
59
|
+
else
|
60
|
+
options = {}
|
61
|
+
end
|
62
|
+
|
63
|
+
namespace id do
|
64
|
+
svc_actions.each do |svc_action,svc_args|
|
65
|
+
svc_action = svc_action.intern unless Symbol===svc_action
|
66
|
+
desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[svc_action]}" if svc_desc
|
67
|
+
task svc_action, options do
|
68
|
+
sudo "#{svc_cmd} #{svc_args}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
instance_eval { yield } if block_given?
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def lsb(id,*args)
|
77
|
+
svc_desc = next_description(:reset)
|
78
|
+
svc_cmd = "/etc/init.d/#{id.to_s.split(':').last}"
|
79
|
+
svc_actions = LSB_DEFAULT_ACTIONS
|
80
|
+
|
81
|
+
if Hash === args.last
|
82
|
+
options = args.pop
|
83
|
+
svc_desc = id.to_s.capitalize unless svc_desc or options.delete(:hide)
|
84
|
+
svc_actions += args.shift if Array === args.first
|
85
|
+
else
|
86
|
+
options = {}
|
87
|
+
end
|
88
|
+
|
89
|
+
namespace id do
|
90
|
+
desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[:status]}" if svc_desc
|
91
|
+
task :default, options do
|
92
|
+
sudo "#{svc_cmd} status"
|
93
|
+
end
|
94
|
+
|
95
|
+
svc_actions.each do |svc_action|
|
96
|
+
svc_action = svc_action.intern
|
97
|
+
desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[svc_action]}" if svc_desc
|
98
|
+
task svc_action, options do
|
99
|
+
sudo "#{svc_cmd} #{svc_action}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
instance_eval { yield } if block_given?
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
Capistrano.plugin :service, CapistranoExtensions::Service
|
@@ -0,0 +1,8 @@
|
|
1
|
+
unless Capistrano::Configuration.respond_to?(:instance)
|
2
|
+
abort "jk-capistrano-extensions requires Capistrano 2"
|
3
|
+
end
|
4
|
+
require 'capistrano'
|
5
|
+
|
6
|
+
require "#{File.dirname(__FILE__)}/capistrano_extensions/file_transfer.rb"
|
7
|
+
require "#{File.dirname(__FILE__)}/capistrano_extensions/files.rb"
|
8
|
+
require "#{File.dirname(__FILE__)}/capistrano_extensions/service.rb"
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: joekhoobyar-capistrano-extensions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joe Khoobyar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-23 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Joe Khoobyar's Capistrano Extensions
|
17
|
+
email: joe@ankhcraft.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- Rakefile
|
26
|
+
- VERSION.yml
|
27
|
+
- lib/capistrano_extensions/files.rb
|
28
|
+
- lib/capistrano_extensions/files/local.rb
|
29
|
+
- lib/capistrano_extensions/files/remote.rb
|
30
|
+
- lib/capistrano_extensions/service.rb
|
31
|
+
- lib/jk_capistrano_extensions.rb
|
32
|
+
- README
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/joekhoobyar/capistrano-extensions
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options:
|
37
|
+
- --charset=UTF-8
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.2.0
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: Joe Khoobyar's Capistrano Extensions
|
59
|
+
test_files: []
|
60
|
+
|