Skip to content

Instantly share code, notes, and snippets.

@JamesChevalier
Created June 8, 2012 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesChevalier/2898018 to your computer and use it in GitHub Desktop.
Save JamesChevalier/2898018 to your computer and use it in GitHub Desktop.
Rake task to switch sites that Pow serves
# This is for instances where a single Rails app serves multiple domains.
# That is, http://domainA.com and http://domainB.com are both served by the same Rails app.
# When launching these manually, I specify which site I want to see by passing a site variable:
# site=domainB ruby script/server
# This gist allows site switching via a rake task:
# rake pow[SITENAME]
# If no '[SITENAME]' is provided, then it defaults to the 'domainA' site
desc "Switches site that Pow serves"
task :pow, :site_name do |t, args|
pow_config = "#{Rails.root}/.powrc"
args.with_defaults(:site_name => "domainA")
# Overwrite the .powrc file with the new site name
file = File.open(pow_config, 'w')
file.write <<EOF
if [ -f "$rvm_path/scripts/rvm" ] && [ -f ".rvmrc" ]; then
source "$rvm_path/scripts/rvm"
source ".rvmrc"
fi
export site=#{args.site_name}
EOF
# Restart Pow
FileUtils.touch "#{Rails.root}/tmp/restart.txt"
# Display the site change
puts "Switched to #{args.site_name}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment