epi 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/bin/epi +1 -1
  3. data/lib/epi/cli/command.rb +7 -0
  4. data/lib/epi/cli/commands/concerns/daemon.rb +33 -0
  5. data/lib/epi/cli/commands/config.rb +11 -3
  6. data/lib/epi/cli/commands/daemon.rb +14 -0
  7. data/lib/epi/cli/commands/help.rb +0 -0
  8. data/lib/epi/cli/commands/job.rb +1 -1
  9. data/lib/epi/cli/commands/restart.rb +16 -0
  10. data/lib/epi/cli/commands/start.rb +15 -0
  11. data/lib/epi/cli/commands/status.rb +6 -2
  12. data/lib/epi/cli/commands/stop.rb +16 -0
  13. data/lib/epi/cli.rb +1 -1
  14. data/lib/epi/connection.rb +7 -0
  15. data/lib/epi/core_ext/inflector.rb +1 -1
  16. data/lib/epi/daemon/receiver.rb +37 -0
  17. data/lib/epi/{server → daemon}/responder.rb +14 -5
  18. data/lib/epi/{server → daemon}/responders/config.rb +14 -2
  19. data/lib/epi/{server → daemon}/responders/job.rb +5 -6
  20. data/lib/epi/{server → daemon}/responders/shutdown.rb +1 -1
  21. data/lib/epi/daemon/responders/start.rb +19 -0
  22. data/lib/epi/{server → daemon}/responders/status.rb +4 -2
  23. data/lib/epi/daemon/responders/stop_all.rb +20 -0
  24. data/lib/epi/daemon/sender.rb +74 -0
  25. data/lib/epi/{server.rb → daemon.rb} +26 -27
  26. data/lib/epi/data.rb +4 -5
  27. data/lib/epi/job.rb +60 -2
  28. data/lib/epi/job_description.rb +6 -8
  29. data/lib/epi/jobs.rb +30 -2
  30. data/lib/epi/launch.rb +1 -1
  31. data/lib/epi/logging.rb +33 -0
  32. data/lib/epi/process_status.rb +1 -1
  33. data/lib/epi/running_process.rb +21 -3
  34. data/lib/epi/trigger.rb +53 -0
  35. data/lib/epi/triggers/concerns/comparison.rb +43 -0
  36. data/lib/epi/triggers/memory.rb +16 -0
  37. data/lib/epi/triggers/touch.rb +37 -0
  38. data/lib/epi/triggers/uptime.rb +12 -0
  39. data/lib/epi/version.rb +1 -1
  40. data/lib/epi.rb +4 -22
  41. metadata +26 -26
  42. data/lib/epi/cli/commands/server.rb +0 -38
  43. data/lib/epi/server/receiver.rb +0 -46
  44. data/lib/epi/server/responders/command.rb +0 -15
  45. data/lib/epi/server/sender.rb +0 -64
@@ -1,46 +0,0 @@
1
- require 'eventmachine'
2
- require 'bson'
3
-
4
- module Epi
5
- module Server
6
- class Receiver < EventMachine::Connection
7
-
8
- def logger
9
- Epi.logger
10
- end
11
-
12
- def receive_data(data)
13
- response = begin
14
- data = Hash.from_bson StringIO.new data
15
- logger.debug "Received message of type '#{data['type']}'"
16
- {result: Responder.run(self, data.delete('type').to_s, data)}
17
- rescue Exceptions::Shutdown
18
- self.should_shut_down = true
19
- {result: 'Server is shutting down'}
20
- rescue => error
21
- {error: {
22
- class: error.class.name,
23
- message: error.message,
24
- backtrace: error.backtrace
25
- }}
26
- end
27
- response[:complete] = true
28
- send_data response.to_bson
29
- Server.shutdown if should_shut_down
30
- end
31
-
32
- def puts(text)
33
- data = {
34
- result: "#{text}\n",
35
- complete: false
36
- }
37
- send_data data.to_bson
38
- end
39
-
40
- private
41
-
42
- attr_accessor :should_shut_down
43
-
44
- end
45
- end
46
- end
@@ -1,15 +0,0 @@
1
- module Epi
2
- module Server
3
- module Responders
4
- class Command < Responder
5
-
6
- attr_accessor :command, :arguments
7
-
8
- def run
9
- Cli::Command.run command, arguments
10
- end
11
-
12
- end
13
- end
14
- end
15
- end
@@ -1,64 +0,0 @@
1
- require 'eventmachine'
2
- require 'bson'
3
-
4
- module Epi
5
- module Server
6
- class Sender < EventMachine::Connection
7
- include Exceptions
8
-
9
- # Send a message to the Epi server
10
- #
11
- # @example Get Epi's status
12
- # Sender.send command: {command: 'status', arguments: []}
13
- #
14
- # @example Shut down the server
15
- # Sender.send :shutdown
16
- #
17
- # @param what [Hash|Symbol] Either a symbol being the message type, or a hash
18
- # with a single key (a symbol) being the message type, and value (a hash) being the message.
19
- def self.send(what)
20
-
21
- raise ArgumentError, 'Expected a hash with one key (a symbol) and value (a hash)' unless
22
- Symbol === what ||
23
- (Hash === what && what.count == 1 && Symbol === what.keys.first && Hash === what.values.first)
24
-
25
- data = case what
26
- when Symbol then {type: what}
27
- when Hash then what.values.first.merge(type: what.keys.first)
28
- else nil
29
- end
30
-
31
- EventMachine.connect Server.socket_path.to_s, Sender, data
32
-
33
- end
34
-
35
- def initialize(data)
36
- send_data data.to_bson
37
- end
38
-
39
- def receive_data(data)
40
- data = Hash.from_bson StringIO.new data
41
-
42
- if data['result']
43
- puts data['result']
44
-
45
- elsif data['error']
46
- error = data['error']
47
- if error['class'] == Fatal.name
48
- STDERR << error['message']
49
- STDERR << "\n"
50
- else
51
- puts "#{error['class']}: #{error['message']}"
52
- error['backtrace'].each { |x| puts ' ' << x }
53
- end
54
- end
55
-
56
- if data['complete']
57
- close_connection
58
- EventMachine.stop_event_loop
59
- end
60
- end
61
-
62
- end
63
- end
64
- end