Module: Otaku::Server

Defined in:
lib/otaku/server.rb

Defined Under Namespace

Modules: EM

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.handlerObject

Returns the value of attribute handler.



6
7
8
# File 'lib/otaku/server.rb', line 6

def handler
  @handler
end

Class Method Details

.run_evented_serverObject



16
17
18
19
20
# File 'lib/otaku/server.rb', line 16

def run_evented_server
  Otaku.log 'started with pid #%s' % Process.pid,
    'listening at %s:%s' % [Otaku.address, Otaku.port]
  EventMachine::run { EventMachine::start_server(Otaku.address, Otaku.port, EM) }
end

.run_server_scriptObject



22
23
24
25
26
27
28
# File 'lib/otaku/server.rb', line 22

def run_server_script
  script = File.join(Otaku.root, 'otaku.rb')
  args = Encoder.encode(:config => Otaku.config, :handler => @handler)
  load_paths = [@handler.root, Otaku.root].join(' -I')
  @process = IO.popen(%|#{Otaku.ruby} -I#{load_paths} #{script} "#{args.gsub('"','\"')}"|,'r')
  sleep Otaku.init_wait_time
end

.start(other_process = false) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/otaku/server.rb', line 8

def start(other_process=false)
  other_process ? run_evented_server : (
    # print '[Otaku] initializing at %s:%s ... ' % [Otaku.address, Otaku.port] # DEBUG
    run_server_script
    # puts 'done [pid#%s]' % @process.pid # DEBUG
  )
end

.stopObject



30
31
32
# File 'lib/otaku/server.rb', line 30

def stop
  Process.kill('SIGHUP', @process.pid) if @process
end