forked from cloudfoundry-attic/stager
/
stager
executable file
·59 lines (49 loc) · 1.62 KB
/
stager
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
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'rubygems'
require 'bundler/setup'
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
require 'vcap/common'
require 'vcap/component'
require 'vcap/concurrency'
require 'vcap/stager'
sleep_interval = 1
if ENV["CLOUD_FOUNDRY_CONFIG_PATH"]
config_file = File.join(ENV["CLOUD_FOUNDRY_CONFIG_PATH"], "stager.yml")
else
config_file = VCAP::Stager::Config::DEFAULT_CONFIG_PATH
end
OptionParser.new do |op|
op.on('-c', '--config [FILENAME]', 'Config filename') do |val|
config_file = val
end
op.on('-s', '--sleep-interval [SECONDS]', 'How long to sleep between dequeing') do |val|
sleep_interval = val.to_i
end
end.parse!
begin
config = VCAP::Stager::Config.from_file(config_file)
rescue VCAP::JsonSchema::ValidationError => ve
puts "ERROR: There was a problem validating the supplied config: #{ve}"
exit 1
rescue => e
puts "ERROR: Failed loading config from file '#{config_file}': #{e}"
exit 1
end
begin
pid_file = VCAP::PidFile.new(config[:pid_filename])
pid_file.unlink_at_exit
rescue => e
puts "ERROR: Can't create stager pid file #{config[:pid_filename]}"
exit 1
end
ENV['TMPDIR'] = config[:dirs][:tmp] if config[:dirs] && config[:dirs][:tmp]
VCAP::Stager.init(config)
user_mgr=nil
if config[:secure]
VCAP::Stager::SecureUserManager.instance.setup
user_mgr = VCAP::Concurrency::Proxy.new(VCAP::Stager::SecureUserManager.instance)
end
thread_pool = VCAP::Concurrency::ThreadPool.new(config[:max_active_tasks])
server = VCAP::Stager::Server.new(config[:nats_uri], thread_pool, user_mgr, config)
server.run