Skip to content

Instantly share code, notes, and snippets.

@limeyd
Forked from dwayne/.excludes
Last active January 17, 2017 18:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save limeyd/5302716 to your computer and use it in GitHub Desktop.
Save limeyd/5302716 to your computer and use it in GitHub Desktop.
Webfaction setup
# 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/
# These directories are created by Thin when `rake:thin start` is invoked
log/
tmp/
# Server options:
address: 127.0.0.1
port: 5000
# Adapter options:
environment: development
# See `thin -h` for more options
# Server options:
port: 12345
# Adapter options:
environment: production
# Daemon options:
daemonize: true
user: user
group: group
# See `thin -h` for more options
# Assuming a classic style app
require './app'
run Sinatra::Application
# Modular style app
# require './awesome-app'
# run AwesomeApp
# or
# map('/end/point') { run AwesomeApp }
# Get rbenv
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
# Add rbenv to shell
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
# reload shell
exec $SHELL -l
# Get Ruby-build
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
# setup local $TMPDIR for ruby-build as webfaction /tmp is noexec
mkdir $HOME/tmp
echo 'export TMPDIR="$HOME/tmp"' >> ~/.bash_profile
# install ruby and activate
rbenv install 1.9.3-p392
rbenv global 1.9.3-p392
# install bundler
gem install bundler
#update rbenv shims
rbenv rehash
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