#!/usr/bin/env ruby # frozen_string_literal: true require 'rubygems' PARAMS_CONFIG = {} def up require 'sinatra' require 'sinatra/base' require 'mkit' # defaults PARAMS_CONFIG[:bind] ||= "localhost" PARAMS_CONFIG[:port] ||= 4567 # MKIt.startup(options: PARAMS_CONFIG) use Rack::MethodOverride use ServicesController use MkitJobsController # sinatra::base ignores in parameters # set it here or via configure... Sinatra::Application.run!({port: PARAMS_CONFIG[:port], bind: PARAMS_CONFIG[:bind] }) # MKIt::Server.run end # if ARGV.any? require 'optparse' parser = OptionParser.new do |op| op.on('-c config-dir', 'set the config dir (default is /etc/mkit)') { |val| PARAMS_CONFIG[:config_dir] = val } op.on('-p port', 'set the port (default is 4567)') { |val| PARAMS_CONFIG[:port] = Integer(val) } op.on('-b bind ', 'specify bind address (e.g. /tmp/app.sock)') { |val| PARAMS_CONFIG[:bind] = val } op.on('-s server', 'specify rack server/handler') { |val| PARAMS_CONFIG[:server] = val } op.on('-q', 'turn on quiet mode (default is off)') { PARAMS_CONFIG[:quiet] = true } op.on('-x', 'turn on the mutex lock (default is off)') { PARAMS_CONFIG[:lock] = true } op.on('-e env', 'set the environment (default is development)') do |val| ENV['RACK_ENV'] = val PARAMS_CONFIG[:environment] = val.to_sym end op.on('-o addr', "set the host (default is (env == 'development' ? 'localhost' : '0.0.0.0'))") do |val| PARAMS_CONFIG[:bind] = val end end begin parser.parse!(ARGV.dup) rescue StandardError => e PARAMS_CONFIG[:optparse_error] = e end end up