Class: RabbitWQ::ServerDaemon

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ServerDaemon

Returns a new instance of ServerDaemon.



15
16
17
18
19
20
21
# File 'lib/rabbit_wq/server_daemon.rb', line 15

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.



8
9
10
# File 'lib/rabbit_wq/server_daemon.rb', line 8

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/rabbit_wq/server_daemon.rb', line 8

def options
  @options
end

#pidObject (readonly)

Returns the value of attribute pid.



8
9
10
# File 'lib/rabbit_wq/server_daemon.rb', line 8

def pid
  @pid
end

#pid_pathObject (readonly)

Returns the value of attribute pid_path.



8
9
10
# File 'lib/rabbit_wq/server_daemon.rb', line 8

def pid_path
  @pid_path
end

#scriptObject (readonly)

Returns the value of attribute script.



8
9
10
# File 'lib/rabbit_wq/server_daemon.rb', line 8

def script
  @script
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



8
9
10
# File 'lib/rabbit_wq/server_daemon.rb', line 8

def timeout
  @timeout
end

Instance Method Details

#runObject



39
40
41
# File 'lib/rabbit_wq/server_daemon.rb', line 39

def run
  Server.new( options ).start
end

#startObject



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

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



48
49
50
51
52
53
54
55
56
# File 'lib/rabbit_wq/server_daemon.rb', line 48

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



43
44
45
46
# File 'lib/rabbit_wq/server_daemon.rb', line 43

def stop
  kill_process
  FileUtils.rm pid_path
end