vmpooler/bin/vmpooler
John O'Connor 85ff3f7022 (MAINT) Add optional API Request Logging
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.
2020-06-29 19:56:29 +01:00

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)