mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
This was partially an exercise to use middleware, but also to enable basic logging for the API by logging all the API calls to the logger.
60 lines
1.6 KiB
Ruby
Executable file
60 lines
1.6 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']
|
|
redis_connection_pool_size = config[:redis]['connection_pool_size']
|
|
redis_connection_pool_timeout = config[:redis]['connection_pool_timeout']
|
|
logger_file = config[:config]['logfile']
|
|
|
|
logger = Vmpooler::Logger.new logger_file
|
|
metrics = Vmpooler::Metrics.init(logger, config)
|
|
|
|
torun_threads = []
|
|
if ARGV.count == 0
|
|
torun = %i[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
|
|
redis = Vmpooler.new_redis(redis_host, redis_port, redis_password)
|
|
Vmpooler::API.execute(torun, config, redis, metrics, logger)
|
|
end
|
|
torun_threads << api
|
|
elsif metrics.respond_to?(:setup_prometheus_metrics)
|
|
# Run the cut down API - Prometheus Metrics only.
|
|
prometheus_only_api = Thread.new do
|
|
Vmpooler::API.execute(torun, config, nil, metrics, logger)
|
|
end
|
|
torun_threads << prometheus_only_api
|
|
end
|
|
|
|
if torun.include? :manager
|
|
manager = Thread.new do
|
|
Vmpooler::PoolManager.new(
|
|
config,
|
|
logger,
|
|
Vmpooler.redis_connection_pool(redis_host, redis_port, redis_password, redis_connection_pool_size, redis_connection_pool_timeout, metrics),
|
|
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)
|