vmpooler/bin/vmpooler
2020-03-05 16:03:21 -08:00

53 lines
1.1 KiB
Ruby
Executable file

#!/usr/bin/env ruby
# frozen_string_literal: true
require 'vmpooler'
config = Vmpooler.config
redis_host = config[:redis]['server']
redis_port = config[:redis]['port']
redis_password = config[:redis]['password']
logger_file = config[:config]['logfile']
metrics = Vmpooler.new_metrics(config)
torun_threads = []
if ARGV.count == 0
torun = ['api', 'manager']
else
torun = []
torun << 'api' if ARGV.include? 'api'
torun << 'manager' if ARGV.include? 'manager'
exit(2) if torun.empty?
end
if torun.include? 'api'
api = Thread.new do
thr = Vmpooler::API.new
redis = Vmpooler.new_redis(redis_host, redis_port, redis_password)
thr.helpers.configure(config, redis, metrics)
thr.helpers.execute!
end
torun_threads << api
end
if torun.include? 'manager'
manager = Thread.new do
Vmpooler::PoolManager.new(
config,
Vmpooler.new_logger(logger_file),
Vmpooler.new_redis(redis_host, redis_port, redis_password),
metrics
).execute!
end
torun_threads << manager
end
if ENV['VMPOOLER_DEBUG']
trap('INT') do
puts 'Shutting down.'
torun_threads.each(&:exit)
end
end
torun_threads.each(&:join)