joekhoobyar-capsaicin 0.1.1 → 0.1.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/VERSION.yml +1 -1
- data/lib/capsaicin/files/remote.rb +20 -12
- data/lib/capsaicin/files.rb +7 -1
- data/lib/capsaicin/invocation.rb +18 -3
- data/lib/capsaicin/service/lsb.rb +7 -6
- metadata +2 -2
data/VERSION.yml
CHANGED
|
@@ -27,17 +27,32 @@ module Capsaicin
|
|
|
27
27
|
|
|
28
28
|
def tail_f(file, n=10)
|
|
29
29
|
cmd = "tail -n #{n} -f #{_q file}"
|
|
30
|
-
|
|
30
|
+
case v = _via
|
|
31
|
+
when :system, :local_run
|
|
32
|
+
send v, cmd
|
|
33
|
+
else
|
|
34
|
+
stream cmd, :via => v
|
|
35
|
+
end
|
|
31
36
|
rescue Interrupt
|
|
32
37
|
logger.trace "interrupted (Ctrl-C)" if logger
|
|
33
38
|
end
|
|
34
39
|
|
|
35
40
|
def upload(*args)
|
|
36
|
-
_via
|
|
41
|
+
case _via
|
|
42
|
+
when :system, :local_run
|
|
43
|
+
cp(*args)
|
|
44
|
+
else
|
|
45
|
+
@config.upload(*args)
|
|
46
|
+
end
|
|
37
47
|
end
|
|
38
48
|
|
|
39
49
|
def download(*args)
|
|
40
|
-
_via
|
|
50
|
+
case _via
|
|
51
|
+
when :system, :local_run
|
|
52
|
+
cp(*args)
|
|
53
|
+
else
|
|
54
|
+
@config.download(*args)
|
|
55
|
+
end
|
|
41
56
|
end
|
|
42
57
|
|
|
43
58
|
def cd(dir, options={})
|
|
@@ -50,7 +65,7 @@ module Capsaicin
|
|
|
50
65
|
end
|
|
51
66
|
|
|
52
67
|
def pwd
|
|
53
|
-
capture
|
|
68
|
+
capture 'pwd', :via => _via
|
|
54
69
|
end
|
|
55
70
|
|
|
56
71
|
private
|
|
@@ -92,14 +107,7 @@ module Capsaicin
|
|
|
92
107
|
end
|
|
93
108
|
|
|
94
109
|
def _via
|
|
95
|
-
|
|
96
|
-
when :local
|
|
97
|
-
:system
|
|
98
|
-
when :remote, NilClass
|
|
99
|
-
@config.fetch(:run_method, nil)
|
|
100
|
-
else
|
|
101
|
-
v
|
|
102
|
-
end
|
|
110
|
+
@config.fetch(:run_method, nil)
|
|
103
111
|
end
|
|
104
112
|
|
|
105
113
|
end
|
data/lib/capsaicin/files.rb
CHANGED
|
@@ -25,6 +25,8 @@ module Capsaicin
|
|
|
25
25
|
%w(executable? -x)
|
|
26
26
|
]
|
|
27
27
|
|
|
28
|
+
LOCAL_RUN_METHODS = [:system, :local_run]
|
|
29
|
+
|
|
28
30
|
require File.join(File.dirname(__FILE__), %w(files local.rb))
|
|
29
31
|
require File.join(File.dirname(__FILE__), %w(files remote.rb))
|
|
30
32
|
|
|
@@ -33,7 +35,11 @@ module Capsaicin
|
|
|
33
35
|
end.join("\n"), __FILE__, __LINE__)
|
|
34
36
|
|
|
35
37
|
def _via
|
|
36
|
-
@config.fetch(:
|
|
38
|
+
if LOCAL_RUN_METHODS.include? @config.fetch(:run_method, nil)
|
|
39
|
+
:local
|
|
40
|
+
else
|
|
41
|
+
:remote
|
|
42
|
+
end
|
|
37
43
|
end
|
|
38
44
|
end
|
|
39
45
|
end
|
data/lib/capsaicin/invocation.rb
CHANGED
|
@@ -1,25 +1,40 @@
|
|
|
1
1
|
module Capsaicin
|
|
2
2
|
|
|
3
3
|
module Invocation
|
|
4
|
+
|
|
5
|
+
# Capistrano's system() override is only available from the base deployment strategy.
|
|
6
|
+
# Also, we could do with a few more windows checks.
|
|
4
7
|
def local_run(*args, &block)
|
|
5
8
|
args.pop if Hash===args.last
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
cmd = args.join(' ')
|
|
10
|
+
if RUBY_PLATFORM =~ /win32|mingw|mswin/
|
|
11
|
+
cmd.gsub!('/','\\') # Replace / with \\
|
|
12
|
+
cmd.gsub!(/^cd /,'cd /D ') # Replace cd with cd /D
|
|
13
|
+
cmd.gsub!(/&& cd /,'&& cd /D ') # Replace cd with cd /D
|
|
14
|
+
logger.trace "executing locally: #{cmd}"
|
|
15
|
+
Kernel.system cmd
|
|
16
|
+
else
|
|
17
|
+
logger.trace "executing locally: #{cmd}"
|
|
18
|
+
Kernel.system cmd
|
|
19
|
+
end
|
|
9
20
|
end
|
|
10
21
|
|
|
22
|
+
# Always uses :runner to sudo as someone.
|
|
23
|
+
# Equivalent to: sudo "command", :as => fetch(:runner,nil)
|
|
11
24
|
def sudo_as(*args, &block)
|
|
12
25
|
options = Hash===args.last ? args.pop.dup : {}
|
|
13
26
|
options[:as] = fetch(:runner, nil)
|
|
14
27
|
sudo *args.push(options), &block
|
|
15
28
|
end
|
|
16
29
|
|
|
30
|
+
# Extremely helpful if you only have permission to: sudo su SOMEUSER -c "command"
|
|
17
31
|
def sudo_su(*args, &block)
|
|
18
32
|
options = Hash===args.last ? args.pop.dup : {}
|
|
19
33
|
args[0] = "su #{fetch(:runner, nil)} -c '#{args[0]}'"
|
|
20
34
|
sudo *args.push(options), &block
|
|
21
35
|
end
|
|
22
36
|
|
|
37
|
+
# Extremely helpful if you only have permission to: sudo su - SOMEUSER
|
|
23
38
|
def sudo_su_to(*args, &block)
|
|
24
39
|
options = Hash===args.last ? args.pop.dup : {}
|
|
25
40
|
options[:shell] = false
|
|
@@ -4,9 +4,9 @@ module Capsaicin
|
|
|
4
4
|
|
|
5
5
|
DEFAULT_ACTIONS = %w(status start stop restart)
|
|
6
6
|
|
|
7
|
-
# Check for the existance of a generic
|
|
8
|
-
def lsb?(id)
|
|
9
|
-
files.exists? "
|
|
7
|
+
# Check for the existance of a generic LSB initscript.
|
|
8
|
+
def lsb?(id, basedir="/etc/init.d")
|
|
9
|
+
files.exists? "#{basedir}/#{id.to_s.split(':').last}"
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
# Defines a recipe to control a generic LSB service.
|
|
@@ -14,6 +14,7 @@ module Capsaicin
|
|
|
14
14
|
def lsb(id,*args)
|
|
15
15
|
options = Hash===args.last ? args.pop : {}
|
|
16
16
|
|
|
17
|
+
basedir = options.delete(:basedir)
|
|
17
18
|
svc_name = id.to_s
|
|
18
19
|
svc_desc = next_description(:reset) || (svc_name.capitalize unless options.delete(:hide))
|
|
19
20
|
svc_actions = DEFAULT_ACTIONS
|
|
@@ -24,18 +25,18 @@ module Capsaicin
|
|
|
24
25
|
when String; id = args.shift.intern
|
|
25
26
|
when Symbol; id = args.shift
|
|
26
27
|
end
|
|
27
|
-
svc_cmd = "/etc/init.d/#{id.to_s.split(':').last}"
|
|
28
|
+
svc_cmd = "#{basedir || '/etc/init.d'}/#{id.to_s.split(':').last}"
|
|
28
29
|
|
|
29
30
|
desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[:status]}" if svc_desc
|
|
30
31
|
task :default, options do
|
|
31
|
-
sudo "#{svc_cmd} status"
|
|
32
|
+
send(basedir ? run_method : :sudo, "#{svc_cmd} status")
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
svc_actions.each do |svc_action|
|
|
35
36
|
svc_action = svc_action.intern if String === svc_action
|
|
36
37
|
desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[svc_action]}" if svc_desc
|
|
37
38
|
task svc_action, options do
|
|
38
|
-
sudo "#{svc_cmd} #{svc_action}"
|
|
39
|
+
send(basedir ? run_method : :sudo, "#{svc_cmd} #{svc_action}")
|
|
39
40
|
end
|
|
40
41
|
end
|
|
41
42
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: joekhoobyar-capsaicin
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joe Khoobyar
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-
|
|
12
|
+
date: 2009-05-07 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|