class Matchd::Control

Controls the demonizing of a {Matchd::Server}

Public Class Methods

new(options = {}) click to toggle source
# File lib/matchd/control.rb, line 6
def initialize(options = {})
  @name = options.delete(:name, "matchd")
end

Public Instance Methods

daemon_opts() click to toggle source

@private

# File lib/matchd/control.rb, line 46
def daemon_opts
  daemon_dir = Matchd::Config.dot_dir
  {
    dir_mode: :normal,
    dir: daemon_dir,
    log_output: true,
    log_dir: daemon_dir
  }
end
restart(options = {}) click to toggle source
# File lib/matchd/control.rb, line 22
def restart(options = {})
  stop
  start(options)
end
run!(argv, options = {}) click to toggle source

@private

# File lib/matchd/control.rb, line 28
def run!(argv, options = {})
  run_options = { ARGV: Array(argv), **options, **daemon_opts }
  Daemons.run_proc(@name, run_options) do
    require "matchd/server"
    Matchd::Server.new(*server_opts).run
  end
end
server_opts() click to toggle source

@private

# File lib/matchd/control.rb, line 37
def server_opts
  [
    Matchd::Registry.load_file(Matchd::Config.registry_file),
    Matchd::Config.listen,
    { resolver: Matchd::Config.resolver }
  ]
end
start(options = {}) click to toggle source
# File lib/matchd/control.rb, line 10
def start(options = {})
  run! "start", ontop: options.fetch(:ontop, false)
end
status() click to toggle source
# File lib/matchd/control.rb, line 18
def status
  run! "status"
end
stop() click to toggle source
# File lib/matchd/control.rb, line 14
def stop
  run! "stop"
end