Skip to content

Instantly share code, notes, and snippets.

@dstrelau
Created November 3, 2008 21:05
Show Gist options
  • Save dstrelau/21980 to your computer and use it in GitHub Desktop.
Save dstrelau/21980 to your computer and use it in GitHub Desktop.
From 1cff7685f5a2013d3e3b13a7407ea64e21aae4de Mon Sep 17 00:00:00 2001
From: dean <dean@26634371-c258-0410-a0b0-f38a24f56ed3>
Date: Fri, 31 Oct 2008 21:50:16 +0000
Subject: [PATCH] Swizzle recipes organization
git-svn-id: svn+ssh://development.mintdigital.com/mint/svn/briarpatch/branches/caplets@73 26634371-c258-0410-a0b0-f38a24f56ed3
---
lib/caplets/plugins/apt.rb | 18 +++++++++++
lib/caplets/plugins/aptitude.rb | 18 -----------
lib/recipes/deploy.rb | 23 ++++++++++++++
lib/recipes/deploy/db.rb | 42 +++++++++++++++++++++++++
lib/recipes/deploy/gems.rb | 11 +++++++
lib/recipes/deploy/mongrel.rb | 5 +++
lib/recipes/deploy/monit.rb | 5 +++
lib/recipes/deploy/nginx.rb | 32 +++++++++++++++++++
lib/recipes/memcached.rb | 9 -----
lib/recipes/mongrel.rb | 4 --
lib/recipes/monit.rb | 11 -------
lib/recipes/mysql.rb | 7 ----
lib/recipes/nginx.rb | 39 -----------------------
lib/recipes/rails.rb | 34 --------------------
lib/recipes/rails/db.rb | 50 ------------------------------
lib/recipes/ruby.rb | 9 -----
lib/recipes/rubygems.rb | 8 -----
lib/recipes/slice/install.rb | 64 +++++++++++++++++++++++++++++++++++++++
lib/recipes/slice/setup.rb | 17 ++++++++++
lib/recipes/sphinx.rb | 9 -----
20 files changed, 217 insertions(+), 198 deletions(-)
create mode 100644 lib/caplets/plugins/apt.rb
delete mode 100644 lib/caplets/plugins/aptitude.rb
create mode 100644 lib/recipes/deploy.rb
create mode 100644 lib/recipes/deploy/db.rb
create mode 100644 lib/recipes/deploy/gems.rb
create mode 100644 lib/recipes/deploy/mongrel.rb
create mode 100644 lib/recipes/deploy/monit.rb
create mode 100644 lib/recipes/deploy/nginx.rb
delete mode 100644 lib/recipes/memcached.rb
delete mode 100644 lib/recipes/mongrel.rb
delete mode 100644 lib/recipes/monit.rb
delete mode 100644 lib/recipes/mysql.rb
delete mode 100644 lib/recipes/nginx.rb
delete mode 100644 lib/recipes/rails.rb
delete mode 100644 lib/recipes/rails/db.rb
delete mode 100644 lib/recipes/ruby.rb
delete mode 100644 lib/recipes/rubygems.rb
create mode 100644 lib/recipes/slice/install.rb
create mode 100644 lib/recipes/slice/setup.rb
delete mode 100644 lib/recipes/sphinx.rb
diff --git a/lib/caplets/plugins/apt.rb b/lib/caplets/plugins/apt.rb
new file mode 100644
index 0000000..0730d5d
--- /dev/null
+++ b/lib/caplets/plugins/apt.rb
@@ -0,0 +1,18 @@
+module Caplets::Plugins::Apt
+
+ # Install a package through apt.
+ #
+ # ==== Arguments
+ # +pkg+:: List of package names, or a single package. Strings or symbols.
+ #
+ # ==== Examples
+ # apt.install 'nginx'
+ # apt.install 'ruby1.8', 'ruby1.8-dev', 'libruby1.8'
+ #
+ def install(*pkgs)
+ sudo "apt-get install -y -q #{pkgs.flatten.join(' ')}"
+ end
+
+end
+
+Capistrano.plugin :apt, Caplets::Plugins::Apt
\ No newline at end of file
diff --git a/lib/caplets/plugins/aptitude.rb b/lib/caplets/plugins/aptitude.rb
deleted file mode 100644
index 2330094..0000000
--- a/lib/caplets/plugins/aptitude.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-module Caplets::Plugins::Aptitude
-
- # Install a package through aptitude.
- #
- # ==== Arguments
- # +pkg+:: List of package names, or a single package. Strings or symbols.
- #
- # ==== Examples
- # aptitude.install 'nginx'
- # aptitude.install 'ruby1.8', 'ruby1.8-dev', 'libruby1.8'
- #
- def install(*pkgs)
- run_via "aptitude install -y -q #{pkgs.flatten.join(' ')}"
- end
-
-end
-
-Capistrano.plugin :aptitude, Caplets::Plugins::Aptitude
\ No newline at end of file
diff --git a/lib/recipes/deploy.rb b/lib/recipes/deploy.rb
new file mode 100644
index 0000000..58d5d86
--- /dev/null
+++ b/lib/recipes/deploy.rb
@@ -0,0 +1,23 @@
+set :user, 'mint'
+set :group, 'mint'
+set :password, 'mintyfr3sh'
+set :use_sudo, false
+set :scm, 'git'
+set :branch, 'master'
+set :deploy_via, 'remote_cache'
+set :deploy_to, "/mint/#{application}"
+
+set :mongrel_pid_file, "#{shared_path}/pids/mongrel.pid"
+set :mongrel_address, '0.0.0.0'
+set :mongrel_conf, "#{shared_path}/mongrel_cluster.yml"
+set :mongrel_port, 8000
+set :mongrel_servers, 2
+
+default_run_options[:pty] = true
+ssh_options[:forward_agent] = true
+
+def rake(cmd)
+ run "cd #{current_path} && RAILS_ENV=production rake #{cmd}"
+end
+
+# bunch of requires here
\ No newline at end of file
diff --git a/lib/recipes/deploy/db.rb b/lib/recipes/deploy/db.rb
new file mode 100644
index 0000000..0cb1bf7
--- /dev/null
+++ b/lib/recipes/deploy/db.rb
@@ -0,0 +1,42 @@
+namespace :deploy do
+ namespace :db do
+ desc "create the production database"
+ task :create, :roles => :app do
+ rake "db:create"
+ end
+
+ desc "load the schema file for initial app setup"
+ task :schema_load, :roles => :app do
+ rake "db:schema:load"
+ end
+
+ desc "run any pending migrations"
+ task :migrate, :roles => :app do
+ rake "db:migrate"
+ end
+
+ desc "write database.yml to the shared directory"
+ task :config, :roles => :app do
+ config = {
+ 'production' => {
+ 'host' => roles[:db].servers.first.to_s,
+ 'adapter' => 'mysql',
+ 'database' => "#{application}_production",
+ 'username' => 'mint',
+ 'password' => ''
+ }
+ }
+ put YAML.dump(config), "#{shared_path}/database.yml"
+ end
+
+ desc "symlink database.yml to the shared copy"
+ task :symlink, :roles => :app do
+ run "ln -nfs #{shared_path}/database.yml #{release_path}/config/database.yml"
+ end
+ end #namespace :db
+end #namespace :deploy
+
+## Hooks ##
+after 'deploy:setup', 'db:config'
+after 'deploy:update_code', 'db:symlink'
+after 'update', 'db:migrate'
diff --git a/lib/recipes/deploy/gems.rb b/lib/recipes/deploy/gems.rb
new file mode 100644
index 0000000..9cb68df
--- /dev/null
+++ b/lib/recipes/deploy/gems.rb
@@ -0,0 +1,11 @@
+namespace :deploy do
+ namespace :gems do
+
+ task :install do
+ # rake gems:install
+ # after deploy:update_code
+ raise NotImplementedError
+ end
+
+ end # namespace :gems
+end # namespace :gems
diff --git a/lib/recipes/deploy/mongrel.rb b/lib/recipes/deploy/mongrel.rb
new file mode 100644
index 0000000..993c789
--- /dev/null
+++ b/lib/recipes/deploy/mongrel.rb
@@ -0,0 +1,5 @@
+namespace :deploy do
+ namespace :mongrel do
+ # Creating/writing config files
+ end # namespace :mongrel
+end # namespace :deploy
\ No newline at end of file
diff --git a/lib/recipes/deploy/monit.rb b/lib/recipes/deploy/monit.rb
new file mode 100644
index 0000000..b4fea0e
--- /dev/null
+++ b/lib/recipes/deploy/monit.rb
@@ -0,0 +1,5 @@
+namespace :deploy do
+ namespace :monit do
+ # Creating/loading config files
+ end # namespace :monit
+end # namespace :deploy
\ No newline at end of file
diff --git a/lib/recipes/deploy/nginx.rb b/lib/recipes/deploy/nginx.rb
new file mode 100644
index 0000000..d484d0b
--- /dev/null
+++ b/lib/recipes/deploy/nginx.rb
@@ -0,0 +1,32 @@
+set :nginx_pid, "/var/run/nginx.pid"
+set :nginx_conf, "/etc/nginx/nginx.conf"
+set :nginx_conf_dir, "/etc/nginx/sites-enabled"
+
+namespace :deploy do
+ namespace :nginx do
+ desc "Generate & push the nginx config file"
+ task :config, :roles => :web do
+ raise NotImplementedError
+ end
+
+ desc "Start up nginx. If it is already running, send it a HUP instead."
+ task :start, :roles => :web do
+ run <<-CMD.gsub(/\n/, "; ")
+ if [ -f #{nginx_pid} ]
+ then #{sudo} kill -HUP $(cat #{nginx_pid})
+ else #{sudo} nginx -t -c #{nginx_conf} && #{sudo} nginx -c #{nginx_conf}
+ fi
+ CMD
+ end
+
+ desc "Stop nginx"
+ task :stop, :roles => :web do
+ sudo "kill -QUIT $(cat #{nginx_pid})"
+ end
+
+ desc "Reload the nginx config by sending a HUP"
+ task :reload, :roles => :web do
+ sudo "#{sudo} nginx -t -c #{nginx_conf} && #{sudo} kill -HUP $(cat #{nginx_pid})"
+ end
+ end # namespace :nginx
+end # namespace :deploy
\ No newline at end of file
diff --git a/lib/recipes/memcached.rb b/lib/recipes/memcached.rb
deleted file mode 100644
index 1beefdf..0000000
--- a/lib/recipes/memcached.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-namespace :memcached do
- desc "Install latest memcached from source"
- task :install do
- # aptitude install libc6, libevent1 first
- # download latest version -- http://www.danga.com/memcached/download.bml
- # config / make / make install
- raise NotImplementedError
- end
-end
\ No newline at end of file
diff --git a/lib/recipes/mongrel.rb b/lib/recipes/mongrel.rb
deleted file mode 100644
index c12fe1e..0000000
--- a/lib/recipes/mongrel.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace :mongrel do
-
- # write config file
-end
\ No newline at end of file
diff --git a/lib/recipes/monit.rb b/lib/recipes/monit.rb
deleted file mode 100644
index 7412f7c..0000000
--- a/lib/recipes/monit.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-namespace :monit do
- desc "Install monit from source"
- task :install do
- # aptitude install libc6, libssl0.9.8 first
- # download latest version -- http://mmonit.com/monit/download/
- # config / make / make install
- raise NotImplementedError
- end
-
- # More for creating/loading config files
-end
\ No newline at end of file
diff --git a/lib/recipes/mysql.rb b/lib/recipes/mysql.rb
deleted file mode 100644
index 817a8af..0000000
--- a/lib/recipes/mysql.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace :mysql do
- desc "Install MySQL 5"
- task :install, :roles => :db do
- # install from source or aptitude?
- raise NotImplementedError
- end
-end
\ No newline at end of file
diff --git a/lib/recipes/nginx.rb b/lib/recipes/nginx.rb
deleted file mode 100644
index 960fa4a..0000000
--- a/lib/recipes/nginx.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-set :nginx_pid, "/var/run/nginx.pid"
-set :nginx_conf, "/etc/nginx/nginx.conf"
-set :nginx_conf_dir, "/etc/nginx/sites-enabled"
-
-namespace :nginx do
- desc "Install Nginx (stable) from source."
- task :install, :roles => :web do
- # aptitude install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev
- # download latest version -- http://sysoev.ru/nginx/download.html
- # include the fair proxy module -- http://wiki.codemongers.com/NginxHttpUpstreamFairModule
- # config / make / make install
- raise NotImplementedError
- end
-
- desc "Generate & push the nginx config file"
- task :config, :roles => :web do
- raise NotImplementedError
- end
-
- desc "Start up nginx. If it is already running, send it a HUP instead."
- task :start, :roles => :web do
- run <<-CMD.gsub(/\n/, "; ")
- if [ -f #{nginx_pid} ]
- then #{sudo} kill -HUP $(cat #{nginx_pid})
- else #{sudo} nginx -t -c #{nginx_conf} && #{sudo} nginx -c #{nginx_conf}
- fi
- CMD
- end
-
- desc "Stop nginx"
- task :stop, :roles => :web do
- sudo "kill -QUIT $(cat #{nginx_pid})"
- end
-
- desc "Reload the nginx config by sending a HUP"
- task :reload, :roles => :web do
- sudo "#{sudo} nginx -t -c #{nginx_conf} && #{sudo} kill -HUP $(cat #{nginx_pid})"
- end
-end # namespace nginx
diff --git a/lib/recipes/rails.rb b/lib/recipes/rails.rb
deleted file mode 100644
index c7dda33..0000000
--- a/lib/recipes/rails.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-set :user, 'mint'
-set :group, 'mint'
-set :password, 'mintyfr3sh'
-set :use_sudo, false
-set :scm, 'git'
-set :branch, 'master'
-set :deploy_via, 'remote_cache'
-set :deploy_to, "/mint/#{application}"
-
-set :mongrel_pid_file, "#{shared_path}/pids/mongrel.pid"
-set :mongrel_address, '0.0.0.0'
-set :mongrel_conf, "#{shared_path}/mongrel_cluster.yml"
-set :mongrel_port, 8000
-set :mongrel_servers, 2
-
-default_run_options[:pty] = true
-ssh_options[:forward_agent] = true
-
-namespace :rails do
- desc 'Install the Rails gem.'
- task :install, :roles => :app do
- raise NotImplementedError
- end
-
- desc 'Install the Rails gem plus additional commonly used gems.'
- task :install_stack, :roles => :app
- # rails, mongrel, ultrasphinx, memcache-client, mislav-will_paginate
- raise NotImplementedError
- end
-end
-
-def rake(cmd)
- run "cd #{current_path} && RAILS_ENV=production rake #{cmd}"
-end
\ No newline at end of file
diff --git a/lib/recipes/rails/db.rb b/lib/recipes/rails/db.rb
deleted file mode 100644
index 068bc92..0000000
--- a/lib/recipes/rails/db.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-namespace :rails do
- namespace :db do
- desc "create the production database"
- task :create, :roles => :app do
- rake "db:create"
- end
-
- desc "load the schema file for initial app setup"
- task :schema_load, :roles => :app do
- rake "db:schema:load"
- end
-
- desc "run any pending migrations"
- task :migrate, :roles => :app do
- rake "db:migrate"
- end
-
- desc "write database.yml to the shared directory"
- task :config, :roles => :app do
- config = {
- 'production' => {
- 'host' => roles[:db].servers.first.to_s,
- 'adapter' => 'mysql',
- 'database' => "#{application}_production",
- 'username' => 'mint',
- 'password' => ''
- }
- }
- put YAML.dump(config), "#{shared_path}/database.yml"
- end
-
- desc "symlink database.yml to the shared copy"
- task :symlink, :roles => :app do
- run "ln -nfs #{shared_path}/database.yml #{release_path}/config/database.yml"
- end
- end #namespace :db
-
- namespace :gems do
- task :install do
- # rake gems:install
- # after deploy:update_code
- raise NotImplementedError
- end
- end
-end #namespace :rails
-
-## Hooks ##
-after 'deploy:setup', 'db:config'
-after 'deploy:update_code', 'db:symlink'
-after 'update', 'db:migrate'
diff --git a/lib/recipes/ruby.rb b/lib/recipes/ruby.rb
deleted file mode 100644
index a0cd979..0000000
--- a/lib/recipes/ruby.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-namespace :ruby do
- desc "Install Ruby 1.8 through aptitude."
- task :install, :roles => :app do
- # for all the packages we need, see the Ruby section of
- # http://articles.slicehost.com/2008/4/30/ubuntu-hardy-ruby-on-rails
- raise NotImplementedError
- end
-end
-
diff --git a/lib/recipes/rubygems.rb b/lib/recipes/rubygems.rb
deleted file mode 100644
index f877047..0000000
--- a/lib/recipes/rubygems.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-namespace :rubygems do
- desc "Install latest rubygems from aptitude then self-update"
- task :install, :roles => :app do
- # aptitude install rubygems
- # gem update --system
- raise NotImplementedError
- end
-end
\ No newline at end of file
diff --git a/lib/recipes/slice/install.rb b/lib/recipes/slice/install.rb
new file mode 100644
index 0000000..b01ddf6
--- /dev/null
+++ b/lib/recipes/slice/install.rb
@@ -0,0 +1,64 @@
+desc "Install monit from source."
+task :monit do
+ # apt install: libc6, libssl0.9.8 first
+ # download latest version -- http://mmonit.com/monit/download/
+ # config / make / make install
+ raise NotImplementedError
+end
+
+desc "Install memcached from source."
+task :memcache do
+ # apt install: libc6, libevent1 first
+ # download latest version -- http://www.danga.com/memcached/download.bml
+ # config / make / make install
+ raise NotImplementedError
+end
+
+desc "Install Nginx (stable) from source."
+task :nginx, :roles => :web do
+ # aptitude install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev
+ # download latest version -- http://sysoev.ru/nginx/download.html
+ # include the fair proxy module -- http://wiki.codemongers.com/NginxHttpUpstreamFairModule
+ # config / make / make install
+ raise NotImplementedError
+end
+
+
+desc "Install Sphinx from source."
+task :sphinx do
+ # depends on mysql5
+ # download latest version -- http://sphinxsearch.com/downloads.html
+ # config / make / make install
+ raise NotImplementedError
+end
+
+desc "Install Ruby 1.8 through apt."
+task :ruby, :roles => :app do
+ # apt install: ruby1.8 ruby1.8-dev libreadline-ruby1.8 irb1.8 ri1.8 rdoc1.8
+ # sudo ln -s /usr/bin/ruby1.8 /usr/bin/ruby
+ # sudo ln -s /usr/bin/irb1.8 /usr/bin/irb
+ # sudo ln -s /usr/bin/ri1.8 /usr/bin/ri
+ # sudo ln -s /usr/bin/rdoc1.8 /usr/bin/rdoc
+
+ raise NotImplementedError
+end
+
+desc "Install latest rubygems from source. Include rails & mongrel"
+task :rubygems, :roles => :app do
+ # curl -LO http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz
+ # tar xzf rubygems-1.3.1.tgz
+ # cd rubygems-1.3.1
+ # sudo ruby setup.rb
+ # cd ..
+ # rm -r rubygems*
+ # gem sources -a http://gems.github.com
+ # echo "gem: --no-ri --no-rdoc" >> .gemrc
+ # sudo gem install rails mongrel mongrel_cluster
+ raise NotImplementedError
+end
+
+desc "Install MySQL 5 through apt."
+task :mysql, :roles => :db do
+ # apt install: mysql-server
+ raise NotImplementedError
+end
diff --git a/lib/recipes/slice/setup.rb b/lib/recipes/slice/setup.rb
new file mode 100644
index 0000000..2ac797c
--- /dev/null
+++ b/lib/recipes/slice/setup.rb
@@ -0,0 +1,17 @@
+namespace :slice do
+ namespace :setup do
+
+ desc 'Fully configure an application slice'
+ task :app do
+ end
+
+ desc 'Fully configure a database slice'
+ task :db do
+ end
+
+ desc 'Fully configure a web slice'
+ task :web do
+ end
+
+ end
+end
\ No newline at end of file
diff --git a/lib/recipes/sphinx.rb b/lib/recipes/sphinx.rb
deleted file mode 100644
index 6d04069..0000000
--- a/lib/recipes/sphinx.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-namespace :sphinx do
- desc "Install Sphinx from source"
- task :install do
- # depends on mysql5
- # download latest version -- http://sphinxsearch.com/downloads.html
- # config / make / make install
- raise NotImplementedError
- end
-end
\ No newline at end of file
--
1.6.0+GitX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment