lib/splash/cli/daemon.rb in prometheus-splash-0.1.1 vs lib/splash/cli/daemon.rb in prometheus-splash-0.2.0
- old
+ new
@@ -6,43 +6,74 @@
include Splash::Transports
include Splash::Exiter
option :foreground, :type => :boolean
- desc "start", "Starting Logs Monitor Daemon"
+ option :purge, :type => :boolean
+ option :scheduling, :type => :boolean, default: true
+ long_desc <<-LONGDESC
+ Starting Splash Daemon\n
+ With --foreground, run Splash in foreground\n
+ With --no-scheduling, inhibit commands scheduling\n
+ With --purge, Purge Input Queue for Splash Daemon
+ LONGDESC
+ desc "start", "Starting Splash Daemon"
def start
- acase = run_as_root :startdaemon
+ if options[:purge] then
+ transport = get_default_client
+ if transport.class == Hash and transport.include? :case then
+ splash_exit transport
+ else
+ queue = "splash.#{Socket.gethostname}.input"
+ transport.purge queue: queue
+ puts " * Queue : #{queue} purged"
+ splash_exit case: :quiet_exit
+ end
+ end
+ acase = run_as_root :startdaemon, options
splash_exit acase
end
- desc "stop", "Stopping Logs Monitor Daemon"
+
+ desc "purge", "Purge Transport Input queue of Daemon"
+ def purge
+ transport = get_default_client
+ if transport.class == Hash and transport.include? :case then
+ splash_exit transport
+ else
+ queue = "splash.#{Socket.gethostname}.input"
+ transport.purge queue: queue
+ puts " * Queue : #{queue} purged"
+ splash_exit case: :quiet_exit
+ end
+ end
+
+ desc "stop", "Stopping Splash Daemon"
def stop
acase = run_as_root :stopdaemon
splash_exit acase
end
- desc "status", "Logs Monitor Daemon status"
+ desc "status", "Splash Daemon status"
def status
acase = run_as_root :statusdaemon
splash_exit acase
end
desc "ping HOSTNAME", "send a ping to HOSTNAME daemon over transport (need an active tranport), Typicallly RabbitMQ"
def ping(hostname=Socket.gethostname)
puts "ctrl+c for interrupt"
- queue = "splash.#{Socket.gethostname}.returncli"
- order = {:verb => :ping, :payload => {:hostname => Socket.gethostname}, :return_to => queue}
-
- lock = Mutex.new
- condition = ConditionVariable.new
begin
- get_default_subscriber(queue: queue).subscribe(timeout: 10) do |delivery_info, properties, payload|
- puts YAML::load(payload)
- lock.synchronize { condition.signal }
+ transport = get_default_client
+ if transport.class == Hash and transport.include? :case then
+ splash_exit transport
+ else
+ puts transport.execute({ :verb => :ping,
+ :payload => {:hostname => Socket.gethostname},
+ :return_to => "splash.#{Socket.gethostname}.returncli",
+ :queue => "splash.#{hostname}.input" })
+ splash_exit case: :quiet_exit
end
- get_default_client.publish queue: "splash.#{hostname}.input", message: order.to_yaml
- lock.synchronize { condition.wait(lock) }
- splash_exit case: :quiet_exit
rescue Interrupt
splash_exit status: :error, case: :interrupt, more: "Ping Command"
end
end