class Cloudkeeper::CLI
Constants
- BACKEND_ERROR_CODE
Public Instance Methods
sync()
click to toggle source
# File lib/cloudkeeper/cli.rb, line 131 def sync initialize_sync options File.open(Cloudkeeper::Settings[:'lock-file'], File::RDWR | File::CREAT, 0o644) do |file| lock = file.flock(File::LOCK_EX | File::LOCK_NB) run_sync if lock abort 'cloudkeeper instance is already running, quitting' unless lock end rescue Cloudkeeper::Errors::InvalidConfigurationError => ex abort ex.message rescue StandardError => ex logger.error "Unexpected error: #{ex.message}" raise ex end
version()
click to toggle source
# File lib/cloudkeeper/cli.rb, line 146 def version $stdout.puts Cloudkeeper::VERSION end
Private Instance Methods
all_options_available(required_options)
click to toggle source
# File lib/cloudkeeper/cli.rb, line 197 def all_options_available(required_options) required_options.reduce(true) { |acc, elem| Cloudkeeper::Settings[elem] && acc } end
exit_with_message(code)
click to toggle source
# File lib/cloudkeeper/cli.rb, line 161 def exit_with_message(code) warn 'Some errors occured during the run. See logs for more info.' exit code end
initialize_configuration(options)
click to toggle source
# File lib/cloudkeeper/cli.rb, line 173 def initialize_configuration(options) Cloudkeeper::Settings.clear Cloudkeeper::Settings.merge! options.to_hash end
initialize_logger()
click to toggle source
# File lib/cloudkeeper/cli.rb, line 201 def initialize_logger Cloudkeeper::Settings[:'logging-level'] = 'DEBUG' if Cloudkeeper::Settings[:debug] logging_file = Cloudkeeper::Settings[:'logging-file'] logging_level = Cloudkeeper::Settings[:'logging-level'] Yell.new :stdout, name: Object, level: logging_level.downcase, format: Yell::DefaultFormat Object.send :include, Yell::Loggable setup_file_logger(logging_file) if logging_file logger.debug 'Running in debug mode...' end
initialize_sync(options)
click to toggle source
# File lib/cloudkeeper/cli.rb, line 166 def initialize_sync(options) initialize_configuration options validate_configuration! initialize_logger logger.debug "Cloudkeeper 'sync' called with parameters: #{Cloudkeeper::Settings.to_hash.inspect}" end
run_sync()
click to toggle source
# File lib/cloudkeeper/cli.rb, line 154 def run_sync appliance_manager = Cloudkeeper::Managers::ApplianceManager.new appliance_manager.synchronize_appliances exit_with_message BACKEND_ERROR_CODE if appliance_manager.errors[:backend_errors] end
setup_file_logger(logging_file)
click to toggle source
# File lib/cloudkeeper/cli.rb, line 215 def setup_file_logger(logging_file) unless (File.exist?(logging_file) && File.writable?(logging_file)) || File.writable?(File.dirname(logging_file)) logger.error "File #{logging_file} isn't writable" return end logger.adapter :file, logging_file end
validate_configuration!()
click to toggle source
# File lib/cloudkeeper/cli.rb, line 178 def validate_configuration! validate_configuration_group! %i[authentication], %i[certificate key backend-certificate], 'Authentication configuration missing' validate_configuration_group! %i[remote-mode], %i[nginx-binary nginx-runtime-dir nginx-error-log-file nginx-access-log-file nginx-pid-file nginx-ip-address nginx-port], 'NGINX configuration missing' validate_configuration_group! %i[remote-mode nginx-proxy-ip-address], %i[nginx-proxy-port], 'NGINX proxy configuration missing' end
validate_configuration_group!(flags, required_options, error_message)
click to toggle source
# File lib/cloudkeeper/cli.rb, line 191 def validate_configuration_group!(flags, required_options, error_message) return unless flags.reduce(true) { |acc, elem| Cloudkeeper::Settings[elem] && acc } raise Cloudkeeper::Errors::InvalidConfigurationError, error_message unless all_options_available(required_options) end