Skip to content

Commit

Permalink
Merge remote-tracking branch 'chrisleishman/daemonize'
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Sep 23, 2011
2 parents 05b579b + dcfbe36 commit 8d92f03
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.markdown
Expand Up @@ -265,6 +265,15 @@ worker process. Use the PIDFILE option for easy access to the PID:

$ PIDFILE=./resque.pid QUEUE=file_serve rake environment resque:work

### Running in the background

(Only supported with ruby >= 1.9). There are scenarios where it's helpful for
the resque worker to run itself in the background (usually in combination with
PIDFILE). Use the BACKGROUND option so that rake will return as soon as the
worker is started.

$ PIDFILE=./resque.pid BACKGROUND=yes QUEUE=file_serve \
rake environment resque:work

### Priorities and Queue Lists

Expand Down
7 changes: 7 additions & 0 deletions lib/resque/tasks.rb
Expand Up @@ -18,6 +18,13 @@
abort "set QUEUE env var, e.g. $ QUEUE=critical,high rake resque:work"
end

if ENV['BACKGROUND']
unless Process.respond_to?('daemon')
abort "env var BACKGROUND is set, which requires ruby >= 1.9"
end
Process.daemon(true)
end

if ENV['PIDFILE']
File.open(ENV['PIDFILE'], 'w') { |f| f << worker.pid }
end
Expand Down
2 changes: 1 addition & 1 deletion lib/resque/worker.rb
Expand Up @@ -480,7 +480,7 @@ def hostname

# Returns Integer PID of running worker
def pid
@pid ||= to_s.split(":")[1].to_i
Process.pid
end

# Returns an Array of string pids of all the other workers on this
Expand Down

0 comments on commit 8d92f03

Please sign in to comment.