Class: Matchd::Control

Inherits:
Object
  • Object
show all
Defined in:
lib/matchd/control.rb

Overview

Controls the demonizing of a Server

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Control

Returns a new instance of Control.



6
7
8
# File 'lib/matchd/control.rb', line 6

def initialize(options = {})
  @name = options.delete(:name, "matchd")
end

Instance Method Details

#daemon_optsObject



46
47
48
49
50
51
52
53
54
# 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 = {}) ⇒ Object



22
23
24
25
# File 'lib/matchd/control.rb', line 22

def restart(options = {})
  stop
  start(options)
end

#run!(argv, options = {}) ⇒ Object



28
29
30
31
32
33
34
# 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_optsObject



37
38
39
40
41
42
43
# 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 = {}) ⇒ Object



10
11
12
# File 'lib/matchd/control.rb', line 10

def start(options = {})
  run! "start", ontop: options.fetch(:ontop, false)
end

#statusObject



18
19
20
# File 'lib/matchd/control.rb', line 18

def status
  run! "status"
end

#stopObject



14
15
16
# File 'lib/matchd/control.rb', line 14

def stop
  run! "stop"
end