initial commit

master
Thomas Riboulet 10 years ago
commit 16eee710ba

@ -0,0 +1,4 @@
source 'https://rubygems.org'
gem 'sinatra'
gem 'unicorn'
gem 'capistrano', '2.15.5'

@ -0,0 +1,39 @@
GEM
remote: https://rubygems.org/
specs:
capistrano (2.15.5)
highline
net-scp (>= 1.0.0)
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
highline (1.6.21)
kgio (2.9.2)
net-scp (1.1.2)
net-ssh (>= 2.6.5)
net-sftp (2.1.2)
net-ssh (>= 2.6.5)
net-ssh (2.8.0)
net-ssh-gateway (1.2.0)
net-ssh (>= 2.6.5)
rack (1.5.2)
rack-protection (1.5.2)
rack
raindrops (0.13.0)
sinatra (1.4.4)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
tilt (1.4.1)
unicorn (4.8.2)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
PLATFORMS
ruby
DEPENDENCIES
capistrano (= 2.15.5)
sinatra
unicorn

@ -0,0 +1,2 @@
require './hello'
run SimpleApp

@ -0,0 +1,49 @@
require "bundler/capistrano"
set :bundle_flags, "--deployment --quiet --binstubs"
set :domain, "arbousier.info"
set :application, "sinatra_hello"
set :deploy_to, "/home/rails/#{application}"
set :unicorn_conf, "#{deploy_to}/current/config/unicorn.rb"
set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid"
set :user, "rails"
set :use_sudo, false
set :group, user
set :runner, user
set :default_environment, {
'PATH' => "/usr/local/rbenv/shims:/usr/local/rbenv/bin:$PATH"
}
set :scm, :git
set :repository, "git@github.com:mcansky/sinatra_hello.git"
set :branch, 'master'
set :git_shallow_clone, 1
set :host, "#{user}@109.107.37.177"
role :web, domain
role :app, domain
#role :db, domain, :primary => true
set :deploy_via, :remote_cache
# Unicorn control tasks
namespace :deploy do
task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
run "ln -nfs #{shared_path}/config/unicorn.rb #{release_path}/config/unicorn.rb"
end
task :restart do
run "if [ -f #{unicorn_pid} ]; then kill -USR2 `cat #{unicorn_pid}`; else cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D; fi"
end
task :start do
run "cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D"
end
task :stop do
run "if [ -f #{unicorn_pid} ]; then kill -QUIT `cat #{unicorn_pid}`; fi"
end
after "deploy:restart", "deploy:symlink_config"
end

@ -0,0 +1,46 @@
# define paths and filenames
deploy_to = "/home/rails/sinatra_hello"
rails_root = "#{deploy_to}/current"
pid_file = "#{deploy_to}/shared/pids/unicorn.pid"
socket_file= "#{deploy_to}/shared/unicorn.sock"
log_file = "#{rails_root}/log/unicorn.log"
err_log = "#{rails_root}/log/unicorn_error.log"
old_pid = pid_file + '.oldbin'
timeout 30
worker_processes 2 # increase or decrease
listen socket_file, :backlog => 1024
pid pid_file
stderr_path err_log
stdout_path log_file
# make forks faster
preload_app true
# make sure that Bundler finds the Gemfile
before_exec do |server|
ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__))
end
before_fork do |server, worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
# zero downtime deploy magic:
# if unicorn is already running, ask it to start a new process and quit.
if File.exists?(old_pid) && server.pid != old_pid
begin
Process.kill("QUIT", File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
# someone else did our job for us
end
end
end
after_fork do |server, worker|
# re-establish activerecord connections.
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end

@ -0,0 +1,9 @@
require 'sinatra'
class SimpleApp < Sinatra::Base
get '/' do
"Hello World!"
end
end
Loading…
Cancel
Save