Class: Acception::Subscriber::ServerDaemon

Inherits:
Object
  • Object
show all
Defined in:
lib/acception/subscriber/server_daemon.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ServerDaemon

Returns a new instance of ServerDaemon.



16
17
18
19
20
21
22
# File 'lib/acception/subscriber/server_daemon.rb', line 16

def initialize( options )
  @options  = options
  @name     = options[:name] || APP_NAME
  @pid_path = options[:pid] || '.'
  @pid      = get_pid
  @timeout  = options[:timeout] || 10
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/acception/subscriber/server_daemon.rb', line 9

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/acception/subscriber/server_daemon.rb', line 9

def options
  @options
end

#pidObject (readonly)

Returns the value of attribute pid.



9
10
11
# File 'lib/acception/subscriber/server_daemon.rb', line 9

def pid
  @pid
end

#pid_pathObject (readonly)

Returns the value of attribute pid_path.



9
10
11
# File 'lib/acception/subscriber/server_daemon.rb', line 9

def pid_path
  @pid_path
end

#scriptObject (readonly)

Returns the value of attribute script.



9
10
11
# File 'lib/acception/subscriber/server_daemon.rb', line 9

def script
  @script
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



9
10
11
# File 'lib/acception/subscriber/server_daemon.rb', line 9

def timeout
  @timeout
end

Instance Method Details

#runObject



40
41
42
# File 'lib/acception/subscriber/server_daemon.rb', line 40

def run
  Server.new( options ).start
end

#startObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/acception/subscriber/server_daemon.rb', line 24

def start
  abort "Process already running!" if process_exists?

  pid = fork do
    exit if fork
    Process.setsid
    exit if fork
    store_pid( Process.pid )
    File.umask 0000
    redirect_output!
    run
  end

  Process.waitpid( pid )
end

#statusObject



49
50
51
52
53
54
55
56
57
# File 'lib/acception/subscriber/server_daemon.rb', line 49

def status
  out = "#{APP_NAME} "
  if process_exists?
    out << "process running with PID: #{pid}"
  else
    out << "process does not exist"
  end
  $stdout.puts out
end

#stopObject



44
45
46
47
# File 'lib/acception/subscriber/server_daemon.rb', line 44

def stop
  kill_process
  FileUtils.rm pid_path
end