eventhub-command 0.5.0 → 0.6.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 +4 -4
- data/.gitignore +17 -17
- data/Gemfile +2 -2
- data/Rakefile +44 -44
- data/eh.rdoc +4 -4
- data/lib/deployer.rb +1 -0
- data/lib/deployer/base_deployer.rb +149 -149
- data/lib/deployer/go_deployer.rb +112 -0
- data/lib/deployer/mule_deployer.rb +85 -85
- data/lib/deployer/net_ssh_extension.rb +45 -45
- data/lib/deployer/stage.rb +36 -36
- data/lib/eh/commands/deploy.rb +19 -12
- data/lib/eh/commands/generate.rb +91 -91
- data/lib/eh/commands/package.rb +27 -8
- data/lib/eh/commands/repository.rb +81 -81
- data/lib/eh/settings.rb +9 -1
- data/lib/eh/version.rb +1 -1
- data/lib/packager.rb +1 -0
- data/lib/packager/go.rb +159 -0
- data/test/default_test.rb +14 -14
- data/test/test_helper.rb +9 -9
- data/todo.txt +8 -8
- metadata +5 -4
@@ -0,0 +1,112 @@
|
|
1
|
+
class Deployer::GoDeployer < Deployer::BaseDeployer
|
2
|
+
attr_accessor :processor_names
|
3
|
+
|
4
|
+
def initialize(processor_names, options)
|
5
|
+
super(options)
|
6
|
+
@processor_names = processor_names
|
7
|
+
end
|
8
|
+
|
9
|
+
def deploy!
|
10
|
+
puts "deploying to #{stage.name} via #{deploy_via}".light_blue.on_blue
|
11
|
+
|
12
|
+
Deployer::Executor.new(stage, verbose: verbose?) do |executor|
|
13
|
+
create_base_dirs(executor)
|
14
|
+
|
15
|
+
|
16
|
+
update_cached_copy(executor)
|
17
|
+
|
18
|
+
|
19
|
+
# fetch processor_names unless they have been passed as an argument to the initializer
|
20
|
+
processor_names_to_deploy = resolve_processor_names(executor, options)
|
21
|
+
processor_names_to_deploy.each do |processor_name|
|
22
|
+
puts
|
23
|
+
puts "Deploying #{processor_name}".light_blue.on_blue
|
24
|
+
log_deployment(executor, "Deploying #{processor_name} via #{deploy_via} from #{cached_copy_dir}")
|
25
|
+
|
26
|
+
# stop old one
|
27
|
+
executor.execute("kill -s TERM $(cat #{File.join(pids_dir, processor_name)}.pid)", abort_on_error: false, comment: "This is not sooo important")
|
28
|
+
|
29
|
+
# unzip package
|
30
|
+
target = deploy_dir('go')
|
31
|
+
source = cached_copy_dir('go',"#{processor_name}.zip")
|
32
|
+
executor.execute("rm -rf #{processor_dir(processor_name)} && unzip -o -d #{target} #{source}")
|
33
|
+
|
34
|
+
# copy config
|
35
|
+
executor.execute("if [[ -d #{config_source_dir(processor_name)} ]] ; then cp -r #{config_source_dir(processor_name)}/* #{processor_dir(processor_name)}; fi")
|
36
|
+
|
37
|
+
# remove log dir if it exists
|
38
|
+
executor.execute("if [[ -d #{processor_dir(processor_name, 'logs')} ]] ; then rm -rf #{processor_dir(processor_name, 'logs')}; fi")
|
39
|
+
|
40
|
+
# symlink log dir
|
41
|
+
executor.execute("ln -s #{logs_dir} #{processor_dir(processor_name, 'logs')}")
|
42
|
+
|
43
|
+
# symlink pids dir
|
44
|
+
executor.execute("ln -s #{pids_dir} #{processor_dir(processor_name, 'pids')}")
|
45
|
+
|
46
|
+
# start new one
|
47
|
+
executor.execute("cd #{processor_dir(processor_name)} && ./#{processor_name} -d -e $EH_ENV")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def update_cached_copy(executor)
|
55
|
+
if via_scp?
|
56
|
+
source = Eh::Settings.current.releases_dir('go', '*.zip')
|
57
|
+
target_dir = File.join(cached_copy_dir, 'go')
|
58
|
+
executor.execute("rm -rf #{target_dir}/*.zip && mkdir -p #{target_dir}")
|
59
|
+
executor.upload(source, target_dir)
|
60
|
+
else
|
61
|
+
update_scm(executor)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def logs_dir
|
66
|
+
File.join(shared_dir, 'logs')
|
67
|
+
end
|
68
|
+
|
69
|
+
def pids_dir
|
70
|
+
File.join(shared_dir, 'pids')
|
71
|
+
end
|
72
|
+
|
73
|
+
def deploy_dir(*extra_paths)
|
74
|
+
File.join(base_dir, *extra_paths)
|
75
|
+
end
|
76
|
+
|
77
|
+
def processor_dir(*extra_paths)
|
78
|
+
File.join(deploy_dir, 'go', *extra_paths)
|
79
|
+
end
|
80
|
+
|
81
|
+
def config_source_dir(processor_name)
|
82
|
+
super('go', processor_name)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Detect what processors to deploy
|
86
|
+
#
|
87
|
+
def resolve_processor_names(executor, options)
|
88
|
+
available = remote_ls(executor, options, File.join(cached_copy_dir, 'go', '*.zip')).map do |name|
|
89
|
+
File.basename(name, '.zip')
|
90
|
+
end
|
91
|
+
|
92
|
+
fetched = Array(processor_names).map do |name|
|
93
|
+
if name.include?('*') # resolve pattern on remote machine
|
94
|
+
remote_ls(executor, options, File.join(cached_copy_dir, 'go', "#{name}.zip"))
|
95
|
+
else
|
96
|
+
name
|
97
|
+
end
|
98
|
+
end
|
99
|
+
if fetched.empty? # then fetch all
|
100
|
+
fetched = available
|
101
|
+
end
|
102
|
+
|
103
|
+
fetched = fetched.flatten.map do |name|
|
104
|
+
File.basename(name, '.zip')
|
105
|
+
end
|
106
|
+
|
107
|
+
verify_deployment_list!(fetched, available)
|
108
|
+
|
109
|
+
fetched
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
@@ -1,85 +1,85 @@
|
|
1
|
-
class Deployer::MuleDeployer < Deployer::BaseDeployer
|
2
|
-
attr_reader :adapter_names
|
3
|
-
|
4
|
-
def initialize(adapter_names, options)
|
5
|
-
super(options)
|
6
|
-
@adapter_names = adapter_names
|
7
|
-
end
|
8
|
-
|
9
|
-
def adapter_cached_copy(adapter_name)
|
10
|
-
cached_copy_dir('mule', "#{adapter_name}.zip")
|
11
|
-
end
|
12
|
-
|
13
|
-
def config_source_dir(adapter_name)
|
14
|
-
super('mule', adapter_name)
|
15
|
-
end
|
16
|
-
|
17
|
-
def deploy!
|
18
|
-
puts "deploying to #{stage.name} via #{deploy_via}".light_blue.on_blue
|
19
|
-
|
20
|
-
Deployer::Executor.new(stage, verbose: verbose?) do |executor|
|
21
|
-
create_base_dirs(executor)
|
22
|
-
|
23
|
-
# update
|
24
|
-
update_cached_copy(executor)
|
25
|
-
|
26
|
-
adapter_names_to_deploy = resolve_adapter_names(executor, options)
|
27
|
-
|
28
|
-
adapter_names_to_deploy.each do |adapter_name|
|
29
|
-
puts
|
30
|
-
puts "Deploying #{adapter_name}".light_blue.on_blue
|
31
|
-
log_deployment(executor, "Deploying #{adapter_name} via #{deploy_via} from #{cached_copy_dir}")
|
32
|
-
# make a copy of the zip files to merge them with config
|
33
|
-
cached_copy_source = adapter_cached_copy(adapter_name)
|
34
|
-
configuration_target = File.join(base_dir, 'mule', "#{adapter_name}.zip")
|
35
|
-
executor.execute("cp #{cached_copy_source} #{configuration_target}")
|
36
|
-
|
37
|
-
# copy config
|
38
|
-
config_source = config_source_dir(adapter_name)
|
39
|
-
executor.execute("if [[ -d #{config_source} ]] ; then cd #{config_source} ; zip -r #{configuration_target} . ; fi")
|
40
|
-
|
41
|
-
# deploy
|
42
|
-
executor.execute("cp #{configuration_target} $MULE_HOME/apps")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def resolve_adapter_names(executor, options)
|
51
|
-
available = remote_ls(executor, options, cached_copy_dir('mule', '*.zip')).map do |name|
|
52
|
-
File.basename(name, '.zip')
|
53
|
-
end
|
54
|
-
|
55
|
-
fetched = Array(adapter_names).map do |name|
|
56
|
-
if name.include?('*') # resolve pattern on remote machine
|
57
|
-
remote_ls(executor, options, cached_copy_dir('mule', "#{name}.zip"))
|
58
|
-
else
|
59
|
-
name
|
60
|
-
end
|
61
|
-
end
|
62
|
-
if fetched.empty? # then fetch all
|
63
|
-
fetched = available
|
64
|
-
end
|
65
|
-
|
66
|
-
fetched = fetched.flatten.map do |name|
|
67
|
-
File.basename(name, '.zip')
|
68
|
-
end
|
69
|
-
|
70
|
-
verify_deployment_list!(fetched, available)
|
71
|
-
|
72
|
-
fetched
|
73
|
-
end
|
74
|
-
|
75
|
-
def update_cached_copy(executor)
|
76
|
-
if via_scp?
|
77
|
-
source = Eh::Settings.current.releases_dir('mule', '*.zip')
|
78
|
-
target_dir = cached_copy_dir('mule')
|
79
|
-
executor.execute("rm -rf #{target_dir}/*.zip && mkdir -p #{target_dir}")
|
80
|
-
executor.upload(source, target_dir)
|
81
|
-
else
|
82
|
-
update_scm(executor)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
1
|
+
class Deployer::MuleDeployer < Deployer::BaseDeployer
|
2
|
+
attr_reader :adapter_names
|
3
|
+
|
4
|
+
def initialize(adapter_names, options)
|
5
|
+
super(options)
|
6
|
+
@adapter_names = adapter_names
|
7
|
+
end
|
8
|
+
|
9
|
+
def adapter_cached_copy(adapter_name)
|
10
|
+
cached_copy_dir('mule', "#{adapter_name}.zip")
|
11
|
+
end
|
12
|
+
|
13
|
+
def config_source_dir(adapter_name)
|
14
|
+
super('mule', adapter_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
def deploy!
|
18
|
+
puts "deploying to #{stage.name} via #{deploy_via}".light_blue.on_blue
|
19
|
+
|
20
|
+
Deployer::Executor.new(stage, verbose: verbose?) do |executor|
|
21
|
+
create_base_dirs(executor)
|
22
|
+
|
23
|
+
# update
|
24
|
+
update_cached_copy(executor)
|
25
|
+
|
26
|
+
adapter_names_to_deploy = resolve_adapter_names(executor, options)
|
27
|
+
|
28
|
+
adapter_names_to_deploy.each do |adapter_name|
|
29
|
+
puts
|
30
|
+
puts "Deploying #{adapter_name}".light_blue.on_blue
|
31
|
+
log_deployment(executor, "Deploying #{adapter_name} via #{deploy_via} from #{cached_copy_dir}")
|
32
|
+
# make a copy of the zip files to merge them with config
|
33
|
+
cached_copy_source = adapter_cached_copy(adapter_name)
|
34
|
+
configuration_target = File.join(base_dir, 'mule', "#{adapter_name}.zip")
|
35
|
+
executor.execute("cp #{cached_copy_source} #{configuration_target}")
|
36
|
+
|
37
|
+
# copy config
|
38
|
+
config_source = config_source_dir(adapter_name)
|
39
|
+
executor.execute("if [[ -d #{config_source} ]] ; then cd #{config_source} ; zip -r #{configuration_target} . ; fi")
|
40
|
+
|
41
|
+
# deploy
|
42
|
+
executor.execute("cp #{configuration_target} $MULE_HOME/apps")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def resolve_adapter_names(executor, options)
|
51
|
+
available = remote_ls(executor, options, cached_copy_dir('mule', '*.zip')).map do |name|
|
52
|
+
File.basename(name, '.zip')
|
53
|
+
end
|
54
|
+
|
55
|
+
fetched = Array(adapter_names).map do |name|
|
56
|
+
if name.include?('*') # resolve pattern on remote machine
|
57
|
+
remote_ls(executor, options, cached_copy_dir('mule', "#{name}.zip"))
|
58
|
+
else
|
59
|
+
name
|
60
|
+
end
|
61
|
+
end
|
62
|
+
if fetched.empty? # then fetch all
|
63
|
+
fetched = available
|
64
|
+
end
|
65
|
+
|
66
|
+
fetched = fetched.flatten.map do |name|
|
67
|
+
File.basename(name, '.zip')
|
68
|
+
end
|
69
|
+
|
70
|
+
verify_deployment_list!(fetched, available)
|
71
|
+
|
72
|
+
fetched
|
73
|
+
end
|
74
|
+
|
75
|
+
def update_cached_copy(executor)
|
76
|
+
if via_scp?
|
77
|
+
source = Eh::Settings.current.releases_dir('mule', '*.zip')
|
78
|
+
target_dir = cached_copy_dir('mule')
|
79
|
+
executor.execute("rm -rf #{target_dir}/*.zip && mkdir -p #{target_dir}")
|
80
|
+
executor.upload(source, target_dir)
|
81
|
+
else
|
82
|
+
update_scm(executor)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -1,45 +1,45 @@
|
|
1
|
-
class Net::SSH::Connection::Session
|
2
|
-
|
3
|
-
def exec_sc!(command, verbose = false)
|
4
|
-
stdout_data,stderr_data = "",""
|
5
|
-
exit_code, exit_signal = nil,nil
|
6
|
-
self.open_channel do |channel|
|
7
|
-
channel.exec(command) do |_, success|
|
8
|
-
raise "Command \"#{command}\" was unable to execute" unless success
|
9
|
-
|
10
|
-
channel.on_data do |_, data|
|
11
|
-
if verbose
|
12
|
-
puts
|
13
|
-
puts data.light_blue.on_white if verbose
|
14
|
-
end
|
15
|
-
stdout_data += data
|
16
|
-
end
|
17
|
-
|
18
|
-
channel.on_extended_data do |_, _, data|
|
19
|
-
if verbose
|
20
|
-
puts
|
21
|
-
puts data.light_blue.on_white if verbose
|
22
|
-
end
|
23
|
-
stderr_data += data
|
24
|
-
end
|
25
|
-
|
26
|
-
channel.on_request("exit-status") do |_, data|
|
27
|
-
exit_code = data.read_long
|
28
|
-
end
|
29
|
-
|
30
|
-
channel.on_request("exit-signal") do |_, data|
|
31
|
-
exit_signal = data.read_long
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
self.loop
|
36
|
-
raise stderr_data unless exit_code == 0
|
37
|
-
|
38
|
-
{
|
39
|
-
stdout: stdout_data,
|
40
|
-
stderr: stderr_data,
|
41
|
-
exit_code: exit_code,
|
42
|
-
exit_signal: exit_signal
|
43
|
-
}
|
44
|
-
end
|
45
|
-
end
|
1
|
+
class Net::SSH::Connection::Session
|
2
|
+
|
3
|
+
def exec_sc!(command, verbose = false)
|
4
|
+
stdout_data,stderr_data = "",""
|
5
|
+
exit_code, exit_signal = nil,nil
|
6
|
+
self.open_channel do |channel|
|
7
|
+
channel.exec(command) do |_, success|
|
8
|
+
raise "Command \"#{command}\" was unable to execute" unless success
|
9
|
+
|
10
|
+
channel.on_data do |_, data|
|
11
|
+
if verbose
|
12
|
+
puts
|
13
|
+
puts data.light_blue.on_white if verbose
|
14
|
+
end
|
15
|
+
stdout_data += data
|
16
|
+
end
|
17
|
+
|
18
|
+
channel.on_extended_data do |_, _, data|
|
19
|
+
if verbose
|
20
|
+
puts
|
21
|
+
puts data.light_blue.on_white if verbose
|
22
|
+
end
|
23
|
+
stderr_data += data
|
24
|
+
end
|
25
|
+
|
26
|
+
channel.on_request("exit-status") do |_, data|
|
27
|
+
exit_code = data.read_long
|
28
|
+
end
|
29
|
+
|
30
|
+
channel.on_request("exit-signal") do |_, data|
|
31
|
+
exit_signal = data.read_long
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
self.loop
|
36
|
+
raise stderr_data unless exit_code == 0
|
37
|
+
|
38
|
+
{
|
39
|
+
stdout: stdout_data,
|
40
|
+
stderr: stderr_data,
|
41
|
+
exit_code: exit_code,
|
42
|
+
exit_signal: exit_signal
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
data/lib/deployer/stage.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
|
-
class Deployer::Stage
|
2
|
-
attr_reader :name, :hosts
|
3
|
-
|
4
|
-
def initialize(name)
|
5
|
-
@name = name
|
6
|
-
@hosts = []
|
7
|
-
end
|
8
|
-
|
9
|
-
def host(host, port, user)
|
10
|
-
@hosts << {
|
11
|
-
host: host,
|
12
|
-
port: port,
|
13
|
-
user: user
|
14
|
-
}
|
15
|
-
self
|
16
|
-
end
|
17
|
-
|
18
|
-
# returns a new stage which only contains one host
|
19
|
-
#
|
20
|
-
def single_host_stage
|
21
|
-
stage = Deployer::Stage.new(name)
|
22
|
-
stage.host(hosts[0][:host], hosts[0][:port], hosts[0][:user])
|
23
|
-
stage
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.load(name, file)
|
27
|
-
data = YAML.load_file(file)
|
28
|
-
data.map do |_, config|
|
29
|
-
stage = Deployer::Stage.new(name)
|
30
|
-
config['hosts'].each do |host|
|
31
|
-
stage.host(host['host'], host['port'], host['user'])
|
32
|
-
end
|
33
|
-
stage
|
34
|
-
end.first
|
35
|
-
end
|
36
|
-
end
|
1
|
+
class Deployer::Stage
|
2
|
+
attr_reader :name, :hosts
|
3
|
+
|
4
|
+
def initialize(name)
|
5
|
+
@name = name
|
6
|
+
@hosts = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def host(host, port, user)
|
10
|
+
@hosts << {
|
11
|
+
host: host,
|
12
|
+
port: port,
|
13
|
+
user: user
|
14
|
+
}
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
# returns a new stage which only contains one host
|
19
|
+
#
|
20
|
+
def single_host_stage
|
21
|
+
stage = Deployer::Stage.new(name)
|
22
|
+
stage.host(hosts[0][:host], hosts[0][:port], hosts[0][:user])
|
23
|
+
stage
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.load(name, file)
|
27
|
+
data = YAML.load_file(file)
|
28
|
+
data.map do |_, config|
|
29
|
+
stage = Deployer::Stage.new(name)
|
30
|
+
config['hosts'].each do |host|
|
31
|
+
stage.host(host['host'], host['port'], host['user'])
|
32
|
+
end
|
33
|
+
stage
|
34
|
+
end.first
|
35
|
+
end
|
36
|
+
end
|
data/lib/eh/commands/deploy.rb
CHANGED
@@ -6,8 +6,8 @@ command :deploy do |c|
|
|
6
6
|
c.switch([:v, :verbose], :desc => 'Show additional output.')
|
7
7
|
c.flag([:deploy_via], desc: 'where to deploy from', type: String, long_desc: 'deploy via scm or scp. If you use scp then the working_dir is packaged and copied tot the servers', default_value: 'svn')
|
8
8
|
|
9
|
+
c.desc 'deploy all'
|
9
10
|
c.command :all do |c|
|
10
|
-
c.desc 'deploy all'
|
11
11
|
c.action do |global_options, options, arguments|
|
12
12
|
forward_arguments = arguments.join(' ')
|
13
13
|
deploy_config(options, forward_arguments)
|
@@ -17,14 +17,14 @@ command :deploy do |c|
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
c.desc 'distribute the configs to the nodes'
|
20
21
|
c.command :config do |c|
|
21
|
-
c.desc 'distribute the configs to the nodes'
|
22
22
|
c.action do |global_options, options, args|
|
23
23
|
Deployer::ConfigDeployer.new(options).deploy!
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
desc 'deploy the rails console app'
|
27
|
+
c.desc 'deploy the rails console app'
|
28
28
|
c.command :console do |c|
|
29
29
|
c.flag([:working_dir], desc: 'directory to execute commands in', type: String, default_value: '.')
|
30
30
|
|
@@ -33,13 +33,10 @@ command :deploy do |c|
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
c.desc 'deploy a single channel adapter'
|
37
|
+
c.arg_name '[channel_adapter[,other_channel_adapter,pattern*]]'
|
37
38
|
c.command :mule do |c|
|
38
|
-
c.desc 'deploy a single channel adapter'
|
39
|
-
c.arg_name '[channel_adapter[,other_channel_adapter,pattern*]]'
|
40
|
-
|
41
39
|
c.action do |global_options, options, args|
|
42
|
-
|
43
40
|
if args[0]
|
44
41
|
adapter_names = args[0].split(',').map(&:strip)
|
45
42
|
else
|
@@ -49,10 +46,9 @@ command :deploy do |c|
|
|
49
46
|
end
|
50
47
|
end
|
51
48
|
|
49
|
+
c.desc 'deploy a single ruby processor'
|
50
|
+
c.arg_name '[processor_name,[other_processor_name,pattern*]]'
|
52
51
|
c.command :ruby do |c|
|
53
|
-
c.desc 'deploy a single ruby processor'
|
54
|
-
c.arg_name '[processor_name,[other_processor_name,pattern*]]'
|
55
|
-
|
56
52
|
c.action do |global_options, options, args|
|
57
53
|
if args[0]
|
58
54
|
processor_names = args[0].split(',').map(&:strip)
|
@@ -63,7 +59,18 @@ command :deploy do |c|
|
|
63
59
|
end
|
64
60
|
end
|
65
61
|
|
66
|
-
|
62
|
+
c.desc 'deploy a single go processor'
|
63
|
+
c.arg_name '[processor_name,[other_processor_name,pattern*]]'
|
64
|
+
c.command :go do |go|
|
65
|
+
go.action do |global_options, options, args|
|
66
|
+
if args[0]
|
67
|
+
processor_names = args[0].split(',').map(&:strip)
|
68
|
+
else
|
69
|
+
processor_names = nil
|
70
|
+
end
|
71
|
+
Deployer::GoDeployer.new(processor_names, options).deploy!
|
72
|
+
end
|
73
|
+
end
|
67
74
|
|
68
75
|
private
|
69
76
|
|