Isnor Creative
Isnor Creative Blog
Ruby, Ruby on Rails, Ember, Elm, Phoenix, Elixir, React, Vue

Jun 3, 2009

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.

  1. ## 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
  2. 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).
  3. Set up the config files and a Rakefile: ### config.ru
    require 'mypp'
    run Sinatra::Application
    view raw config.ru hosted with ❤ by GitHub
    ### config.yml
    ---
    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
    view raw config.yml hosted with ❤ by GitHub
    ### Rakefile
    require '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
    view raw rakefile.rb hosted with ❤ by GitHub
  4. To deploy the site, rake deploy.

I am available for Ruby on Rails consulting work – get in touch to learn more.

Gordon B. Isnor

Gordon B. Isnor writes about Ruby on Rails, Ember.js, Elm, Elixir, Phoenix, React, Vue and the web.
If you enjoyed this article, you may be interested in the occasional newsletter.

I am now available for project work. I have availability to build greenfield sites and applications, to maintain and update/upgrade existing applications, team augmentation. I offer website/web application assessment packages that can help with SEO/security/performance/accessibility and best practices. Let’s talk