Created
June 11, 2012 08:27
-
-
Save dwayne/2909075 to your computer and use it in GitHub Desktop.
Deploying Sinatra/Thin to WebFaction
This file contains 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
# Exclude files that don't need to be on the server | |
# Used by rsync when deploying code to the server | |
.excludes | |
.git | |
.gitignore | |
log/ | |
tmp/ |
This file contains 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
# These directories are created by Thin when `rake:thin start` is invoked | |
log/ | |
tmp/ |
This file contains 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
# Server options: | |
address: 127.0.0.1 | |
port: 5000 | |
# Adapter options: | |
environment: development | |
# See `thin -h` for more options |
This file contains 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
# Server options: | |
port: 12345 | |
# Adapter options: | |
environment: production | |
# Daemon options: | |
daemonize: true | |
user: user | |
group: group | |
# See `thin -h` for more options |
This file contains 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
# Assuming a classic style app | |
require './app' | |
run Sinatra::Application | |
# Modular style app | |
# require './awesome-app' | |
# run AwesomeApp | |
# or | |
# map('/end/point') { run AwesomeApp } |
This file contains 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
require 'rake' | |
ENV['RACK_ENV'] ||= 'development' | |
namespace :thin do | |
desc 'Start the app' | |
task :start do | |
puts 'Starting...' | |
system "bundle exec thin -s 1 -C config/config-#{ENV['RACK_ENV']}.yml -R config/config.ru start" | |
puts 'Started!' | |
end | |
desc 'Stop the app' | |
task :stop do | |
puts 'Stopping...' | |
pids = File.join(File.dirname(__FILE__), 'tmp/pids') | |
if File.directory?(pids) | |
Dir.new(pids).each do |file| | |
prefix = file.to_s | |
if prefix[0, 4] == 'thin' | |
puts "Stopping the server on port #{file[/\d+/]}..." | |
system "bundle exec thin stop -Ptmp/pids/#{file}" | |
end | |
end | |
end | |
puts 'Stopped!' | |
end | |
desc 'Restart the application' | |
task :restart do | |
puts 'Restarting...' | |
Rake::Task['thin:stop'].invoke | |
Rake::Task['thin:start'].invoke | |
puts 'Restarted!' | |
end | |
end | |
user = 'username' | |
app_name = 'app' | |
app_dir = "/home/#{user}/webapps/#{app_name}" | |
desc 'Deploy to server' | |
task :deploy, :password do |t, args| | |
puts 'Deploying to server...' | |
# http://linux.die.net/man/1/rsync | |
# Push: rsync [OPTION...] SRC... [USER@]HOST:DEST | |
success = system "rsync --exclude-from .excludes -rltvz -e ssh . #{user}@#{user}.webfactional.com:#{app_dir}" | |
if success | |
require 'net/ssh' | |
Net::SSH.start("#{user}.webfactional.com", user, :password => args[:password]) do |ssh| | |
commands = [ | |
'export RACK_ENV=production', | |
"cd #{app_dir}", | |
'bundle install --without=development', | |
'rake thin:restart' | |
].join ' && ' | |
ssh.exec commands | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment