Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Update how we provision and deploy to server
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjlandau committed Jan 15, 2011
1 parent 8157a1c commit 9135ed5
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -12,3 +12,5 @@ config/deploy.rb
config/database.yml
db/*.sqlite3
.rvmrc
config/stack/files/monitrc.conf
config/stack/files/nginx.conf.sample
22 changes: 17 additions & 5 deletions config/deploy.example.rb
@@ -1,7 +1,12 @@
set :application, "watch-dog"
set :application, "watchdog"
set :use_sudo, false
set :repository, "git://github.com/vigetlabs/watch-dog.git"
set :scm, :git
set :ssh_options, {:forward_agent => true}
set :branch, 'origin/master'
set :user, "watchdog-deploy"
set :deploy_to, "/var/www/#{application}"
set :rake, "/usr/local/bin/rake"

set(:latest_release) { fetch(:current_path) }
set(:release_path) { fetch(:current_path) }
Expand All @@ -13,16 +18,14 @@

set(:moinitrc_path) { File.join(shared_path, 'monitrc') }

set :deploy_to, "/var/www/html/#{application}"
default_run_options[:shell] = 'bash'

set :user, "watch-dog-deploy"
default_environment["RACK_ENV"] = 'production'

role :web, "your.server.com"
role :app, "your.server.com"
role :db, "your.server.com", :primary => true

set :branch, 'origin/master'

after "deploy:update_code", "app:symlinks"

namespace :deploy do
Expand Down Expand Up @@ -58,6 +61,13 @@
run "cd #{current_path}; touch tmp/restart.txt"
end

desc "Run the database migrations"
task :migrations, :except => { :no_release => true } do
update_code
run "cd #{current_path}; #{rake} RACK_ENV=production db:migrate"
restart
end

namespace :rollback do
desc "Moves the repo back to the previous version of HEAD"
task :repo, :except => { :no_release => true } do
Expand All @@ -82,5 +92,7 @@
desc "Make symlinks"
task :symlinks do
run "ln -nfs #{shared_path}/monitrc #{current_path}/monitrc"
run "ln -nfs #{shared_path}/config/database.yml #{current_path}/config/database.yml"
run "ln -nfs #{shared_path}/config/settings.yml #{current_path}/config/settings.yml"
end
end
52 changes: 52 additions & 0 deletions config/provision.rb
@@ -0,0 +1,52 @@
require 'highline/import'
require 'erb'

# Require our stack
Dir[File.join(File.dirname(__FILE__), 'stack', '*.rb')].each do |lib|
require lib
end

policy :watchdog_stack, :roles => :provision do
requires :ruby_enterprise
requires :nginx_passenger
requires :nginx_conf
requires :nginx_init
requires :git
requires :monit
requires :monit_conf
requires :rack
requires :sinatra
requires :sqlite
requires :sqlite_driver
end

deployment do
# mechanism for deployment
delivery :capistrano do
begin
recipes 'Capfile'
rescue LoadError
recipes 'deploy'
end

default_run_options[:pty] = true
set :use_sudo, true
role :provision, ask("Enter the IP address or hostname to provision: ")
set :user, ask("Enter your username on the host to provision: ") { |q| q.default = ENV['USER'] }
end

# source based package installer defaults
source do
prefix '/usr/local'
archives '/usr/local/sources'
builds '/usr/local/build'
end
end

# Depend on a specific version of sprinkle
begin
gem 'sprinkle', ">= 0.2.6"
rescue Gem::LoadError
puts "sprinkle 0.2.6 required.\n Run: `gem install sprinkle`"
exit
end
7 changes: 7 additions & 0 deletions config/stack/dependencies.rb
@@ -0,0 +1,7 @@
package :dependencies do
apt %w(libglib2.0-dev cmake libpcre3 libpcre3-dev libxml2-dev
libxml2 libxslt-dev libgcrypt11-dev libreadline5-dev zlib1g-dev zlibc
libedit-dev gettext logrotate libcurl4-openssl-dev
libevent-dev libevent-1.4-2 openssl libssl-dev)
requires :build_essential
end
7 changes: 7 additions & 0 deletions config/stack/essential.rb
@@ -0,0 +1,7 @@
package :build_essential do
description 'Build tools'
apt 'build-essential' do
pre :install, 'apt-get update'
pre :install, 'apt-get upgrade'
end
end
70 changes: 70 additions & 0 deletions config/stack/files/nginx-init.sh
@@ -0,0 +1,70 @@
#! /bin/sh

# Provides: nginx
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'sudo update-rc.d nginx defaults', or use the appropriate command on your
# distro.
#
# Author: Ryan Norbauer <ryan.norbauer@gmail.com>
# Modified: Geoffrey Grosenbach http://topfunky.com

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/nginx.conf
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

d_start() {
$DAEMON -c $CONFIGFILE || echo -n " already running"
}

d_stop() {
kill -QUIT `cat $PIDFILE` || echo -n " not running"
}

d_reload() {
kill -HUP `cat $PIDFILE` || echo -n " can't reload"
}

case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
d_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
# One second might not be time enough for a daemon to stop,
# if this happens, d_start will fail (and dpkg will break if
# the package is being upgraded). Change the timeout if needed
# be, or change d_stop to have start-stop-daemon use --retry.
# Notice that using --retry slows down the shutdown process somewhat.
sleep 1
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac

exit 0
9 changes: 9 additions & 0 deletions config/stack/gems.rb
@@ -0,0 +1,9 @@
package :rack do
gem 'rack'
version '1.1.0'
end

package :sinatra do
gem 'sinatra'
version '1.1.0'
end
15 changes: 15 additions & 0 deletions config/stack/git.rb
@@ -0,0 +1,15 @@
package :git, :provides => :scm do
description 'Git Distributed Version Control'
version '1.7.3.5'
source "http://kernel.org/pub/software/scm/git/git-#{version}.tar.gz"
requires :git_dependencies

verify do
has_file '/usr/local/bin/git'
end
end

package :git_dependencies do
description 'Git Build Dependencies'
apt 'git-core', :dependencies_only => true
end
23 changes: 23 additions & 0 deletions config/stack/monit.rb
@@ -0,0 +1,23 @@
package :monit, :provides => :monitoring do
description 'installs monit - a system monitoring utility which allows an admin to easily monitor files, processes, directories, or devices on your system.'

apt "monit"

requires :build_essential, :dependencies

verify do
has_executable "monit"
end
end

package :monit_conf do
description "Monit conf file"
requires :monit
install_path "/etc/monit/monitrc"

transfer 'config/stack/files/monitrc.conf', "/tmp/monitrc" do
post :install, "mv -f /tmp/monitrc /etc/monit/monitrc"
post :install, "chown root:root /etc/monit/monitrc"
post :install, "chmod u=rw,go= /etc/monit/monitrc"
end
end
48 changes: 48 additions & 0 deletions config/stack/nginx.rb
@@ -0,0 +1,48 @@
package :nginx_passenger, :provides => [:webserver, :appserver] do
description "Nginx with the Passenger module"
version "0.8.54"
install_path "/usr/local/nginx"

source "http://sysoev.ru/nginx/nginx-#{version}.tar.gz" do
custom_install "sudo /usr/local/bin/passenger-install-nginx-module " +
"--auto --prefix=#{install_path} --nginx-source-dir=/usr/local/build/nginx-#{version} " +
"--extra-configure-flags='--with-http_ssl_module'"
post :install, "ln -s #{install_path}/sbin/nginx /usr/local/bin/nginx"
post :install, "chown -R deploy /usr/local/nginx/logs"
post :install, "mkdir /var/www"
post :install, "chown -R deploy /var/www"
end

verify do
has_directory "/usr/local/nginx"
has_file "/usr/local/nginx/conf/nginx.conf"
has_executable "/usr/local/nginx/sbin/nginx"
end

requires :ruby_enterprise, :build_essential, :dependencies
end

package :nginx_init do
description "Nginx init.d file for Ubuntu"
install_path "/etc/init.d"

transfer 'config/stack/files/nginx-init.sh', '/tmp/nginx' do
post :install, "mv -f /tmp/nginx /etc/init.d/nginx"
post :install, "chmod +x /etc/init.d/nginx"
post :install, "/usr/sbin/update-rc.d -f nginx defaults"
post :install, "/etc/init.d/nginx start"
end

requires :nginx_passenger
end

package :nginx_conf do
description "Sample Nginx conf file"
install_path "/usr/local/nginx/conf/nginx.conf"

transfer 'config/stack/files/nginx.conf.sample', '/tmp/nginx.conf' do
post :install, "mv -f /tmp/nginx.conf /usr/local/nginx/conf/nginx.conf"
end

requires :nginx_passenger
end
20 changes: 20 additions & 0 deletions config/stack/ree.rb
@@ -0,0 +1,20 @@
package :ruby_enterprise do
description 'Ruby Enterprise Edition'
version '1.8.7-2010.02'

install_path = "/usr/local/ruby-enterprise"
binaries = %w(erb gem irb passenger-config passenger-install-apache2-module passenger-install-nginx-module passenger-make-enterprisey passenger-memory-stats passenger-spawn-server passenger-status passenger-stress-test rackup rails rake rdoc ree-version ri ruby testrb)
source "http://rubyforge.org/frs/download.php/71096/ruby-enterprise-#{version}.tar.gz" do
custom_install './installer --auto=/usr/local/ruby-enterprise'

binaries.each {|bin| post :install, "ln -s #{install_path}/bin/#{bin} /usr/local/bin/#{bin}" }
end

verify do
has_directory install_path
has_executable "#{install_path}/bin/ruby"
binaries.each {|bin| has_symlink "/usr/local/bin/#{bin}", "#{install_path}/bin/#{bin}" }
end

requires :dependencies
end
23 changes: 23 additions & 0 deletions config/stack/sqlite.rb
@@ -0,0 +1,23 @@
package :sqlite, :provides => :database do
description 'SQLite 3 Database'
apt 'sqlite3'

verify do
has_executable 'sqlite3'
end

requires :build_essential
optional :sqlite_driver
end

package :sqlite_driver, :provides => :ruby_database_driver do
description 'Ruby SQLite database driver'
apt 'libsqlite3-dev'
gem 'sqlite3-ruby'

verify do
has_gem 'sqlite3-ruby'
end

requires :ruby_enterprise
end

0 comments on commit 9135ed5

Please sign in to comment.