Skip to content

Instantly share code, notes, and snippets.

@minichiello
Forked from dwayne/.excludes
Created August 10, 2012 20:52
Show Gist options
  • Save minichiello/3317759 to your computer and use it in GitHub Desktop.
Save minichiello/3317759 to your computer and use it in GitHub Desktop.
Deploying Sinatra/Thin to WebFaction
# config/config.ru
require "rubygems"
require "bundler/setup"
require './app'
run Sinatra::Application
# config/config.yml
environment: production
chdir: /home/user/webapps/app_name
address: 127.0.0.1
user: user
group: user
port: 12345 # you get this from the WebFaction Control Panel after creating the custom application
rackup: /home/user/webapps/app_name/config/config.ru
max_conns: 1024
timeout: 30
max_persistent_conns: 512
daemonize: true
require 'rake'
namespace :thin do
desc "Start the application"
task :start do
puts "Starting the application..."
system "thin -s 1 -C config/config.yml -R config/config.ru start"
end
desc "Stop the application"
task :stop do
puts "Stopping the application..."
Dir.new("/home/user/webapps/app_name/tmp/pids").each do |file|
prefix = file.to_s
if prefix[0, 4] == 'thin'
puts "Stopping server on port #{file[/\d+/]}..."
system "thin stop -Ptmp/pids/#{file}"
end
end
end
desc "Restart the application"
task :restart do
puts "Restarting the application..."
Rake::Task["thin:stop"].invoke
Rake::Task["thin:start"].invoke
end
end
desc "Deploy to server"
task :deploy, :password do |t, args|
puts "Deploying to server..."
system "rsync --exclude 'log/*.log' --exclude 'tmp/**/*' --exclude '.git' --exclude '.gitignore' -rltvz -e ssh . user@user.webfactional.com:/home/user/webapps/app_name"
require "net/ssh"
Net::SSH.start("user.webfactional.com", "user", :password => args[:password]) do |ssh|
commands = [
"cd /home/user/webapps/app_name",
"rvm use 1.9.3-p194@app_name --create", # assumes, rvm is already setup on the server
"bundle install --without=development",
# "bundle exec whenever --update-crontab", optionally, schedule cron jobs using whenever
"bundle exec rake thin:restart"
].join " && "
ssh.exec commands
end
puts "Finished!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment