railslove_deploy 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/LICENSE +20 -0
  2. data/README +12 -0
  3. data/TODO +4 -0
  4. data/bin/deployify +31 -0
  5. data/lib/railslove/recipes/apache.rb +45 -0
  6. data/lib/railslove/recipes/backup.rb +8 -0
  7. data/lib/railslove/recipes/db.rb +52 -0
  8. data/lib/railslove/recipes/deploy.rb +49 -0
  9. data/lib/railslove/recipes/ferm.rb +12 -0
  10. data/lib/railslove/recipes/gems.rb +50 -0
  11. data/lib/railslove/recipes/helpers.rb +35 -0
  12. data/lib/railslove/recipes/hooks.rb +31 -0
  13. data/lib/railslove/recipes/job_runner.rb +17 -0
  14. data/lib/railslove/recipes/logrotate.rb +35 -0
  15. data/lib/railslove/recipes/memcache.rb +21 -0
  16. data/lib/railslove/recipes/misc.rb +36 -0
  17. data/lib/railslove/recipes/monit.rb +32 -0
  18. data/lib/railslove/recipes/passenger.rb +25 -0
  19. data/lib/railslove/recipes/shared.rb +16 -0
  20. data/lib/railslove/recipes/sphinx.rb +37 -0
  21. data/lib/railslove/recipes/workling.rb +26 -0
  22. data/lib/railslove/recipes.rb +7 -0
  23. data/lib/railslove/sprinkle/apache.rb +45 -0
  24. data/lib/railslove/sprinkle/essentials.rb +14 -0
  25. data/lib/railslove/sprinkle/ferm.rb +23 -0
  26. data/lib/railslove/sprinkle/git.rb +15 -0
  27. data/lib/railslove/sprinkle/image_magick.rb +5 -0
  28. data/lib/railslove/sprinkle/memcache.rb +42 -0
  29. data/lib/railslove/sprinkle/monit.rb +34 -0
  30. data/lib/railslove/sprinkle/mysql.rb +20 -0
  31. data/lib/railslove/sprinkle/nginx.rb +16 -0
  32. data/lib/railslove/sprinkle/passenger.rb +68 -0
  33. data/lib/railslove/sprinkle/rails_user.rb +19 -0
  34. data/lib/railslove/sprinkle/ruby_enterprise.rb +38 -0
  35. data/lib/railslove/sprinkle/sphinx.rb +14 -0
  36. data/lib/railslove/sprinkle/sqlite.rb +15 -0
  37. data/lib/railslove/sprinkle/subversion.rb +4 -0
  38. data/lib/railslove/sprinkle/usefull_gems.rb +10 -0
  39. data/lib/railslove/sprinkle.rb +3 -0
  40. data/lib/railslove/templates/deploy.rb +177 -0
  41. data/lib/railslove/templates/ferm.conf.erb +56 -0
  42. data/lib/railslove/templates/maintenance.html +0 -0
  43. data/lib/railslove/templates/memcache_init +31 -0
  44. data/lib/railslove/templates/monit_init +115 -0
  45. data/lib/railslove/templates/monitoring/apache.monit.erb +18 -0
  46. data/lib/railslove/templates/monitoring/job_worker.monit.erb +4 -0
  47. data/lib/railslove/templates/monitoring/memcached.monit.erb +4 -0
  48. data/lib/railslove/templates/monitoring/mysql.monit.erb +5 -0
  49. data/lib/railslove/templates/monitoring/nginx.monit.erb +4 -0
  50. data/lib/railslove/templates/monitoring/sphinx.monit.erb +0 -0
  51. data/lib/railslove/templates/monitoring/sshd.monit.erb +5 -0
  52. data/lib/railslove/templates/monitrc.erb +236 -0
  53. data/lib/railslove/templates/nginx.conf +0 -0
  54. data/lib/railslove/templates/nginx_init +65 -0
  55. data/lib/railslove/templates/passenger.conf +3 -0
  56. data/lib/railslove/templates/passenger.load +1 -0
  57. data/lib/railslove/templates/post_logrotate +1 -0
  58. data/lib/railslove/templates/safe.rb +42 -0
  59. data/lib/railslove/templates/sprinkle.rb +43 -0
  60. data/lib/railslove/templates/sprinkle_config.rb +2 -0
  61. data/lib/railslove/templates/sshd_config.erb +81 -0
  62. data/lib/railslove/templates/stack_readme.txt +4 -0
  63. data/lib/railslove/templates/vhost.erb +42 -0
  64. data/lib/railslove_deploy.rb +0 -0
  65. data/test/railslove_deploy_test.rb +7 -0
  66. data/test/test_helper.rb +7 -0
  67. metadata +132 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Michael Bumann
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,12 @@
1
+ railslove_deploy
2
+ ================
3
+
4
+ The Railslove deploy gem to setup a full ruby server stack. Includes Sprinkle setup scripts and Capistrano deployment recipes.
5
+
6
+ TODO: README
7
+
8
+
9
+ COPYRIGHT
10
+ =========
11
+
12
+ Copyright (c) 2008 Michael Bumann. See LICENSE for details.
data/TODO ADDED
@@ -0,0 +1,4 @@
1
+ * learn how to test capistrano tasks ans sprinkle packages
2
+
3
+ SPRINKLE
4
+ * Don't fail if memcache user already exists
data/bin/deployify ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ if ARGV.first == "install"
3
+ require "#{File.dirname(__FILE__)}/../lib/railslove/sprinkle"
4
+ Sprinkle::Script.sprinkle File.read("config/server/policy.rb"), "config/server/policy.rb"
5
+ else
6
+ require "fileutils"
7
+ folder = "."
8
+
9
+ `capify #{folder}`
10
+
11
+ FileUtils.mkdir_p("#{folder}/config/deploy")
12
+ FileUtils.mkdir_p("#{folder}/config/server")
13
+ FileUtils.mkdir_p("#{folder}/config/server/monit")
14
+
15
+ FileUtils.cp("#{File.dirname(__FILE__)}/../lib/railslove/templates/vhost.erb", "#{folder}/config/server/vhost.erb")
16
+ FileUtils.cp("#{File.dirname(__FILE__)}/../lib/railslove/templates/sprinkle.rb", "#{folder}/config/server/policy.rb")
17
+ FileUtils.cp("#{File.dirname(__FILE__)}/../lib/railslove/templates/sprinkle_config.rb", "#{folder}/config/server/config.rb")
18
+ FileUtils.cp("#{File.dirname(__FILE__)}/../lib/railslove/templates/deploy.rb", "#{folder}/config/deploy.rb")
19
+ FileUtils.cp("#{File.dirname(__FILE__)}/../lib/railslove/templates/safe.rb", "#{folder}/config/server/backup.rb")
20
+ FileUtils.cp("#{File.dirname(__FILE__)}/../lib/railslove/templates/maintenance.html", "#{folder}/config/server/maintenance.html")
21
+
22
+ FileUtils.cp("#{File.dirname(__FILE__)}/../lib/railslove/templates/monitrc.erb", "#{folder}/config/server/monitrc.erb")
23
+ #Dir.new("#{File.dirname(__FILE__)}/../lib/railslove/templates/monitoring").each do |monit_config|
24
+ # next unless File.file?("#{File.dirname(__FILE__)}/../lib/railslove/templates/monitoring/#{monit_config}")
25
+ # FileUtils.cp("#{File.dirname(__FILE__)}/../lib/railslove/templates/monitoring/#{monit_config}", "#{folder}/config/server/monit/#{monit_config}")
26
+ #end
27
+
28
+ FileUtils.cp("#{File.dirname(__FILE__)}/../lib/railslove/templates/ferm.conf.erb", "#{folder}/config/server/ferm.conf.erb")
29
+
30
+ puts "[Deployment files created]"
31
+ end
@@ -0,0 +1,45 @@
1
+ # from josh's (http://joshpeek.com/) slicehost dpeloyment: http://github.com/josh/slicehost/tree/master
2
+ namespace :apache do
3
+ desc "Restart Apache"
4
+ task :restart, :roles => :web do
5
+ sudo "/etc/init.d/apache2 restart"
6
+ end
7
+
8
+ desc "Start Apache"
9
+ task :start, :roles => :web do
10
+ sudo "/etc/init.d/apache2 start"
11
+ end
12
+
13
+ desc "Stop Apache"
14
+ task :stop, :roles => :web do
15
+ sudo "/etc/init.d/apache2 stop"
16
+ end
17
+
18
+ desc "Reload Apache"
19
+ task :reload, :roles => :web do
20
+ sudo "/etc/init.d/apache2 reload"
21
+ end
22
+
23
+ desc "Force reload Apache"
24
+ task :force_reload, :roles => :web do
25
+ sudo "/etc/init.d/apache2 force-reload"
26
+ end
27
+
28
+ desc "Disable Apache site"
29
+ task :disable_site, :roles => :web do
30
+ sudo "sudo a2dissite #{application}"
31
+ reload
32
+ end
33
+
34
+ desc "Enable Apache site"
35
+ task :enable_site, :roles => :web do
36
+ sudo "sudo a2ensite #{application}"
37
+ reload
38
+ end
39
+
40
+ desc "Upload Apache virtual host"
41
+ task :upload_vhost_config, :roles => :web do
42
+ put render("config/server/vhost.erb", binding), "/tmp/#{application}"
43
+ sudo "mv /tmp/#{application} /etc/apache2/sites-available/#{application}"
44
+ end
45
+ end
@@ -0,0 +1,8 @@
1
+ namespace :backup do
2
+
3
+ desc "Create a new backup using the astrails-safe config script from config/server/backup.rb"
4
+ task :run do
5
+ sudo "cd #{current_path}; /usr/local/ruby-enterprise/bin/astrails-safe -v #{current_path}/config/server/backup.rb"
6
+ end
7
+
8
+ end
@@ -0,0 +1,52 @@
1
+ namespace :db do
2
+ desc "Restarts MySQL database server"
3
+ task :restart, :roles => :db do
4
+ sudo "/etc/init.d/mysql restart"
5
+ end
6
+
7
+ desc "Starts MySQL database server"
8
+ task :start, :roles => :db do
9
+ sudo "/etc/init.d/mysql start"
10
+ end
11
+
12
+ desc "Stops MySQL database server"
13
+ task :stop, :roles => :db do
14
+ sudo "/etc/init.d/mysql stop"
15
+ end
16
+
17
+ desc "Export MySQL database"
18
+ task :export, :roles => :db do
19
+ database = Capistrano::CLI.ui.ask("Which database should we export: ")
20
+ sudo "mysqldump -u root -p #{database} > #{database}.sql"
21
+ end
22
+
23
+ desc "run the rake db:create task for the specific environment"
24
+ task :create, :roles => :db, :only => { :primary => true } do
25
+ rake("db:create")
26
+ end
27
+
28
+ desc "Upload the database yml from the /config/database.yml"
29
+ task :upload_config_yml, :roles => :db do
30
+ put open("config/database.yml").read, "#{shared_path}/database.yml"
31
+ end
32
+ desc "Symlink database.yml to shared path"
33
+ task :symlink_config_yml, :roles => :db do
34
+ run "ln -nfs #{shared_path}/database.yml #{release_path}/config/database.yml"
35
+ end
36
+
37
+ desc "create a backup of the mysql database save it to shared/backups/database and download it to /backups"
38
+ task :backup, :roles => :db, :only => { :primary => true } do
39
+ filename = "#{application}.dump.#{Time.now.to_i}.sql.bz2"
40
+ dir = backup_dir || "#{shared_dir}/backups"
41
+ file = "#{dir}/#{filename}"
42
+
43
+ on_rollback { delete file }
44
+
45
+ db = YAML::load(ERB.new(IO.read(File.join('config', 'database.yml'))).result)[rails_env]
46
+ run "mysqldump -u #{db['username']} --password=#{db['password']} #{db['database']} | bzip2 -c > #{file}" do |ch, stream, data|
47
+ puts data
48
+ end
49
+ `mkdir -p backups/`
50
+ get file, "backups/#{filename}"
51
+ end
52
+ end
@@ -0,0 +1,49 @@
1
+ namespace :deploy do
2
+
3
+ desc "restart"
4
+ task :restart, :roles => :web do
5
+ passenger.restart
6
+ end
7
+
8
+ desc "restart"
9
+ task :start, :roles => :web do
10
+ passenger.restart
11
+ end
12
+
13
+ desc "stop"
14
+ task :stop, :roles => :web do
15
+ end
16
+
17
+ namespace :web do
18
+
19
+ desc "disable application by adding a maintenance.html"
20
+ task :disable, :roles => :web do
21
+ on_rollback {
22
+ run "rm #{shared_path}/system/maintenance.html"
23
+ }
24
+ put render("config/server/maintenance.html", binding), "#{shared_path}/system/maintenance.html"
25
+ end
26
+
27
+ desc "enable "
28
+ task :enable, :roles => :web do
29
+ run "rm #{shared_path}/system/maintenance.html"
30
+ end
31
+
32
+ desc "Restart Apache"
33
+ task :restart, :roles => :web do
34
+ apache.restart
35
+ end
36
+
37
+ desc "Start Apache"
38
+ task :start, :roles => :web do
39
+ apache.start
40
+ end
41
+
42
+ desc "Stop Apache"
43
+ task :stop, :roles => :web do
44
+ apache.stop
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,12 @@
1
+ namespace :ferm do
2
+
3
+ desc "Configure IPtables using ferm"
4
+ task :configure do
5
+ put render("config/server/ferm.conf.erb", binding), "/tmp/ferm"
6
+ # make sure we have a /etc/ferm directory. we use echo 0 to ignore errors - for example if the folder already exists. ;)
7
+ sudo "mkdir /etc/ferm;echo 0"
8
+ sudo "mv /tmp/ferm /etc/ferm/ferm.conf"
9
+ sudo "/etc/init.d/ferm restart"
10
+ end
11
+
12
+ end
@@ -0,0 +1,50 @@
1
+ # THANKS: http://dev.animoto.com/articles/capistrano-gem-management
2
+ # ===========
3
+ # CAP GEMS
4
+ # Author: Stevie Clifton
5
+ # Somewhat hackish tasks for managing/installing remote gems
6
+ # that is loosely similar to "rake gems" in rails.
7
+ #
8
+ # Usage:
9
+ # > cap gems
10
+ # [ ] RubyInline >=3.7.0 (box1.yourdomain.com, box2.yourdomain.com)
11
+ # [I] image_science 1.1.3
12
+ #
13
+ # > cap gems:install
14
+ # ...lots of cap stuff echoed to screen...
15
+ # Successfully installed RubyInline >=3.7.0
16
+ #
17
+ # > cap gems
18
+ # [I] RubyInline >=3.7.0
19
+ # [I] image_science 1.1.3
20
+ #
21
+ # ===========
22
+
23
+ namespace :gems do
24
+
25
+ # prints status of all gems on remote system
26
+ task :default do
27
+ results = []
28
+ with_gem_dependencies do |dep, gem, version|
29
+ install_status = "[#{dep.pass? ? 'I' : ' '}]"
30
+ hosts = dep.hosts ? "(#{dep.hosts})" : ""
31
+ results << "#{install_status} #{gem.to_s} #{version} #{hosts}"
32
+ end
33
+ results.each {|r| puts r}
34
+ end
35
+
36
+ desc "installs gems listed in depend declarations"
37
+ task :install do
38
+ results = []
39
+ with_gem_dependencies do |dep, gem, version|
40
+ unless dep.pass?
41
+ sudo "gem install --no-ri --no-rdoc #{"--version '#{version}' " if version}#{gem}"
42
+ results << "Successfully installed #{gem} #{version}"
43
+ end
44
+ end
45
+ results.each {|r| puts r}
46
+ end
47
+ end
48
+
49
+
50
+ #====================
@@ -0,0 +1,35 @@
1
+ # run a rake task
2
+ def rake(task, args={})
3
+ rails_env = args[:rails_env] || fetch(:rails_env, "production")
4
+ rake_env = args[:rake_env] || fetch(:rake_env, "")
5
+ rake = fetch(:rake, "rake")
6
+ directory = args[:directory] || release_path
7
+ run "sh -c 'cd #{directory}; #{rake} #{task} RAILS_ENV=#{rails_env} #{rake_env}'"
8
+ end
9
+
10
+ def render(template,bind=binding)
11
+ ERB.new(open(template).read).result(bind)
12
+ end
13
+
14
+ # THANKS: http://dev.animoto.com/articles/capistrano-gem-management
15
+ # ===========
16
+ # CAP GEMS
17
+ # Author: Stevie Clifton
18
+ def gem_list
19
+ fetch(:dependencies, {})[:remote][:gem] rescue {}
20
+ end
21
+
22
+ # Passes the Deploy::Dependency after running a check, the gem,
23
+ # and version to a block. Deploy::Dependency does not have any
24
+ # internal awareness of which gem it is, which make doing this
25
+ # a PITA. Probably would be wiser to extend Deploy::Dependency
26
+ # to save the gem name and args so that we could query them directly
27
+ #
28
+ def with_gem_dependencies &block
29
+ Deploy::Dependencies.new(strategy.configuration) do |d|
30
+ gem_list.each do |gem, version|
31
+ dep = d.remote.gem(gem, version, {})
32
+ yield dep, gem, version
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,31 @@
1
+ # thanks to Arya Asemanfa (http://asemanfar.com/) for http://github.com/arya/capistrano_twitter
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'cgi'
5
+
6
+ namespace :hooks do
7
+ namespace :twitter do
8
+ desc "Update twitter status"
9
+ task :update do
10
+ url = URI.parse("http://twitter.com/statuses/update.json")
11
+
12
+ status = Capistrano::CLI.ui.ask("Update Twitter status to: (leave blank to skip)")
13
+ unless status.empty?
14
+
15
+ http = Net::HTTP.new(url.host, 80)
16
+ http.open_timeout = 20
17
+
18
+ headers = {'Authorization' => 'Basic ' + ["#{twitter_user}:#{twitter_password}"].pack('m').delete("\r\n")}
19
+
20
+ body = "status=#{CGI.escape(status)}"
21
+ begin
22
+ http.send(:post, url.path, body, headers)
23
+ rescue Timeout::Error => e
24
+ puts "Timeout after 20s: Seems like Twitter is down."
25
+ puts "Use \"cap twitter:update\" to update Twitter status later w/o deploying"
26
+ end
27
+ # if an exception is thrown, let them see it, they're a developer (most likely)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,17 @@
1
+ namespace :job_runner do
2
+ desc "Start your Job runner process"
3
+ task :start, :roles => :app do
4
+ run "cd #{release_path}; RAILS_ENV=#{fetch(:rails_env, "production")} #{fetch(:job_runner_script, "script/job_runner")} start"
5
+ end
6
+
7
+ desc "Stop your Job runner process"
8
+ task :stop, :roles => :app do
9
+ run "cd #{current_path}; RAILS_ENV=#{fetch(:rails_env, "production")} #{fetch(:job_runner_script, "script/job_runner")} stop"
10
+ end
11
+
12
+ desc "Restart your Job runner process"
13
+ task :restart, :roles => :app do
14
+ run "cd #{current_path}; RAILS_ENV=#{fetch(:rails_env, "production")} #{fetch(:job_runner_script, "script/job_runner")} restart"
15
+ end
16
+
17
+ end
@@ -0,0 +1,35 @@
1
+ namespace :logrotate do
2
+
3
+ desc "generate and save a logrotation config file"
4
+ task :configure do
5
+ filename = "/etc/logrotate.d/#{application}"
6
+ tmp_file = "/tmp/logrotate_#{application}"
7
+ put generate_logrotate_configuration, tmp_file
8
+ sudo "mv #{tmp_file} #{filename}"
9
+
10
+ end
11
+
12
+ desc "Force logrotate to run"
13
+ task :force do
14
+ sudo "logrotate -f /etc/logrotate.conf"
15
+ end
16
+
17
+ end
18
+
19
+ def generate_logrotate_configuration
20
+ config = []
21
+ fetch(:logrotate_options, []).each do |option|
22
+ if option.is_a?(Hash)
23
+ option.each do |key, value|
24
+ config << "#{key} #{value}"
25
+ end
26
+ else
27
+ config << option.to_s
28
+ end
29
+ end
30
+ %Q{
31
+ #{logrotate_directory}/*.log {
32
+ #{config.join("\n ")}
33
+ }
34
+ }
35
+ end
@@ -0,0 +1,21 @@
1
+ namespace :memcache do
2
+
3
+ desc "Start Memcached"
4
+ task :start, :roles => :cache do
5
+ sudo "/etc/init.d/memcached start"
6
+ #sudo "memcached -d -m #{memcache_memory} -l #{memcache_ip} -p #{memcache_port}"
7
+ end
8
+
9
+ desc "Stop Memcached using killall"
10
+ task :stop, :roles => :cache do
11
+ sudo "/etc/init.d/memcached stop"
12
+ #sudo "killall memcached; echo 0"
13
+ end
14
+
15
+ desc "Restart Memcached"
16
+ task :restart, :roles => :cache do
17
+ stop
18
+ start
19
+ end
20
+
21
+ end
@@ -0,0 +1,36 @@
1
+ desc "Connect to the Server(s) via SSH"
2
+ task :ssh do
3
+ #sorry I don't know how to make this nice and DRY... *shame on me*
4
+ don_ips = []
5
+ # if you enter an role - just connect to these servers
6
+ role = Capistrano::CLI.ui.ask("Role: (leave blank to connect to all server)")
7
+ if not role.empty?
8
+ roles[role.to_sym].each do |server|
9
+ if don_ips.include?(server.host)
10
+ puts("we've already hacked on #{server.host}")
11
+ next
12
+ end
13
+ puts server.host
14
+
15
+ system("ssh #{user}@#{server.host} -p #{ssh_options[:port]}")
16
+ don_ips << server.host
17
+ sleep 1
18
+ end
19
+ # else connect to all servers
20
+ else
21
+ roles.each do |environment,settings|
22
+ puts "----------------------"
23
+ puts "#{environment.to_s.capitalize}:"
24
+ settings.each do |server|
25
+ if don_ips.include?(server.host)
26
+ puts("we've already hacked on #{server.host}")
27
+ next
28
+ end
29
+ puts server.host
30
+ system("ssh #{user}@#{server.host} -p #{ssh_options[:port]}")
31
+ don_ips << server.host
32
+ sleep 1
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,32 @@
1
+ namespace :monit do
2
+
3
+ desc "Setup the monitrc and enable monit on the server"
4
+ task :setup do
5
+ put render("config/server/monitrc.erb", binding), "/tmp/monitrc"
6
+ sudo "mv /tmp/monitrc /etc/monit/monitrc"
7
+ sudo "chown -R root:root /etc/monit"
8
+ sudo "echo 'startup=1' | sudo tee -a /etc/default/monit"
9
+ end
10
+
11
+ desc "Upload global monit configurations. This task allows you to install system-wide monit configuration files"
12
+ task :upload_global do
13
+ Dir.new("config/server/monit").each do |file|
14
+ next unless File.file?("config/server/monit/#{file}")
15
+ file_name = file.gsub('.erb', "")
16
+ put render("config/server/monit/#{file}", binding), "/tmp/#{file_name}"
17
+ sudo "mv /tmp/#{file_name} /etc/monit.d/#{file_name}"
18
+ sudo "chown root:root /etc/monit.d/#{file_name}"
19
+ end
20
+ end
21
+
22
+ desc "Start monit on the server"
23
+ task :start do
24
+ sudo "/etc/init.d/monit start"
25
+ end
26
+
27
+ desc "Stop monit on the server"
28
+ task :stop do
29
+ sudo "/etc/init.d/monit stop"
30
+ end
31
+
32
+ end
@@ -0,0 +1,25 @@
1
+ namespace :passenger do
2
+
3
+ desc "Restart Passenger"
4
+ task :restart, :roles => :app do
5
+ run "touch #{current_path}/tmp/restart.txt"
6
+ end
7
+
8
+
9
+ namespace :info do
10
+ desc "Display the passenger-memory-stats"
11
+ task :memory, :roles => :app do
12
+ run "passenger-memory-stats" do |channel, stream, data|
13
+ puts data
14
+ end
15
+ end
16
+
17
+ desc "Display general Passernger status passernger-status"
18
+ task :general, :roles => :app do
19
+ run "passenger-status" do |channel, stream, data|
20
+ puts data
21
+ end
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,16 @@
1
+ namespace :shared do
2
+ task :setup do
3
+ fetch(:shared_files,{}).each do |source,target|
4
+ path = File.directory?(source) ? File.dirname(target) : target
5
+ run "mkdir -p #{shared_path}/#{path}"
6
+ end
7
+ end
8
+
9
+ task :symlink do
10
+ fetch(:shared_files,{}).each do |source,target|
11
+ run "rm -rf #{source}"
12
+ run "ln -s #{shared_path}/#{target} #{release_path}/#{source}"
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,37 @@
1
+ namespace :thinking_sphinx do
2
+
3
+ desc "Configure Thinkig Sphinx"
4
+ task :config, :roles => :app do
5
+ run "cd #{current_path}; rake ts:config RAILS_ENV=#{fetch(:rails_env, "production")}"
6
+ end
7
+
8
+ desc "Start Thinkig Sphinx"
9
+ task :start, :roles => :app do
10
+ run "cd #{current_path}; rake ts:start RAILS_ENV=#{fetch(:rails_env, "production")}"
11
+ end
12
+
13
+ desc "Stop Thinkig Sphinx"
14
+ task :stop, :roles => :app do
15
+ run "cd #{current_path}; rake ts:stop RAILS_ENV=#{fetch(:rails_env, "production")};echo 0"
16
+ end
17
+
18
+ desc "Run Thinkig Sphinx indexing"
19
+ task :index, :roles => :app do
20
+ run "cd #{current_path}; rake ts:index RAILS_ENV=#{fetch(:rails_env, "production")}"
21
+ end
22
+
23
+ desc "Bootstrap Thinkig Sphinx"
24
+ task :bootstrap, :roles => :app do
25
+ run "cd #{current_path}; rake ts:stop RAILS_ENV=#{fetch(:rails_env, "production")}"
26
+ run "cd #{current_path}; rake ts:config RAILS_ENV=#{fetch(:rails_env, "production")}"
27
+ run "cd #{current_path}; rake ts:index RAILS_ENV=#{fetch(:rails_env, "production")}"
28
+ run "cd #{current_path}; rake ts:start RAILS_ENV=#{fetch(:rails_env, "production")}"
29
+ end
30
+
31
+ desc "Symlink Sphinx index DB"
32
+ task :symlink, :roles => :app do
33
+ run "mkdir -p #{shared_path}/db/sphinx"
34
+ run "rm -fr #{release_path}/db/sphinx && ln -nfs #{shared_path}/db/sphinx #{release_path}/db/sphinx"
35
+ end
36
+
37
+ end
@@ -0,0 +1,26 @@
1
+ namespace :workling do
2
+
3
+ desc "Restart Workling Client"
4
+ task :restart, :roles => :app do
5
+ run "cd #{current_path}; RAILS_ENV=#{fetch(:rails_env, "production")} script/workling_client stop"
6
+ run "cd #{current_path}; RAILS_ENV=#{fetch(:rails_env, "production")} script/workling_client start"
7
+ end
8
+
9
+ desc "Start Workling Client"
10
+ task :start, :roles => :app do
11
+ run "cd #{current_path}; RAILS_ENV=#{fetch(:rails_env, "production")} script/workling_client start"
12
+ end
13
+
14
+ desc "Stop Workling Client"
15
+ task :stop, :roles => :app do
16
+ run "cd #{current_path}; RAILS_ENV=#{fetch(:rails_env, "production")} script/workling_client stop; echo 0"
17
+ end
18
+
19
+ end
20
+
21
+ namespace :starling do
22
+ desc "Start Starling"
23
+ task :start do
24
+ run "sudo starling -d -p #{fetch(:starling_port, "15151")}"
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ # cap gems helper methods
2
+ require "capistrano"
3
+ require 'capistrano/recipes/deploy/dependencies'
4
+
5
+ Dir["#{File.dirname(__FILE__)}/recipes/*.rb"].each { |recipe|
6
+ Capistrano::Configuration.instance(true).load recipe
7
+ }
@@ -0,0 +1,45 @@
1
+ package :apache, :provides => :webserver do
2
+ description 'Apache2 web server.'
3
+ apt 'apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1' do
4
+ post :install, 'a2enmod rewrite'
5
+ post :install, 'a2enmod deflate'
6
+ post :install, 'a2enmod expires'
7
+ post :install, 'a2enmod headers'
8
+ post :install, "a2dissite 000-default"
9
+
10
+ # configure /server-status module
11
+ ["<Location /server-status>","SetHandler server-status","Order deny,allow", "Deny from all", "Allow from 127.0.0.1", "</Location>"].each do |line|
12
+ post :install, "echo '#{line}' | sudo tee -a /etc/apache2/status.conf"
13
+ end
14
+ end
15
+
16
+ verify do
17
+ has_process 'apache2'
18
+ end
19
+
20
+ requires :essentials, :apache2_prefork_dev
21
+ end
22
+
23
+ package :apache_xsendfile do
24
+ description "installs the Apache X-Sendfile module"
25
+ source "http://tn123.ath.cx/mod_xsendfile/mod_xsendfile-0.9.tar.gz" do
26
+ # apxs throws an error becaus it can not activate the module. we just ignore that
27
+ # apxs error:"Error: Activation failed for custom /etc/apache2/httpd.conf file.."
28
+ custom_install 'apxs2 -cia mod_xsendfile.c;echo 0'
29
+ post :install, "touch /etc/apache2/mods-available/xsendfile.load"
30
+ post :install, 'echo "LoadModule xsendfile_module /usr/lib/apache2/modules/mod_xsendfile.so" > /etc/apache2/mods-available/xsendfile.load'
31
+ post :install, "a2enmod xsendfile"
32
+ end
33
+
34
+ verify do
35
+ has_file '/usr/lib/apache2/modules/mod_xsendfile.so'
36
+ has_file '/etc/apache2/mods-available/xsendfile.load'
37
+ end
38
+ requires :apache
39
+ end
40
+
41
+
42
+ package :apache2_prefork_dev do
43
+ description 'A dependency required by some packages.'
44
+ apt 'apache2-prefork-dev'
45
+ end