Created
June 11, 2012 08:27
-
-
Save dwayne/2909075 to your computer and use it in GitHub Desktop.
Revisions
-
dwayne revised this gist
Nov 21, 2012 . 2 changed files with 40 additions and 21 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ # 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 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 charactersOriginal file line number Diff line number Diff line change @@ -14,13 +14,19 @@ namespace :thin do 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 @@ -34,26 +40,32 @@ namespace :thin do 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 -
dwayne revised this gist
Nov 20, 2012 . 1 changed file with 3 additions and 3 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,12 @@ # Server options: port: 12345 # Adapter options: environment: production # Daemon options: daemonize: true user: user group: group # See `thin -h` for more options -
dwayne revised this gist
Nov 20, 2012 . 6 changed files with 51 additions and 30 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ # These directories are created by Thin when `rake:thin start` is invoked log/ tmp/ 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 charactersOriginal file line number Diff line number Diff line change @@ -1,34 +1,41 @@ 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...' Dir.new(File.join(File.dirname(__FILE__), 'tmp/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 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 # FIXME: Refactor the deployment code desc "Deploy to server" task :deploy, :password do |t, args| puts "Deploying to server..." 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ # Server options: address: 127.0.0.1 port: 5000 # Adapter options: environment: development # See `thin -h` for more options 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ # Server options: port: 27017 # Adapter options: environment: production # Daemon options: daemonize: true user: dwaynecrooks group: dwaynecrooks # See `thin -h` for more options 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,11 @@ # 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 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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +0,0 @@ -
dwayne revised this gist
Jun 11, 2012 . 1 changed file with 7 additions and 9 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -11,13 +11,11 @@ namespace :thin do 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 @@ -35,13 +33,13 @@ 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 . [email protected]:/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" -
dwayne created this gist
Jun 11, 2012 .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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ 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| Thread.new do 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 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 '.rvmrc' --exclude '.git' --exclude '.gitignore' -rltvz -e ssh . [email protected]:/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@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 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ # config/config.ru require "rubygems" require "bundler/setup" require './app' run Sinatra::Application 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ # 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