My Recipe For Sinatra/Thin/Rack/Webfaction
The solution I am using for deploying a Sinatra app that runs on Thin and Rack on Webfaction, without Capistrano or Git, just using Rsync and Rake.
-
## Create the application:
myapp config config.ru config.yml db migrate rake migration files myapp.sqlite3.db myapp.rb lib models public stylesheets images javascripts Rakefile tmp/ views layout.erb myview.erb
- In the Wefaction Control Panel, create a custom application listening on port, get the port number, needed for config files. Create a domain. Create a website that links a domain to the application. Do a custom Ruby install. Install any necessary gems (eg Thin, Rack, ActiveRecord, whatever).
-
Set up the config files and a Rakefile:
### config.ru
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 characters
require 'mypp' 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 characters--- environment: production chdir: /home/me/webapps/myapp address: 127.0.0.1 user: root group: root port: myport rackup: /home/me/webapps/myapp/config/config.ru log: /home/me/webapps/myapp/thin.log max_conns: 1024 timeout: 30 max_persistent_conns: 512 daemonize: true 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 charactersrequire 'rake' namespace :thin do desc "Start The Application" task :start do puts "Restarting 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/me/webapps/myapp/tmp/pids").each do |file| Thread.new do prefix = file.to_s if prefix[0, 4] == 'thin' str = "thin stop -Ptmp/pids/#{file}" puts "Stopping server on port #{file[/\d+/]}..." system(str) end end end end desc "Restart The Application" task :restart do puts "Restarting The Application..." [:stop, :start] end end task :deploy do puts "Deploying to server" system("rsync --exclude 'db/myapp.sqlite3.db' --exclude 'tmp/**/*' -rltvz -e ssh . me@mydomain.com:/home/me/webapps/myapp") require 'net/ssh' Net::SSH.start('mydomain.com', 'my user name', :password => "my password") do |ssh| ssh.exec "cd /home/me/webapps/myapp && rake thin:restart" end end - To deploy the site, rake deploy.
I am available for Ruby on Rails consulting work – get in touch to learn more.