-
Notifications
You must be signed in to change notification settings - Fork 150
Options to aid zero-downtime deployment / process supervision #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
361af7b
Support no-pidfile mode
brasic 742cb6d
Support holding a shared lock on a designated file forever
brasic a76afd2
Add README note and example upstart config
brasic 816578b
An explicit --pidfile arg overrides the --no-pidfile arg
joshuaflanagan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Seamless reload of resque-pool after a deploy. | ||
| # Assuming resque-pool is already running, invoke with | ||
| # `sudo initctl emit resque-pool-reload`. | ||
| description "resque-pool-reload" | ||
|
|
||
| start on resque-pool-reload | ||
|
|
||
| task | ||
|
|
||
| limit nofile 65536 65536 | ||
|
|
||
| # You may need to set things like PATH here. | ||
| env HOME=/home/your_app_user | ||
| export HOME | ||
|
|
||
| script | ||
| source /home/your_app_user/app_env.sh | ||
| cd /your/app_root | ||
| /usr/local/bin/setuidgid your_app_user bundle exec resque-pool \ | ||
| --daemon \ | ||
| --no-pidfile \ | ||
| --kill-others \ | ||
| --lock /path/to/your/lock_file \ | ||
| --config /path/to/resque_pool_config.yml | ||
| end script |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Manages resque-pool. | ||
| # Start the process with `initctl start resque-pool`. | ||
| description "resque-pool" | ||
|
|
||
| start on virtual-filesystems | ||
| stop on runlevel [06] | ||
|
|
||
| respawn | ||
| kill timeout 30 | ||
| limit nofile 65536 65536 | ||
|
|
||
| # You may need to set things like PATH here. | ||
| env HOME=/home/your_app_user | ||
| export HOME | ||
|
|
||
| # Ensure no subsequently deployed instances are running after shutdown. | ||
| post-stop script | ||
| /usr/bin/pkill -INT -f resque-pool-master | ||
| end script | ||
|
|
||
| # This script assumes you will deploy new application code by using | ||
| # something similar to upstart-reload.conf which runs a second copy of | ||
| # the application then shuts down the first when ready to fork. The | ||
| # --lock argument should point to a file that is accessible across | ||
| # deploys (i.e. not under a capistrano versioned path). setuidgid is | ||
| # only necessary if you are running an older version of upstart such as | ||
| # the one included with RHEL/Centos 6. In Upstart 1.4 and above you can | ||
| # use the setuid and setgid directives instead. | ||
| script | ||
| # Assuming you use environment-based configuration. | ||
| source /home/your_app_user/app_env.sh | ||
| cd /your/app_root | ||
| /usr/local/bin/setuidgid your_app_user bundle exec resque-pool \ | ||
| --daemon \ | ||
| --no-pidfile \ | ||
| --kill-others \ | ||
| --lock /path/to/your/lock_file \ | ||
| --config /path/to/resque_pool_config.yml | ||
| # The above command will return if resque-pool is restarted using the | ||
| # --kill-others functionality. This line will block until all pool | ||
| # instances are terminated, ensuring that upstart doesn't try to | ||
| # restart our process unless it is actually dead. | ||
| flock -x 0 < /path/to/your/lock_file | ||
| end script |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| require 'spec_helper' | ||
| require 'resque/pool/cli' | ||
|
|
||
| describe Resque::Pool::CLI do | ||
| subject(:cli) { Resque::Pool::CLI } | ||
|
|
||
| describe "option parsing" do | ||
| it "`--daemon` sets the 'daemon' flag" do | ||
| options = cli.parse_options(%w[--daemon]) | ||
| options[:daemon].should be_truthy | ||
| end | ||
|
|
||
| it "`--daemon` redirects stdout and stderr, when none specified" do | ||
| options = cli.parse_options(%w[--daemon]) | ||
| options[:stdout].should == "log/resque-pool.stdout.log" | ||
| options[:stderr].should == "log/resque-pool.stderr.log" | ||
| end | ||
|
|
||
| it "`--daemon` does not override provided stdout/stderr options" do | ||
| options = cli.parse_options(%w[--daemon --stdout my.stdout --stderr my.stderr]) | ||
| options[:stdout].should == "my.stdout" | ||
| options[:stderr].should == "my.stderr" | ||
| end | ||
|
|
||
| it "`--daemon` sets a default pidfile, when none specified" do | ||
| options = cli.parse_options(%w[--daemon]) | ||
| options[:pidfile].should == "tmp/pids/resque-pool.pid" | ||
| end | ||
|
|
||
| it "`--daemon` does not override provided pidfile" do | ||
| options = cli.parse_options(%w[--daemon --pidfile my.pid]) | ||
| options[:pidfile].should == "my.pid" | ||
| end | ||
|
|
||
| it "`--no-pidfile sets the 'no-pidfile' flag" do | ||
| options = cli.parse_options(%w[--no-pidfile]) | ||
| options[:no_pidfile].should be_truthy | ||
| end | ||
|
|
||
| it "`--no-pidfile prevents `--daemon` from setting a default pidfile" do | ||
| options = cli.parse_options(%w[--daemon --no-pidfile]) | ||
| options[:pidfile].should be_nil | ||
| end | ||
|
|
||
| it "--no-pidfile does not prevent explicit --pidfile setting" do | ||
| options = cli.parse_options(%w[--no-pidfile --pidfile my.pid]) | ||
| options[:pidfile].should == "my.pid" | ||
| options[:no_pidfile].should be_falsey | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--pidfile FILEshould also override--no-pidfile;opts.delete(:no_pidfile)