Module: JsChat::Server

Defined in:
lib/jschat/server.rb

Class Method Summary collapse

Class Method Details

.pid_file_nameObject



15
16
17
# File 'lib/jschat/server.rb', line 15

def self.pid_file_name
  File.join(ServerConfig['tmp_files'], 'jschat.pid')
end

.rm_pid_fileObject



24
25
26
# File 'lib/jschat/server.rb', line 24

def self.rm_pid_file
  FileUtils.rm pid_file_name
end

.run!Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jschat/server.rb', line 32

def self.run!
  write_pid_file
  JsChat.init_storage

  at_exit do
    stop
  end

  EM.run do
    EM.start_server ServerConfig['ip'], ServerConfig['port'], JsChat
  end
end

.stopObject



28
29
30
# File 'lib/jschat/server.rb', line 28

def self.stop
  rm_pid_file
end

.write_pid_fileObject



19
20
21
22
# File 'lib/jschat/server.rb', line 19

def self.write_pid_file
  return unless ServerConfig['use_tmp_files']
  File.open(pid_file_name, 'w') { |f| f << Process.pid }
end