mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Previously, if you ran the vpooler via ruby, pressing Ctrl-C would terminate the Webserver however the PoolManager does not have a handler and would instead just keep executing. This commit adds a global Ctrl-C hook which terminates both the api and manager threads. This behaviour will only be enabled if the `VMPOOLER_DEBUG` environment variable exists so that it does not affect VMPooler when running in production environments.
36 lines
734 B
Ruby
Executable file
36 lines
734 B
Ruby
Executable file
#!/usr/bin/env ruby
|
|
|
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
|
|
require 'rubygems' unless defined?(Gem)
|
|
require 'lib/vmpooler'
|
|
|
|
config = Vmpooler.config
|
|
redis_host = config[:redis]['server']
|
|
logger_file = config[:config]['logfile']
|
|
|
|
metrics = Vmpooler.new_metrics(config)
|
|
|
|
api = Thread.new {
|
|
thr = Vmpooler::API.new
|
|
thr.helpers.configure(config, Vmpooler.new_redis(redis_host), metrics)
|
|
thr.helpers.execute!
|
|
}
|
|
|
|
manager = Thread.new {
|
|
Vmpooler::PoolManager.new(
|
|
config,
|
|
Vmpooler.new_logger(logger_file),
|
|
Vmpooler.new_redis(redis_host),
|
|
metrics
|
|
).execute!
|
|
}
|
|
|
|
if ENV['VMPOOLER_DEBUG']
|
|
trap("INT") {
|
|
puts "Shutting down."
|
|
[api, manager].each { |t| t.exit }
|
|
}
|
|
end
|
|
|
|
[api, manager].each { |t| t.join }
|