#!/usr/bin/env ruby # Try to load external libs, helpers and constants begin require "rubygems" require "optparse" require 'daemons' require 'logger' require_relative "../lib/pushyd/config" rescue LoadError raise "EXITING: some basic libs were not found" end include PushyDaemon # Handle configuration APP_ROOT = File.expand_path(File.dirname(__FILE__) + "/../") begin # Defaults cmd_config = nil cmd_env = "production" cmd_dump = false # Parse options and check compliance OptionParser.new do |opts| opts.banner = "Usage: #{File.basename $PROGRAM_NAME} [options] start|stop" opts.on("-c", "--config CONFIGFILE") { |config| cmd_config = File.expand_path(config)} opts.on("-e", "--environment ENV") { |env| cmd_env = env } opts.on("-d", "--dump") { cmd_dump = true } opts.on("", "--dev") { cmd_env = "development" } end.order!(ARGV) # Build Chamber-based configuration from Gemspec with initial context Conf.prepare root: APP_ROOT, gemspec: "pushyd", env: cmd_env, config: cmd_config # Display final configuration puts "--- #{Conf.name} #{Conf.version}" puts "Environment \t #{Conf.env}" puts "Config files \t #{Conf.files}" puts puts "Log file \t #{Conf[:log]}" puts Conf.dump if cmd_dump rescue OptionParser::InvalidOption => e abort "EXITING: option parser: #{e.message}" rescue PushyDaemon::ConfigParseError => e abort "EXITING: ConfigParseError: #{e.message}" rescue Exception => e abort "EXITING: Exception: #{e.message}" end # Run daemon run_options = { ontop: false, # :dir_mode => :normal, # :dir => File.join(root, 'amine.log'), # :log_output => true, :backtrace => true, :multiple => false } Daemons.run_proc('pushy-daemon', run_options) do # Load code puts "--- loading code and logger" require_relative "../lib/pushyd" # Start daemon puts "--- starting" PushyDaemon::Daemon.run end