class Necro::Runner

Public Class Methods

add_command(selected_command) click to toggle source
# File lib/necro/runner.rb, line 70
def self.add_command(selected_command)
  socket = UNIXSocket.open(Necro::CommandListener::Server::SOCKET_PATH)
  socket.puts("add #{selected_command.command_key}")
  socket.flush()
  socket.close()
end
refresh_command(selected_command) click to toggle source
# File lib/necro/runner.rb, line 84
def self.refresh_command(selected_command)
  socket = UNIXSocket.open(Necro::CommandListener::Server::SOCKET_PATH)
  socket.puts("reload #{selected_command.command_key}")
  socket.flush()
  socket.close()
end
remove_command(selected_command) click to toggle source
# File lib/necro/runner.rb, line 77
def self.remove_command(selected_command)
  socket = UNIXSocket.open(Necro::CommandListener::Server::SOCKET_PATH)
  socket.puts("remove #{selected_command.command_key} #{selected_command.signal}")
  socket.flush()
  socket.close()
end
run(args) click to toggle source
# File lib/necro/runner.rb, line 7
def self.run(args)

  selected_command = nil
  
  Slop.parse(args, help: true) do
    on :v, "Print the version" do
      $stdout.puts Necro::VERSION
    end

    command 'start' do
      banner "Usage : necro start config.ini \n Start Necro Process Manager"
      run do |cmd_opts, cmd_args|
        selected_command = OpenStruct.new(:command => 'start', :file => cmd_args.first)
      end
    end

    command 'add' do
      banner "Usage : necro add process_label \n Start the process with given process_label"
      run do |cmd_opts, cmd_args|
        selected_command = OpenStruct.new(:command => 'add', :command_key => cmd_args.first)
      end
    end

    command 'remove' do
      banner "Usage : necro remove process_label \n Stop the process with given label"
      on :s, :signal=, "Signal to send for killing the process, default is SIGINT", as: String

      run do |cmd_opts, cmd_args|
        signal_to_use = cmd_opts.to_hash[:signal] || 'INT'
        selected_command = OpenStruct.new(
          :command => 'remove', 
          :command_key => cmd_args.first,
          :signal => signal_to_use
        )
      end
    end
  end
  run_command(selected_command)
end
run_command(selected_command) click to toggle source
# File lib/necro/runner.rb, line 47
def self.run_command(selected_command)
  return unless selected_command
  case selected_command.command
  when 'start'
    start_server(selected_command)
  when 'add'
    add_command(selected_command)
  when 'remove'
    remove_command(selected_command)
  else
    $stdout.puts "Invalid command"
  end
end
start_server(selected_command) click to toggle source
# File lib/necro/runner.rb, line 61
def self.start_server(selected_command)
  config = Necro::Config.new(selected_command.file)
  Necro.const_set(:CONFIG, config)
  warn_about_terminal_notifier()
  commander = Necro::Commander.new()
  Necro.const_set(:COMMANDER, commander)
  commander.start_manager()
end
warn_about_terminal_notifier() click to toggle source
# File lib/necro/runner.rb, line 91
def self.warn_about_terminal_notifier
  if RUBY_PLATFORM.downcase.include?("darwin")
    command_path = `which terminal-notifier`
    if !command_path || command_path.empty?
      $stdout.puts("You can enable OSX notification for processes by installing terminal-notification gem".red)
    end
  end
end