#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../lib/kldockeragent' def version? File.read(File.dirname(__FILE__) + '/../VERSION').strip end opts = Trollop::options do version "kldockeragent #{version?} (c) 2016 Kytoonlabs" banner <<-EOS Agent for KL Docker Agent configuration management tool. Usage: kldockeragent [options] where [options] are: EOS opt :start, "Start the agent. If --daemon option is set true, then the agent will start as a daemon.", :short => '-s' opt :stop, "Stop the daemon agent.", :short => '-t' opt :restart, "Restart the daemon agent.", :short => '-r' opt :status, "Print the status of the daemon agent.", :short => '-a' opt :pid, "Print the PID of the daemon agent." end if opts[:start] if not KL::Agent.pid.nil? puts "Agent is already running with PID #{KL::Agent.pid}" else opts[:daemon] = true KL::Agent.start(opts) end elsif opts[:stop] KL::Agent.stop(opts) elsif opts[:restart] KL.logger.info '[main] Restart Agent command detected.' opts[:daemon] = true KL::Agent.stop if KL::Agent.pid.to_i > 0 KL::Agent.start(opts) elsif opts[:status] KL::Agent.status elsif opts[:pid] KL::Agent.get_pid end