haredo 0.0.5 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ module HareDo
2
+
3
+ class Plugin
4
+
5
+ attr_reader :uuid
6
+
7
+ def initialize(uuid, peer, config={})
8
+ @uuid = uuid
9
+ @peer = peer
10
+ @config = config
11
+ end
12
+
13
+ def finalize()
14
+ puts "finalize(#{@uuid})"
15
+ end
16
+
17
+ end # class Plugin
18
+
19
+ end # module Sonar
@@ -0,0 +1,15 @@
1
+ require 'haredo/plugin'
2
+
3
+ class Plugin < HareDo::Plugin
4
+
5
+ UUID = 'echo'
6
+
7
+ def initialize(peer, config)
8
+ super UUID, peer, config
9
+ end
10
+
11
+ def process(msg)
12
+ @peer.reply(msg, :data=>msg.data)
13
+ end
14
+
15
+ end # class Plugin
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+ require 'haredo/plugin'
3
+
4
+ class Plugin < HareDo::Plugin
5
+
6
+ UUID = 'example'
7
+
8
+ def initialize(service, config)
9
+ super UUID, service, config
10
+ end
11
+
12
+ def process(msg)
13
+ # Send back configuration
14
+ @peer.reply(msg, :data=>JSON::pretty_generate(@config))
15
+ end
16
+
17
+ end # class Plugin
@@ -0,0 +1,31 @@
1
+ require 'json'
2
+ require 'haredo/plugin'
3
+
4
+ class Plugin < HareDo::Plugin
5
+
6
+ UUID = 'status'
7
+
8
+ attr_accessor :plugins
9
+
10
+ def initialize(service, config)
11
+ super UUID, service, config
12
+
13
+ @plugins = {}
14
+ end
15
+
16
+ def process(msg)
17
+ data = {}
18
+ data['time'] = Time.now()
19
+ data['pid'] = Process.pid.to_s
20
+
21
+ plugins = []
22
+ @plugins.each do |k,v|
23
+ plugins << k
24
+ end
25
+
26
+ data['plugins'] = plugins
27
+
28
+ @peer.reply(msg, :data=>JSON::generate(data))
29
+ end
30
+
31
+ end # class Plugin
@@ -0,0 +1,128 @@
1
+ require 'haredo/peer'
2
+ require 'haredo/admin/interface'
3
+ require 'haredo/service/config'
4
+
5
+ module HareDo
6
+ module Admin
7
+ module Daemon
8
+
9
+ # The class implements to command line interface for configuration module
10
+ class Interface < Admin::Interface
11
+
12
+ include HareDo::Service::Config
13
+
14
+ def initialize()
15
+ super('daemon', 'Control daemon')
16
+
17
+ loadConfig()
18
+
19
+ @commands = {}
20
+
21
+ # Start the daemon
22
+ @commands['start'] = lambda do | name |
23
+ startCommand()
24
+ end
25
+
26
+ # Stop the daemon
27
+ @commands['stop'] = lambda do | name |
28
+ stopCommand()
29
+ end
30
+
31
+ # Check status
32
+ @commands['status'] = lambda do | name |
33
+ statusCommand()
34
+ end
35
+ end
36
+
37
+ def startCommand()
38
+ $stderr.puts 'Daemon start'
39
+
40
+ # Check if already running
41
+ if daemonPid() != nil
42
+ $stderr.puts 'Daemon already running'
43
+ return
44
+ end
45
+
46
+ fork do
47
+ Process.daemon()
48
+ exec('/usr/bin/haredo', '-d')
49
+ end
50
+ end
51
+
52
+ def statusCommand()
53
+ if daemonPid() != nil
54
+ client = connectBroker()
55
+ client.timeout = 3
56
+
57
+ response = client.call('haredo', :headers=>{'uuid'=>'status'})
58
+
59
+ if response != nil
60
+ puts response.data()
61
+ end
62
+
63
+ client.disconnect()
64
+ else
65
+ puts 'down'
66
+ end
67
+ end
68
+
69
+ def stopCommand()
70
+ $stderr.puts "stop #{daemonPid()}"
71
+
72
+ daemon_key = @config['daemon']['key']
73
+
74
+ client = connectBroker()
75
+
76
+ client.send( 'haredo',
77
+ :headers => {
78
+ 'command' => 'stop',
79
+ 'key' => daemon_key,
80
+ })
81
+
82
+ client.disconnect()
83
+ end
84
+
85
+ def help(opts)
86
+ puts opts
87
+ end
88
+
89
+ def parse(args)
90
+ opts = OptionParser.new do |opts|
91
+ opts.separator ''
92
+ opts.banner = "Manage the haredo daemon\n\n"
93
+ opts.banner += "Usage: config [options] { start | stop | status }"
94
+
95
+ opts.separator 'Available options:'
96
+
97
+ opts.on('-c', '--config [val]', String, 'Use specific config file (default /etc/haredo/system.yml)') do |file|
98
+ @configfile = file
99
+ end
100
+
101
+ opts.on('-p', '--pidfile [val]', String, 'Use specific PID file') do |pid|
102
+ @pid = pid
103
+ end
104
+
105
+ opts.on_tail("-h", "--help", "Display help") do
106
+ puts opts
107
+ exit
108
+ end
109
+ end
110
+
111
+ opts.parse!(args)
112
+
113
+ command = args[0].chomp
114
+
115
+ if not @commands.has_key?(command)
116
+ help opts
117
+
118
+ return
119
+ end
120
+
121
+ @commands[command].call(command)
122
+ end
123
+
124
+ end # class
125
+
126
+ end # module Daemon
127
+ end # module Admin
128
+ end # module HareDo
@@ -0,0 +1,29 @@
1
+ require 'yaml'
2
+
3
+ require 'haredo/config'
4
+
5
+ module HareDo
6
+ module Service
7
+
8
+ module Config
9
+
10
+ include HareDo::Config
11
+
12
+ # @return Returns PID of running daemon if it corresponds to a running
13
+ # process. Returns nil otherwise.
14
+ def daemonPid()
15
+ pid = File.open(@pid_file).read().strip.chomp
16
+
17
+ return nil if pid.size == 0
18
+
19
+ if Dir.exist?("/proc/#{pid}")
20
+ return pid
21
+ end
22
+
23
+ return nil
24
+ end
25
+
26
+ end # class Context
27
+
28
+ end # module Service
29
+ end # module HareDo
@@ -0,0 +1,141 @@
1
+ require 'syslog'
2
+ require 'haredo/service/config'
3
+
4
+ def dump_message(msg)
5
+ if msg.properties != nil
6
+ puts ' Headers:'
7
+ msg.properties.each do |k,v|
8
+ puts " #{k}: #{v}"
9
+ end
10
+ end
11
+
12
+ puts " Data: #{msg.data}"
13
+ puts
14
+ end
15
+
16
+ module HareDo
17
+ module Service
18
+
19
+ #-------------------------------------------------------------------------------
20
+ # The Daemon
21
+ #-------------------------------------------------------------------------------
22
+
23
+ class Daemon < HareDo::Peer
24
+
25
+ attr_reader :loaded_modules
26
+
27
+ include HareDo::Service::Config
28
+
29
+ def initialize(name='haredo')
30
+ super(name)
31
+
32
+ @name = name
33
+ @queue_name = 'haredo'
34
+ @queue_properties = {}
35
+ @loaded_modules = []
36
+
37
+ loadConfig()
38
+
39
+ account = @config['system']['broker']
40
+
41
+ connect( :user => account['user'],
42
+ :password => account['password'],
43
+ :host => account['host'],
44
+ :port => account['port'],
45
+ :vhost => account['vhost'],
46
+ :ssl => account['ssl'] )
47
+
48
+ @daemon_key = @config['daemon']['key']
49
+
50
+ # Load modules in config
51
+ daemon_conf = @config['daemon']
52
+ daemon_conf['modules'].each do |mod|
53
+ @loaded_modules << mod
54
+ require mod
55
+ end
56
+
57
+ # Use configuration file for queue name
58
+
59
+ if daemon_conf.has_key?('queue')
60
+ @queue_name = daemon_conf['queue']['name'] || 'haredo'
61
+ @queue_properties = daemon_conf['queue']['properties'] || {}
62
+ end
63
+
64
+ # Change module search path
65
+
66
+ plugin_conf = @config['daemon']['services'].each do |service_name, service_conf|
67
+
68
+ if service_conf.has_key?('path_prefix')
69
+ @plugins.module_path_prefix = service_conf['path_prefix']
70
+ end
71
+
72
+ @plugins.loadConfig(service_conf['plugins'])
73
+ end
74
+
75
+ # Load the status plugin
76
+ @plugins.module_path_prefix = 'haredo/plugins'
77
+ @plugins.load('status')
78
+ status_plugin = @plugins['status']
79
+ status_plugin.plugins = @plugins.loaded
80
+ end
81
+
82
+ # Defined the queue this service will listen on. Assumes a single-instance
83
+ # service therefore declares queue as exclusive.
84
+ def createQueue()
85
+ properties = {
86
+ :auto_delete => true,
87
+ :exclusive => true
88
+ }
89
+
90
+ @queue_properties.each do |k,v|
91
+ properties[k.to_sym] = v
92
+ end
93
+
94
+ return @channel.queue(@queue_name, properties)
95
+ end
96
+
97
+ def run(args={})
98
+
99
+ if not args.has_key?(:blocking)
100
+ args[:blocking] = true
101
+ end
102
+
103
+ if $syslog.nil?
104
+ Syslog.open('haredo', Syslog::LOG_PID,
105
+ Syslog::LOG_DAEMON | Syslog::LOG_LOCAL7)
106
+
107
+ Syslog.notice('Daemonizing')
108
+
109
+ $syslog = true
110
+ end
111
+
112
+ # Write PID file out
113
+ file = File.open(@pid_file, 'w')
114
+ file.write(Process.pid.to_s)
115
+ file.close()
116
+
117
+ listen(args)
118
+ end
119
+
120
+ def serve(msg)
121
+ data = msg.headers['i'].to_i + 1
122
+
123
+ if msg.headers.has_key?('command')
124
+ if msg.headers['key'] == @daemon_key
125
+ Syslog.notice('Exiting')
126
+ disconnect()
127
+ return
128
+ end
129
+ end
130
+
131
+ @plugins.process(msg)
132
+ end
133
+
134
+ def shutdown()
135
+ @plugins.shutdown()
136
+ end
137
+
138
+ end # class
139
+
140
+ end # module Service
141
+ end # module HareDo
@@ -1,5 +1,11 @@
1
+ # Version information. Auto-generated by CMake.
1
2
  module HareDo
2
3
 
3
- VERSION = '0.0.5-1'
4
+ VERSION_MAJ = '2'
5
+ VERSION_MIN = '0'
6
+ VERSION_CL = '-beta'
7
+ VERSION_PL = '0'
8
+ VERSION = '2.0.0-beta-1'
9
+ RELEASE_DATE = 'Tue, 01 Oct 2013 15:16:38 -0500'
4
10
 
5
11
  end # module HareDo
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haredo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Owens
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: src/bin
10
10
  cert_chain: []
11
- date: 2013-09-23 00:00:00.000000000 Z
11
+ date: 2013-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -24,18 +24,31 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- description:
27
+ description: A P2P framework over RabbitMQ
28
28
  email: mikeowens@gmail.com
29
- executables: []
29
+ executables:
30
+ - haredo
30
31
  extensions: []
31
32
  extra_rdoc_files:
32
33
  - README.md
33
34
  files:
35
+ - src/lib/haredo/admin/config.rb
36
+ - src/lib/haredo/admin/interface.rb
37
+ - src/lib/haredo/config.rb
34
38
  - src/lib/haredo/peer.rb
39
+ - src/lib/haredo/plugin.rb
40
+ - src/lib/haredo/plugins/echo.rb
41
+ - src/lib/haredo/plugins/example.rb
42
+ - src/lib/haredo/plugins/status.rb
43
+ - src/lib/haredo/service/admin/daemon.rb
44
+ - src/lib/haredo/service/config.rb
45
+ - src/lib/haredo/service/daemon.rb
35
46
  - src/lib/haredo/version.rb
47
+ - src/bin/haredo
36
48
  - README.md
37
49
  homepage: https://github.com/mikeowens/haredo
38
- licenses: []
50
+ licenses:
51
+ - MIT
39
52
  metadata: {}
40
53
  post_install_message:
41
54
  rdoc_options: []