-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdig.rb
More file actions
59 lines (47 loc) · 1.35 KB
/
dig.rb
File metadata and controls
59 lines (47 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# encoding: utf-8
module DHTDigger
module Diggers
end
end
require 'logger'
require 'yaml'
require_relative 'diggers/wiretap'
config = YAML.load_file("#{File.dirname(__FILE__)}/configuration/config.yml")
redis_config = config['redis']
wiretap_options = config['wiretap_options']
dht_hosts = config['dht_hosts']
logging_config = config['logging']
wiretap_config = config['wiretap']
file_path = config['pid_path']
unless File.exist?(file_path)
File.open(file_path, 'w') do |file|
file.write(Process.pid)
end
end
all_diggers = []
trap('TERM') do
puts 'Receiving terminate signal ...'
all_diggers.each { |pid| Process.kill(:TERM, pid)}
exit
end
wiretap_config.each do |each_config|
all_diggers << fork do
name = each_config['name']
host = each_config['host']
port = each_config['port']
private_logger = Logger.new("#{logging_config['output']}#{name}.log")
private_logger.level = Logger.const_get(logging_config['level']) || Logger::INFO
single_digger = DHTDigger::Diggers::Wiretap.new(
host, port, dht_hosts, redis_config, private_logger, wiretap_options)
single_digger.setup
single_digger.run
end
end
at_exit do
# check PID file and delete it
puts 'Deleting PID file'
File.delete(file_path) if File.exist?(file_path)
puts 'Exiting ...'
end
puts "Starting #{all_diggers.size} digger(s) ..."
Process.waitall