#!/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.redis_connection(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), 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)