class HareDo::Admin::Daemon::Interface
The class implements to command line interface for configuration module
Public Class Methods
new()
click to toggle source
Calls superclass method
HareDo::Admin::Interface::new
# File src/lib/haredo/service/admin/daemon.rb, line 14 def initialize() super('daemon', 'Control daemon') loadConfig() @commands = {} # Start the daemon @commands['start'] = lambda do | name | startCommand() end # Stop the daemon @commands['stop'] = lambda do | name | stopCommand() end # Check status @commands['status'] = lambda do | name | statusCommand() end end
Public Instance Methods
help(opts)
click to toggle source
# File src/lib/haredo/service/admin/daemon.rb, line 97 def help(opts) puts opts end
parse(args)
click to toggle source
# File src/lib/haredo/service/admin/daemon.rb, line 101 def parse(args) opts = OptionParser.new do |opts| opts.separator '' opts.banner = "Manage the haredo daemon\n\n" opts.banner += "Usage: config [options] { start | stop | status }" opts.separator 'Available options:' opts.on('-c', '--config [val]', String, 'Use specific config file (default /etc/haredo/system.yml)') do |file| @configfile = file end opts.on('-p', '--pidfile [val]', String, 'Use specific PID file') do |pid| @pid = pid end opts.on_tail("-h", "--help", "Display help") do puts opts exit end end opts.parse!(args) command = args[0].chomp if not @commands.has_key?(command) help opts return end @commands[command].call(command) end
startCommand()
click to toggle source
# File src/lib/haredo/service/admin/daemon.rb, line 37 def startCommand() # Check if already running if daemonPid() != nil $stderr.puts 'Daemon already running' return end if File.exist?($haredo_daemon_name) == false msg = "Error: #{$haredo_daemon_name} does not exist." $stderr.puts msg exit 1 end $stderr.puts 'Daemon start' fork do Process.daemon() exe = $haredo_daemon_name || HAREDO_DEFAULT_DAEMON_NAME exec(exe, '-d') end end
statusCommand()
click to toggle source
# File src/lib/haredo/service/admin/daemon.rb, line 61 def statusCommand() if daemonPid() != nil client = connectBroker() client.timeout = 3 queue_name = @config['system']['queue'] response = client.call(queue_name, :headers=>{'uuid'=>'status'}) if response != nil puts response.data() end client.disconnect() else puts 'down' end end
stopCommand()
click to toggle source
# File src/lib/haredo/service/admin/daemon.rb, line 80 def stopCommand() $stderr.puts "stop #{daemonPid()}" daemon_key = @config['daemon']['key'] queue_name = @config['system']['queue'] client = connectBroker() client.send( queue_name, :headers => { 'command' => 'stop', 'key' => daemon_key, }) client.disconnect() end