traut 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/traut/server.rb CHANGED
@@ -15,7 +15,7 @@ module Traut
15
15
  AMQP.connect(:host => @amqp[:host], :port => @amqp[:port]) do |connection|
16
16
  @log.info "Connected to AMQP at #{@amqp[:host]}:#{@amqp[:port]}"
17
17
  channel = AMQP::Channel.new(connection)
18
- exchange = channel.topic("traut", :auto_delete => true)
18
+ exchange = channel.topic('traut')
19
19
 
20
20
  @actions.each { |route, script|
21
21
  @log.info("Registering #{script} for route #{route}")
data/lib/traut/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Traut
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/samples/kili CHANGED
@@ -5,7 +5,7 @@ require 'optparse'
5
5
  require 'net/ssh'
6
6
  require 'json'
7
7
  require 'yaml'
8
- require 'amqp'
8
+ require 'bunny'
9
9
  require 'logger'
10
10
 
11
11
  trap(:INT) { puts; exit }
@@ -21,6 +21,7 @@ options = {
21
21
  :port => '22',
22
22
  :user => 'nobody',
23
23
  :keys => '~/.ssh/id_rsa',
24
+ :command => 'gerrit stream-events'
24
25
  }
25
26
  }
26
27
  optparse = OptionParser.new do|opts|
@@ -43,6 +44,9 @@ optparse = OptionParser.new do|opts|
43
44
  opts.on( '--ssh_user USER', 'SSH user for host.') do |su|
44
45
  options[:ssh][:user] = su
45
46
  end
47
+ opts.on( '--command CMD', 'Command to run through SSH exec.') do |cmd|
48
+ options[:ssh][:command] = cmd
49
+ end
46
50
  opts.on( '-l', '--log LOG', 'The log location of Kili') do |log|
47
51
  options[:logs] = log
48
52
  end
@@ -59,50 +63,43 @@ log.level = Logger::INFO
59
63
  amqp = options[:amqp]
60
64
  sshd = options[:ssh]
61
65
 
62
- loop do
63
- begin
64
- EventMachine.run do
65
- AMQP.connect(:host => amqp[:host]) do |connection|
66
- log.info "Connected to AMQP at #{amqp[:host]}:#{amqp[:port]}"
67
- channel = AMQP::Channel.new(connection)
68
- exchange = channel.topic("traut", :auto_delete => true)
69
-
70
- Net::SSH.start(sshd[:host], sshd[:user],
71
- :port => sshd[:port], :keys => sshd[:keys].split(',')) do |ssh|
72
- log.info "SSH connection to #{sshd[:host]}:#{sshd[:port]} as #{sshd[:user]} made."
66
+ Net::SSH.start(sshd[:host], sshd[:user],
67
+ :port => sshd[:port], :keys => sshd[:keys].split(',')) do |ssh|
68
+ log.info "SSH connection to #{sshd[:host]}:#{sshd[:port]} as #{sshd[:user]} made."
73
69
 
74
- channel = ssh.open_channel do |ch|
75
- ch.exec "gerrit stream-events" do |ch, success|
76
- abort "could not stream gerrit events" unless success
70
+ bunny = Bunny.new(:host => amqp[:host], :port => amqp[:port])
71
+ bunny.start
72
+ log.info "AMQP connection made to #{amqp[:host]}:#{amqp[:port]}"
77
73
 
78
- # "on_data" is called when the process writes something to
79
- # stdout
80
- ch.on_data do |c, data|
81
- json = JSON.parse(data)
82
- if json['type'] == 'change-merged'
83
- log.info("Received change-merged event.")
84
- project = json['change']['project']
85
- exchange.publish(data, "com.carepilot.event.code.review.#{project}")
86
- else
87
- log.info("Ignoring event of type #{json['type']}")
88
- end
89
- end
74
+ exch = bunny.exchange('traut', :durable => false, :passive => true, :auto_delete => true)
90
75
 
91
- # "on_extended_data" is called when the process writes
92
- # something to stderr
93
- ch.on_extended_data do |c, type, data|
94
- log.error(data)
95
- end
76
+ channel = ssh.open_channel do |ch|
77
+ ch.exec sshd[:command] do |ch, success|
78
+ abort "could not stream #{sshd[:command]}" unless success
96
79
 
97
- ch.on_close { log.info('Connection closed') }
98
- end
99
- end
100
-
101
- channel.wait
80
+ # "on_data" is called when the process writes something to
81
+ # stdout
82
+ ch.on_data do |c, data|
83
+ json = JSON.parse(data)
84
+ if json['type'] == 'change-merged'
85
+ project = json['change']['project']
86
+ route = "com.carepilot.event.code.review.#{project}"
87
+ exch.publish(data, :key => route)
88
+ log.info("Published #{data} over #{route}")
89
+ else
90
+ log.info("Ignoring event of type #{json['type']}")
102
91
  end
103
92
  end
93
+
94
+ # "on_extended_data" is called when the process writes
95
+ # something to stderr
96
+ ch.on_extended_data do |c, type, data|
97
+ log.error(data)
98
+ end
99
+
100
+ ch.on_close { log.info('Connection closed') }
104
101
  end
105
- rescue Net::SSH::Exception => e
106
- log.error("Connection died with exception #{e}. Restarting...")
107
102
  end
103
+
104
+ channel.wait
108
105
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traut
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-28 00:00:00.000000000Z
12
+ date: 2011-11-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: daemons
16
- requirement: &76444620 !ruby/object:Gem::Requirement
16
+ requirement: &71562050 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *76444620
24
+ version_requirements: *71562050
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: amqp
27
- requirement: &76444360 !ruby/object:Gem::Requirement
27
+ requirement: &71561500 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.8.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *76444360
35
+ version_requirements: *71561500
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: systemu
38
- requirement: &76444090 !ruby/object:Gem::Requirement
38
+ requirement: &71560720 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '2.4'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *76444090
46
+ version_requirements: *71560720
47
47
  description: Traut is a configurable daemon for running localhost commands in response
48
48
  to events generated elsewhere. AMQP is used as the interchange. Traut can make application
49
49
  deployments in response to code checkins, automate database failover and anything
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  requirements: []
92
92
  rubyforge_project: traut
93
- rubygems_version: 1.8.7
93
+ rubygems_version: 1.8.10
94
94
  signing_key:
95
95
  specification_version: 3
96
96
  summary: Turns AMQP events to system command execution