Class: Server

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

Class Method Summary collapse

Class Method Details

.is_running(path) ⇒ Object



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

def self.is_running(path)
  FileSystem.file_exists?("#{path}/pid.txt") || FileSystem.file_exists?("#{path}/https_pid.txt")
end

.is_started(path, counter = 0) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/brisk/server/server.rb', line 25

def self.is_started(path, counter = 0)
  sleep(0.5)

  if Pid.exists?(path)
    pid = Pid.read(path)
    if Pid.alive?(pid)
      return true
    end
  end

  is_started(path, counter + 1)
end

.kill(path) ⇒ Object



10
11
12
13
14
15
# File 'lib/brisk/server/server.rb', line 10

def self.kill(path)
  if is_running(path)
    pid = FileSystem.read("#{path}/pid.txt")
    shutdown pid
  end
end

.shutdown(pid) ⇒ Object



38
39
40
# File 'lib/brisk/server/server.rb', line 38

def self.shutdown(pid)
  system "sudo kill -9 #{pid}"
end

.start(path) ⇒ Object



17
18
19
# File 'lib/brisk/server/server.rb', line 17

def self.start(path)
  spawn "cd #{path} && /usr/local/bin/rerun \"/usr/local/bin/thin -d -R config.ru -a localhost -p 3001 start\""
end

.start_https(path) ⇒ Object



21
22
23
# File 'lib/brisk/server/server.rb', line 21

def self.start_https(path)
  spawn "cd #{path} && /usr/local/bin/thin start -d -R config.ru -a localhost -p 3003 --ssl"
end