Class: Nodectl::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/nodectl/server.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



4
5
6
# File 'lib/nodectl/server.rb', line 4

def initialize(options = {})
  @options = self.class.default_options.merge(options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



2
3
4
# File 'lib/nodectl/server.rb', line 2

def options
  @options
end

Class Method Details

.default_optionsObject



49
50
51
# File 'lib/nodectl/server.rb', line 49

def self.default_options
  @default_options ||= YAML.load_file(Nodectl.options[:config_dir].join('server.yml'))
end

Instance Method Details

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/nodectl/server.rb', line 8

def run
  if @options["daemonize"]
    if Process.fork
      exit
    else
      Nodectl.shut_up!
    end
  end

  if @options["pidfile"]
    File.open(@options["pidfile"], "w") do |file|
      file.write(Process.pid)
    end

    at_exit { File.unlink @options["pidfile"] }
  end

  Nodectl.logger.info "server with pid #{Process.pid} started"
  at_exit { Nodectl.logger.info "server with pid #{Process.pid} shutting down" }

  Nodectl::Service.load_register
  Nodectl::Instance.load_register

  EM.run do
    setup_signals
    rack_run
    watchdog_run
    stream_run
  end
end

#stopObject



39
40
41
42
# File 'lib/nodectl/server.rb', line 39

def stop
  @thin.stop if @thin
  EM.stop
end

#stop!Object



44
45
46
47
# File 'lib/nodectl/server.rb', line 44

def stop!
  @thin.stop! if @thin
  EM.stop
end