invoker 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -0
- data/.rubocop.yml +30 -0
- data/.travis.yml +1 -0
- data/Gemfile +1 -0
- data/bin/invoker +4 -8
- data/invoker.gemspec +10 -11
- data/lib/invoker.rb +95 -21
- data/lib/invoker/cli.rb +126 -0
- data/lib/invoker/cli/pinger.rb +23 -0
- data/lib/invoker/cli/question.rb +15 -0
- data/lib/invoker/cli/tail.rb +34 -0
- data/lib/invoker/cli/tail_watcher.rb +34 -0
- data/lib/invoker/command_worker.rb +28 -2
- data/lib/invoker/commander.rb +34 -236
- data/lib/invoker/config.rb +5 -0
- data/lib/invoker/daemon.rb +126 -0
- data/lib/invoker/dns_cache.rb +23 -0
- data/lib/invoker/errors.rb +1 -0
- data/lib/invoker/ipc.rb +45 -0
- data/lib/invoker/ipc/add_command.rb +12 -0
- data/lib/invoker/ipc/add_http_command.rb +10 -0
- data/lib/invoker/ipc/base_command.rb +24 -0
- data/lib/invoker/ipc/client_handler.rb +26 -0
- data/lib/invoker/ipc/dns_check_command.rb +16 -0
- data/lib/invoker/ipc/list_command.rb +11 -0
- data/lib/invoker/ipc/message.rb +170 -0
- data/lib/invoker/ipc/message/list_response.rb +33 -0
- data/lib/invoker/ipc/message/tail_response.rb +10 -0
- data/lib/invoker/ipc/ping_command.rb +10 -0
- data/lib/invoker/ipc/reload_command.rb +12 -0
- data/lib/invoker/ipc/remove_command.rb +12 -0
- data/lib/invoker/{command_listener → ipc}/server.rb +6 -11
- data/lib/invoker/ipc/tail_command.rb +11 -0
- data/lib/invoker/ipc/unix_client.rb +60 -0
- data/lib/invoker/parsers/config.rb +1 -0
- data/lib/invoker/power/balancer.rb +17 -7
- data/lib/invoker/power/config.rb +6 -3
- data/lib/invoker/power/dns.rb +22 -21
- data/lib/invoker/power/http_response.rb +1 -1
- data/lib/invoker/power/power.rb +3 -0
- data/lib/invoker/power/powerup.rb +3 -2
- data/lib/invoker/power/setup.rb +6 -4
- data/lib/invoker/process_manager.rb +187 -0
- data/lib/invoker/process_printer.rb +27 -38
- data/lib/invoker/reactor.rb +19 -38
- data/lib/invoker/reactor/reader.rb +53 -0
- data/lib/invoker/version.rb +1 -1
- data/readme.md +1 -1
- data/spec/invoker/cli/pinger_spec.rb +22 -0
- data/spec/invoker/cli/tail_watcher_spec.rb +39 -0
- data/spec/invoker/cli_spec.rb +27 -0
- data/spec/invoker/command_worker_spec.rb +30 -0
- data/spec/invoker/commander_spec.rb +57 -127
- data/spec/invoker/config_spec.rb +21 -0
- data/spec/invoker/daemon_spec.rb +34 -0
- data/spec/invoker/invoker_spec.rb +31 -0
- data/spec/invoker/ipc/client_handler_spec.rb +44 -0
- data/spec/invoker/ipc/dns_check_command_spec.rb +32 -0
- data/spec/invoker/ipc/message/list_response_spec.rb +22 -0
- data/spec/invoker/ipc/message_spec.rb +45 -0
- data/spec/invoker/ipc/unix_client_spec.rb +29 -0
- data/spec/invoker/power/setup_spec.rb +1 -1
- data/spec/invoker/process_manager_spec.rb +98 -0
- data/spec/invoker/reactor_spec.rb +6 -0
- data/spec/spec_helper.rb +15 -24
- metadata +107 -77
- data/lib/invoker/command_listener/client.rb +0 -45
- data/lib/invoker/parsers/option_parser.rb +0 -106
- data/lib/invoker/power.rb +0 -7
- data/lib/invoker/runner.rb +0 -98
- data/spec/invoker/command_listener/client_spec.rb +0 -52
data/lib/invoker/power.rb
DELETED
data/lib/invoker/runner.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
require "slop"
|
2
|
-
require "ostruct"
|
3
|
-
require "socket"
|
4
|
-
|
5
|
-
module Invoker
|
6
|
-
class Runner
|
7
|
-
def self.run(args)
|
8
|
-
selected_command = Invoker::Parsers::OptionParser.parse(args)
|
9
|
-
if selected_command
|
10
|
-
run_command(selected_command)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.run_command(selected_command)
|
15
|
-
return unless selected_command
|
16
|
-
case selected_command.command
|
17
|
-
when 'version'
|
18
|
-
emit_version
|
19
|
-
when 'setup'
|
20
|
-
setup_pow(selected_command)
|
21
|
-
when 'uninstall'
|
22
|
-
uninstall_pow(selected_command)
|
23
|
-
when 'start'
|
24
|
-
start_server(selected_command)
|
25
|
-
when 'add'
|
26
|
-
add_command(selected_command)
|
27
|
-
when 'reload'
|
28
|
-
refresh_command(selected_command)
|
29
|
-
when 'list'
|
30
|
-
list_commands(selected_command)
|
31
|
-
when 'remove'
|
32
|
-
remove_command(selected_command)
|
33
|
-
else
|
34
|
-
Invoker::Logger.puts "Invalid command"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.emit_version
|
39
|
-
Invoker::Logger.puts Invoker::VERSION
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.setup_pow(selected_command)
|
43
|
-
Invoker::Power::Setup.install()
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.uninstall_pow(selected_command)
|
47
|
-
Invoker::Power::Setup.uninstall()
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.start_server(selected_command)
|
51
|
-
config = Invoker::Parsers::Config.new(selected_command.file, selected_command.port)
|
52
|
-
Invoker.const_set(:CONFIG, config)
|
53
|
-
warn_about_terminal_notifier()
|
54
|
-
commander = Invoker::Commander.new()
|
55
|
-
Invoker.const_set(:COMMANDER, commander)
|
56
|
-
commander.start_manager()
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.add_command(selected_command)
|
60
|
-
Socket.unix(Invoker::CommandListener::Server::SOCKET_PATH) do |socket|
|
61
|
-
socket.puts("add #{selected_command.command_key}")
|
62
|
-
socket.flush()
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def self.remove_command(selected_command)
|
67
|
-
Socket.unix(Invoker::CommandListener::Server::SOCKET_PATH) do |socket|
|
68
|
-
socket.puts("remove #{selected_command.command_key} #{selected_command.signal}")
|
69
|
-
socket.flush()
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.refresh_command(selected_command)
|
74
|
-
Socket.unix(Invoker::CommandListener::Server::SOCKET_PATH) do |socket|
|
75
|
-
socket.puts("reload #{selected_command.command_key} #{selected_command.signal}")
|
76
|
-
socket.flush()
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def self.list_commands(selected_command)
|
81
|
-
Socket.unix(Invoker::CommandListener::Server::SOCKET_PATH) {|sock|
|
82
|
-
sock.puts("list")
|
83
|
-
data = sock.gets()
|
84
|
-
Invoker::ProcessPrinter.print_table(data)
|
85
|
-
}
|
86
|
-
end
|
87
|
-
|
88
|
-
def self.warn_about_terminal_notifier
|
89
|
-
if RUBY_PLATFORM.downcase.include?("darwin")
|
90
|
-
command_path = `which terminal-notifier`
|
91
|
-
if !command_path || command_path.empty?
|
92
|
-
Invoker::Logger.puts("You can enable OSX notification for processes by installing terminal-notifier gem".color(:red))
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Invoker::CommandListener::Client do
|
4
|
-
describe "add command" do
|
5
|
-
before do
|
6
|
-
@client_socket = mock()
|
7
|
-
@client = Invoker::CommandListener::Client.new(@client_socket)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should run if read from socket" do
|
11
|
-
invoker_commander.expects(:on_next_tick).with("foo")
|
12
|
-
@client_socket.expects(:gets).returns("add foo\n")
|
13
|
-
|
14
|
-
@client.read_and_execute()
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "remove command" do
|
19
|
-
before do
|
20
|
-
@client_socket = mock()
|
21
|
-
@client = Invoker::CommandListener::Client.new(@client_socket)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "with specific signal" do
|
25
|
-
invoker_commander.expects(:on_next_tick).with("foo", "9")
|
26
|
-
@client_socket.expects(:gets).returns("remove foo 9\n")
|
27
|
-
|
28
|
-
@client.read_and_execute()
|
29
|
-
end
|
30
|
-
|
31
|
-
it "with default signal" do
|
32
|
-
invoker_commander.expects(:on_next_tick).with("foo",nil)
|
33
|
-
@client_socket.expects(:gets).returns("remove foo\n")
|
34
|
-
|
35
|
-
@client.read_and_execute()
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "invalid command" do
|
40
|
-
before do
|
41
|
-
@client_socket = mock()
|
42
|
-
@client = Invoker::CommandListener::Client.new(@client_socket)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should print error if read from socket" do
|
46
|
-
invoker_commander.expects(:on_next_tick).never()
|
47
|
-
@client_socket.expects(:gets).returns("eugh foo\n")
|
48
|
-
|
49
|
-
@client.read_and_execute
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|