Class: RabbitWQ::ServerDaemon
- Inherits:
-
Object
- Object
- RabbitWQ::ServerDaemon
- Defined in:
- lib/rabbit_wq/server_daemon.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#pid_path ⇒ Object
readonly
Returns the value of attribute pid_path.
-
#script ⇒ Object
readonly
Returns the value of attribute script.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(options) ⇒ ServerDaemon
constructor
A new instance of ServerDaemon.
- #run ⇒ Object
- #start ⇒ Object
- #status ⇒ Object
- #stop ⇒ Object
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 = @name = [:name] || APP_NAME @pid_path = [:pid] || '.' @pid = get_pid @timeout = [:timeout] || 10 end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/rabbit_wq/server_daemon.rb', line 8 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/rabbit_wq/server_daemon.rb', line 8 def @options end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
8 9 10 |
# File 'lib/rabbit_wq/server_daemon.rb', line 8 def pid @pid end |
#pid_path ⇒ Object (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 |
#script ⇒ Object (readonly)
Returns the value of attribute script.
8 9 10 |
# File 'lib/rabbit_wq/server_daemon.rb', line 8 def script @script end |
#timeout ⇒ Object (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
#run ⇒ Object
39 40 41 |
# File 'lib/rabbit_wq/server_daemon.rb', line 39 def run Server.new( ).start end |
#start ⇒ Object
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 |
#status ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rabbit_wq/server_daemon.rb', line 48 def status $stdout.print "#{APP_NAME} " if process_exists? $stdout.puts "process running with PID: #{pid}" true else $stdout.puts "process does not exist" false end end |
#stop ⇒ Object
43 44 45 46 |
# File 'lib/rabbit_wq/server_daemon.rb', line 43 def stop kill_process FileUtils.rm pid_path end |