-
Notifications
You must be signed in to change notification settings - Fork 0
/
master.rb
55 lines (49 loc) · 1.54 KB
/
master.rb
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
# Launches the worker and initiates updates
require File.expand_path( File.join( File.dirname(__FILE__), 'server' ) )
class Master
attr_reader :worker, :api_config, :local_config
def initialize
# config files are loaded relative to working dir, not this file
@api_config = Configuration.new 'servers.yml' # relative to working dir
@local_config = Configuration.new File.join( File.dirname(__FILE__), 'master.yml' ) # in repo folder
@worker = Server.new @api_config, 'worker'
@update_cmd = @local_config['update_cmd']
@log_path = @local_config['log_path']
end
# Initiate the update on the worker
def initiate_update options
puts '-'*60
puts "Starting update at #{Time.now}"
@worker.up
puts "Initiating worker at #{Time.now}."
if @worker.initiate "#{@local_config['worker_bin']} #{options.join(' ')} >> #{@log_path}"
puts 'View log file on worker to check progress'
#we're done, worker will shut itself down after it finishes
else
raise 'Failed to initiate worker!'
end
rescue Exception => e
puts e
puts e.backtrace
@worker.shutdown
ensure
puts
end
# Read command line options and take action
def run argv
if argv[0]=='run'
argv.shift
initiate_update argv
elsif argv[0]=='up'
@worker.up
elsif argv[0]=='down'
@worker.down
elsif argv[0]=='status'
puts "Worker is #{@worker.status}"
elsif argv[0]=='test'
puts "Test at #{Time.now}."
else
puts "Unknown option #{argv[0]}!"
end
end
end