Class: Afterlife::Cdn::Server

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Server

Returns a new instance of Server.



28
29
30
31
32
33
34
35
36
37
# File 'lib/afterlife/cdn/server.rb', line 28

def initialize(args)
  @instance = Rackup::Server.new(
    environment: ENV['RACK_ENV'] || 'development',
    quiet: true, # we setup log in config.ru
    Port: args['port'],
    config: Afterlife.root.join('config.ru').to_s,
    pid: Server.pid_file.to_s,
    daemonize: !args['foreground'],
  )
end

Instance Attribute Details

#instanceObject (readonly)

Returns the value of attribute instance.



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

def instance
  @instance
end

Class Method Details

.killObject



12
13
14
15
16
# File 'lib/afterlife/cdn/server.rb', line 12

def self.kill
  fail Afterlife::Error, 'The server is not running' unless running?

  Process.kill('INT', pid_file.read.to_i)
end

.pid_fileObject



8
9
10
# File 'lib/afterlife/cdn/server.rb', line 8

def self.pid_file
  Afterlife.local_path.join('pids/server.pid')
end

.running?Boolean

Returns:

  • (Boolean)


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

def self.running?
  pid_file.exist?
end

.start(args) ⇒ Object



18
19
20
21
22
# File 'lib/afterlife/cdn/server.rb', line 18

def self.start(args)
  fail Afterlife::Error, 'A server is already running' if running?

  new(args).start
end

Instance Method Details

#startObject



39
40
41
# File 'lib/afterlife/cdn/server.rb', line 39

def start
  instance.start
end