Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Customized runit tasks

  • Loading branch information...
commit e6e055b6aa3513b8f2afa7db1a478ea2fd2b00f9 1 parent f892696
@topfunky topfunky authored
View
2  README.txt
@@ -7,7 +7,7 @@ PeepServer plugin for Capistrano.
Provides Capistrano deployment tasks for setting up and maintaining a CentOS server such those installed at RailsMachine (http://railsmachine.com).
-Customize for your own situation.
+Some are highly customized for my current server (nginx, runit, thin, ruby-enterprise). You should customize it for your own situation.
Use at your own risk.
View
29 recipes/peepserver.rb
@@ -31,6 +31,13 @@ def run_and_return(cmd)
end
return output.to_s
end
+
+ ##
+ # Return the path to a file inside the Peepserver templates directory.
+
+ def local_template_file_path(sub_path)
+ File.dirname(__FILE__) + "/templates/#{sub_path}"
+ end
end
@@ -98,9 +105,10 @@ def run_and_return(cmd)
# TODO
# * Uninstall httpd: chkconfig --del httpd
- runit
git
nginx
+ runit
+ beanstalkd
memcached
munin
httperf
@@ -184,9 +192,7 @@ def run_and_return(cmd)
desc "Install nginx"
task :nginx do
-
- result = File.read(File.dirname(__FILE__) + "/templates/install-nginx.sh")
- put result, "src/install-nginx.sh"
+ upload local_template_file_path("install-nginx.sh"), "src/install-nginx.sh", :mode => 0755
cmd = [
"cd src",
@@ -196,11 +202,10 @@ def run_and_return(cmd)
run cmd
end
- desc "Install runit"
+ desc "Install runit task manager"
task :runit do
%w(install-runit.sh install-runit-for-user.sh).each do |filename|
- result = File.read(File.dirname(__FILE__) + "/templates/#{filename}")
- put result, "src/#{filename}", :mode => 0755
+ upload local_template_file_path(filename), "src/#{filename}", :mode => 0755
end
sudo "src/install-runit.sh"
@@ -217,8 +222,7 @@ def run_and_return(cmd)
sudo "mv ~/src/memcached-i386.conf /etc/ld.so.conf.d/memcached-i386.conf"
sudo "/sbin/ldconfig"
- result = File.read(File.dirname(__FILE__) + "/templates/install-memcached-linux.sh")
- put result, "src/install-memcached-linux.sh"
+ upload local_template_file_path("install-memcached-linux.sh"), "src/install-memcached-linux.sh", :mode => 0755
cmd = [
"cd src",
@@ -269,8 +273,7 @@ def run_and_return(cmd)
# Reset
sudo "rm -f /etc/munin/plugins/*"
- # Upload
- put File.read(File.dirname(__FILE__) + "/templates/memcached_"), "/tmp/memcached_"
+ upload local_template_file_path("memcached_"), "/tmp/memcached_"
sudo "cp /tmp/memcached_ /usr/share/munin/plugins/memcached_"
sudo "chmod 755 /usr/share/munin/plugins/memcached_"
@@ -357,7 +360,7 @@ def run_and_return(cmd)
desc "Install beanstalk in-memory queue"
- task :beanstalk do
+ task :beanstalkd do
# TODO Bail unless make 3.81 is installed
cmd = [
"cd src",
@@ -385,3 +388,5 @@ def run_and_return(cmd)
end
end
+
+# TODO sudo gem list | ruby -n -e 'puts $1 if ($_ =~ /(\S+) \(/)' | xargs sudo /opt/ruby-enterprise/bin/gem install
View
60 recipes/peepserver_runit.rb
@@ -0,0 +1,60 @@
+
+class Capistrano::Configuration
+
+ ##
+ # Path to the directory with the rails-runit/service directory.
+
+ def shared_runit_service_path
+ File.join(shared_path, "rails-runit", "service")
+ end
+
+ def install_runit_service(service_name)
+ single_service_path = File.join(shared_runit_service_path, service_name)
+ run "mkdir -p #{single_service_path}"
+ upload local_template_file_path("runit/#{service_name}"), "#{single_service_path}/run", :mode => 0755
+ run "ln -s #{single_service_path} ~/service/"
+ end
+
+end
+
+namespace :peepcode do
+
+ namespace :runit do
+
+ desc "Install runit tasks for the current Rails app, using thin and Ruby enterprise.\nDo this before other peepcode:runit tasks."
+ task :rails do
+ cmd = [
+ "cd #{shared_path}",
+ "git clone git://github.com/purcell/rails-runit.git",
+ "cd rails-runit",
+ "ln -s /opt/ruby-enterprise/bin/thin thin",
+ "ln -s #{current_path} app"
+ ].join(" && ")
+ run cmd
+
+ # Add runit task for all thin ports
+ (mongrel_port...(mongrel_port + mongrel_servers)).each do |port_number|
+ run "cd #{shared_path}/rails-runit && ./add-thin #{port_number}"
+ run "ln -s #{shared_runit_service_path}/thin-#{port_number} ~/service"
+ end
+ end
+
+
+ desc "Install runit task for beanstalk"
+ task :beanstalkd do
+ install_runit_service("beanstalkd")
+ end
+
+ desc "Install runit task for memcache"
+ task :memcached do
+ install_runit_service("memcached")
+ end
+
+ desc "Dev task"
+ task :reset do
+ run "rm -rf #{shared_path}/rails-runit"
+ end
+
+ end
+
+end
View
11 recipes/templates/nginx.logrotate.d
@@ -0,0 +1,11 @@
+# TODO Make erb and use app variables
+/var/log/nginx*.log /var/www/apps/nubyonrails.com/shared/log/nginx.*.log {
+ daily
+ rotate 7
+ compress
+ missingok
+ sharedscripts
+ postrotate
+ /etc/init.d/nginx relog
+ endscript
+}
View
4 recipes/templates/runit/beanstalkd
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+exec 2>&1
+exec /usr/local/bin/beanstalkd
View
4 recipes/templates/runit/memcached
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+exec 2>&1
+exec /usr/local/bin/memcached -m 16 -l 127.0.0.1 -p 11211
Please sign in to comment.
Something went wrong with that request. Please try again.