#!/usr/bin/ruby $LOAD_PATH.unshift File.expand_path("../../lib", File.realdirpath(__FILE__)) require 'optparse' options = {} version = "1.0.0" options = {} version = "1.0.0" daemonize_help = "run daemonized in the background (default: false)" pidfile_help = "the pid filename" logfile_help = "the log filename" debug_help = "set $DEBUG to true" warn_help = "enable warnings" op = OptionParser.new op.banner = "A background service that supervises the Particle firmware" op.separator "" op.separator "Usage: daemon [options]" op.separator "" op.separator "Process options:" op.on("-d", "--daemon", daemonize_help) { options[:daemonize] = true } op.on("-p", "--pidfile PIDFILE", pidfile_help) { |value| options[:pidfile] = value } op.on("-l", "--logfile LOGFILE", logfile_help) { |value| options[:logfile] = value } op.separator "" op.separator "Ruby options:" op.on( "--debug", debug_help) { $DEBUG = true } op.on( "--warn", warn_help) { $-w = true } op.separator "" op.separator "Common options:" op.on("-h", "--help") { puts op.to_s; exit } op.on("-v", "--version") { puts version; exit } op.separator "" op.parse!(ARGV) require 'particlepi/daemon' require 'particlepi/agent' ParticlePi::Daemon.new(options).run! do |daemon| ParticlePi::Agent.new.run!(daemon) end