smith 0.7.7 → 0.7.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/agency +5 -1
- data/bin/smithctl +13 -6
- data/config/smithrc.toml +3 -0
- data/lib/smith/agent_monitoring.rb +1 -1
- data/lib/smith/application/agency.rb +1 -1
- data/lib/smith/commands/agency/restart.rb +1 -1
- data/lib/smith/commands/common.rb +28 -10
- data/lib/smith/commands/smithctl/status.rb +2 -2
- data/lib/smith/daemon.rb +20 -1
- data/lib/smith/queue_definitions.rb +4 -1
- data/lib/smith/utils.rb +2 -2
- data/lib/smith/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 672819de30ca51cefb95f9b58f975574bb59b24a
|
4
|
+
data.tar.gz: bbc895d5842922f23e866086c549010bb0ec58f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c87facd4414ed52f8380f718ec7585567bb850e1f9928cdc8462ace844575eae1610eaf7164d302f22a36cce7819f0912959e505a9a09d9f3ac85a83a65a5ad
|
7
|
+
data.tar.gz: 944f322a51b2b8c90c606238565c513e64503024277a3bcf2d6513cc2869ce039ffda9a4dc65b081579858ac9e1b7cd7437eff13400edbfaac503d7dbbe85977
|
data/bin/agency
CHANGED
@@ -24,7 +24,11 @@ module Smith
|
|
24
24
|
|
25
25
|
@daemon = Daemon.new(add_vhost(AGENCY_NAME), opts[:daemon], opts[:pid_dir])
|
26
26
|
|
27
|
-
|
27
|
+
if @daemon.running?
|
28
|
+
msg = "An agency with pid: #{@daemon.pid} is already running"
|
29
|
+
logger.fatal { msg}
|
30
|
+
raise AgencyRunning, msg
|
31
|
+
end
|
28
32
|
|
29
33
|
@agency = Agency.new
|
30
34
|
|
data/bin/smithctl
CHANGED
@@ -20,7 +20,9 @@ module Smith
|
|
20
20
|
|
21
21
|
def initialize(options={})
|
22
22
|
log_level((options[:log_level_given]) ? options[:log_level].to_sym : :warn)
|
23
|
+
|
23
24
|
@timeout = (options[:timeout_given]) ? options[:timeout] : Smith.config.smith.timeout
|
25
|
+
@node = options[:node]
|
24
26
|
end
|
25
27
|
|
26
28
|
def send_command(command, args, &blk)
|
@@ -38,7 +40,7 @@ module Smith
|
|
38
40
|
end
|
39
41
|
|
40
42
|
def agency_command(command, args, &blk)
|
41
|
-
Messaging::Sender.new(QueueDefinitions::Agency_control) do |sender|
|
43
|
+
Messaging::Sender.new(QueueDefinitions::Agency_control.call(@node)) do |sender|
|
42
44
|
sender.on_timeout(@timeout) { |message_id| blk.call("Timeout. Is the agency still running?") }
|
43
45
|
|
44
46
|
sender.on_reply(:auto_ack => true) do |reply_payload, r|
|
@@ -70,16 +72,21 @@ Usage:
|
|
70
72
|
stop_on Command.commands
|
71
73
|
opt :log_level, "Set the log level of smithctl only.", :short => :l, :type => :string
|
72
74
|
opt :timeout, "Specify the timeout when communicating with the agency.", :short => :t, :type => :integer, :default => 60
|
75
|
+
opt :node, "Specify the agency node to connect to.", :type => :string, :short => :none
|
73
76
|
end
|
74
77
|
|
75
78
|
opts = Trollop::with_standard_exception_handling parser do
|
76
79
|
raise Trollop::HelpNeeded if ARGV.size < 1
|
77
|
-
parser.parse(ARGV)
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
80
|
+
parser.parse(ARGV)
|
81
|
+
end
|
82
|
+
|
83
|
+
if ARGV.size > 0
|
84
|
+
if ! Command.commands.include?(ARGV.first)
|
85
|
+
puts "Unknown command: #{ARGV.first}"
|
86
|
+
exit 1
|
82
87
|
end
|
88
|
+
else
|
89
|
+
raise Trollop::HelpNeeded
|
83
90
|
end
|
84
91
|
|
85
92
|
command = ARGV.shift.dup
|
data/config/smithrc.toml
CHANGED
@@ -21,6 +21,9 @@ kqueue = true
|
|
21
21
|
pid_directory = "~/.smith/run"
|
22
22
|
cache_directory = "~/.smith/cache"
|
23
23
|
|
24
|
+
# This is the directory that will contain the agent groups
|
25
|
+
group_directory = "groups"
|
26
|
+
|
24
27
|
# It would be better to use inline tables here but there is a bug in
|
25
28
|
# toml-rb: https://github.com/emancu/toml-rb/issues/57.
|
26
29
|
# TODO: Change these to inline tables when this bug is fixed.
|
@@ -36,7 +36,7 @@ module Smith
|
|
36
36
|
logger.info { "Agent is shutting down: #{agent_process.name}" }
|
37
37
|
when 'dead'
|
38
38
|
logger.info { "Restarting dead agent: #{agent_process.name}" }
|
39
|
-
Messaging::Sender.new(QueueDefinitions::Agency_control) do |sender|
|
39
|
+
Messaging::Sender.new(QueueDefinitions::Agency_control.call) do |sender|
|
40
40
|
sender.on_reply { |p, r| logger.debug { "Agent restart message acknowledged: #{agent_process.name}" } }
|
41
41
|
sender.publish(ACL::AgencyCommand.new(:command => 'start', :args => [agent_process.name]))
|
42
42
|
end
|
@@ -18,7 +18,7 @@ module Smith
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def setup_queues
|
21
|
-
Messaging::Receiver.new(QueueDefinitions::Agency_control, :auto_ack => false) do |receiver|
|
21
|
+
Messaging::Receiver.new(QueueDefinitions::Agency_control.call, :auto_ack => false) do |receiver|
|
22
22
|
receiver.subscribe do |payload, responder|
|
23
23
|
|
24
24
|
completion = EM::Completion.new.tap do |c|
|
@@ -12,7 +12,7 @@ module Smith
|
|
12
12
|
include Common
|
13
13
|
|
14
14
|
def execute
|
15
|
-
Messaging::Sender.new(QueueDefinitions::Agency_control) do |sender|
|
15
|
+
Messaging::Sender.new(QueueDefinitions::Agency_control.call) do |sender|
|
16
16
|
@sender = sender
|
17
17
|
|
18
18
|
# agent is a method and as such I cannot pass it into the block.
|
@@ -5,7 +5,7 @@ module Smith
|
|
5
5
|
|
6
6
|
# Returns the fully qualified class of all agents in a group. The group
|
7
7
|
# //must// be a sub-directory in the agents directory. Only sym-links are
|
8
|
-
# considered. The group directory is recursively searched and
|
8
|
+
# considered. The group directory is recursively searched and added to
|
9
9
|
# the ilst of agents for that group if it passed all checks.
|
10
10
|
#
|
11
11
|
# @param group [String] the group name
|
@@ -13,19 +13,20 @@ module Smith
|
|
13
13
|
# @return [Array<Class>] the class of each agent in the group
|
14
14
|
def agent_group(group)
|
15
15
|
agents = Smith.agent_directories.map do |agent_directory|
|
16
|
-
group_directory
|
16
|
+
group_directory(agent_directory, group) do |group_directory, groups_prefix|
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
if group_directory.exist? && group_directory.directory?
|
19
|
+
agents = Pathname.glob(group_directory.join("*.rb")).map(&:expand_path)
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
agents.inject([]) do |acc, agent|
|
22
|
+
if agent.symlink?
|
23
|
+
expanded_agent_path = resolve_agent_path(group_directory, agent)
|
24
|
+
acc << Utils.class_name_from_path(expanded_agent_path, agent_directory, groups_prefix)
|
25
|
+
end
|
25
26
|
end
|
27
|
+
else
|
28
|
+
nil
|
26
29
|
end
|
27
|
-
else
|
28
|
-
nil
|
29
30
|
end
|
30
31
|
end.uniq
|
31
32
|
|
@@ -38,6 +39,23 @@ module Smith
|
|
38
39
|
def resolve_agent_path(group_directory, agent)
|
39
40
|
agent.readlink.expand_path(group_directory)
|
40
41
|
end
|
42
|
+
|
43
|
+
# Return the group directory. This checks to see if the directory "groups"
|
44
|
+
# exists and if it does it appends the group name to that otherwise it appends
|
45
|
+
# it to the agent directory.
|
46
|
+
#
|
47
|
+
# @param path [Pathname] the agent directory
|
48
|
+
# @param group [String] the group name
|
49
|
+
#
|
50
|
+
# @return [Pathname] the group directory
|
51
|
+
def group_directory(path, group, &blk)
|
52
|
+
dir = path.join(Smith.config.agency.group_directory)
|
53
|
+
if dir.exist?
|
54
|
+
blk.call(dir.join(group), Smith.config.agency.group_directory)
|
55
|
+
else
|
56
|
+
blk.call(path.join(group), nil)
|
57
|
+
end
|
58
|
+
end
|
41
59
|
end
|
42
60
|
end
|
43
61
|
end
|
@@ -12,7 +12,7 @@ module Smith
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def status(&blk)
|
15
|
-
Messaging::Queue.number_of_consumers(QueueDefinitions::Agency_control) do |consumers_count|
|
15
|
+
Messaging::Queue.number_of_consumers(QueueDefinitions::Agency_control.call) do |consumers_count|
|
16
16
|
blk.call(consumers_count > 0)
|
17
17
|
end
|
18
18
|
end
|
@@ -20,7 +20,7 @@ module Smith
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def options_spec
|
23
|
-
banner "Shows the status of the agency
|
23
|
+
banner "Shows the status of the agency — ONLY WORKS LOCALLY"
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
data/lib/smith/daemon.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'daemons/daemonize'
|
4
4
|
require 'daemons/pidfile'
|
5
|
+
require 'sys/proctable'
|
5
6
|
|
6
7
|
require 'smith/utils'
|
7
8
|
|
@@ -52,10 +53,16 @@ module Smith
|
|
52
53
|
false
|
53
54
|
else
|
54
55
|
pid = File.read(pid_files.first).to_i
|
55
|
-
pid > 0 && Daemons::Pid.running?(pid)
|
56
|
+
pid > 0 && Daemons::Pid.running?(pid) && process_names_match?(@name, pid)
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
60
|
+
# Return the pid of the process
|
61
|
+
# @return the pid or nil if not set.
|
62
|
+
def pid
|
63
|
+
@pid.pid
|
64
|
+
end
|
65
|
+
|
59
66
|
def unlink_pid_file
|
60
67
|
p = Pathname.new(@pid.filename)
|
61
68
|
if p.exist?
|
@@ -66,6 +73,18 @@ module Smith
|
|
66
73
|
|
67
74
|
private
|
68
75
|
|
76
|
+
# Checks to see if running process that matches the pid in the pid matches
|
77
|
+
# the name.
|
78
|
+
# @param name [String] the name of the process
|
79
|
+
#
|
80
|
+
# @param pid [Integer] the pid of the process
|
81
|
+
#
|
82
|
+
# @return true if the running process matches the name
|
83
|
+
def process_names_match?(name, pid)
|
84
|
+
proc_table = Sys::ProcTable.ps(pid)
|
85
|
+
proc_table && proc_table.cmdline == name
|
86
|
+
end
|
87
|
+
|
69
88
|
# Get the pid directory. This checks for the command line option,
|
70
89
|
# then the config and finally use the tmp directory.
|
71
90
|
def pid_directory(dir)
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
module Smith
|
4
4
|
module QueueDefinitions
|
5
|
-
Agency_control = QueueDefinition.new("#{Smith.hostname}.agency.control", :auto_ack => false, :durable => true, :persistent => false, :strict => true)
|
6
5
|
Agent_keepalive = QueueDefinition.new("#{Smith.hostname}.agent.keepalive", :auto_delete => false, :durable => true)
|
7
6
|
Agent_lifecycle = QueueDefinition.new("#{Smith.hostname}.agent.lifecycle", :auto_delete => false, :durable => true)
|
8
7
|
|
@@ -10,5 +9,9 @@ module Smith
|
|
10
9
|
|
11
10
|
# Something tells me that I've crossed line with this.
|
12
11
|
Agent_control = ->(uuid) { QueueDefinition.new("agent.control.#{uuid}", :durable => false, :auto_delete => true) }
|
12
|
+
|
13
|
+
Agency_control = ->(node=nil) {
|
14
|
+
QueueDefinition.new("#{node || Smith.hostname}.agency.control", :auto_ack => false, :durable => true, :persistent => false, :strict => true)
|
15
|
+
}
|
13
16
|
end
|
14
17
|
end
|
data/lib/smith/utils.rb
CHANGED
@@ -27,9 +27,9 @@ module Smith
|
|
27
27
|
module_function :path_from_class
|
28
28
|
|
29
29
|
# Returns a Constant based on the pathname.
|
30
|
-
def class_name_from_path(path, root=Pathname.new('.'))
|
30
|
+
def class_name_from_path(path, root=Pathname.new('.'), segment_to_remove=nil)
|
31
31
|
relative_path = path.relative_path_from(root)
|
32
|
-
parts = split_path(relative_path.sub_ext(''))
|
32
|
+
parts = split_path(relative_path.sub_ext('')).reject { |p| p == segment_to_remove }
|
33
33
|
|
34
34
|
parts.map { |p| p.to_s.camel_case }.join('::')
|
35
35
|
end
|
data/lib/smith/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smith
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Heycock
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: amqp
|
@@ -198,6 +198,20 @@ dependencies:
|
|
198
198
|
- - "~>"
|
199
199
|
- !ruby/object:Gem::Version
|
200
200
|
version: '0.3'
|
201
|
+
- !ruby/object:Gem::Dependency
|
202
|
+
name: sys-proctable
|
203
|
+
requirement: !ruby/object:Gem::Requirement
|
204
|
+
requirements:
|
205
|
+
- - "~>"
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: 0.9.0
|
208
|
+
type: :runtime
|
209
|
+
prerelease: false
|
210
|
+
version_requirements: !ruby/object:Gem::Requirement
|
211
|
+
requirements:
|
212
|
+
- - "~>"
|
213
|
+
- !ruby/object:Gem::Version
|
214
|
+
version: 0.9.0
|
201
215
|
- !ruby/object:Gem::Dependency
|
202
216
|
name: oj
|
203
217
|
requirement: !ruby/object:Gem::Requirement
|