Skip to content

Commit

Permalink
Added/merged god, nginx, thin, and maintenance tasks. (github cluster…
Browse files Browse the repository at this point in the history
…fuck)

[git-p4: depot-paths = "//src/vlad/dev/": change = 4670]
  • Loading branch information
zenspider committed Mar 3, 2009
1 parent ee0849a commit 49dd1ee
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 0 deletions.
1 change: 1 addition & 0 deletions History.txt
Expand Up @@ -6,6 +6,7 @@
* Added merb support. (Jamie Macey)
* remote_task now supports arguments and supplies task like rake
0.8. (Daniel P. Kionka)
* Added/merged god, nginx, thin, and maintenance tasks. (github clusterfuck)

* N minor enhancements:

Expand Down
23 changes: 23 additions & 0 deletions lib/vlad/god.rb
@@ -0,0 +1,23 @@
require 'vlad'

namespace :vlad do
## God module for merb app server

desc "Prepares application servers for deployment.".cleanup

remote_task :setup_app, :roles => :app do

end

desc "Restart the app servers"

remote_task :start_app, :roles => :app do
run "god restart #{cluster_name}"
end

desc "Stop the app servers"

remote_task :stop_app, :roles => :app do
run "god stop #{cluster_name}"
end
end
48 changes: 48 additions & 0 deletions lib/vlad/nginx.rb
@@ -0,0 +1,48 @@
require 'vlad'

namespace :vlad do
##
# Nginx web server on Gentoo/Debian init.d systems FIX

set :web_command, "/etc/init.d/nginx"

remote_task :setup_app, :roles => :web do
config_file = "/etc/nginx/vhosts/#{application}_#{environment}.conf"
raise "not yet... must review this code"
run [ "sudo test -e #{config_file} || ",
"sudo sh -c \"ruby ",
" /etc/sliceconfig/install/interactive/nginx_config.rb ",
"'#{app_domain}' '#{application}' '#{environment}' ",
"'#{app_port}' '#{app_servers}' #{only_www ? 1 : 0} ",
"> #{config_file}\""
].join(" ")
end

desc "(Re)Start the web servers"

remote_task :start_web, :roles => :web do
run "#{web_command} restart"
# TODO: run %Q(sudo #{web_command} configtest && sudo #{web_command} reload)
end

desc "Stop the web servers"

remote_task :stop_web, :roles => :web do
run "#{web_command} stop"
end

##
# Everything HTTP.

desc "(Re)Start the web and app servers"

remote_task :start do
Rake::Task['vlad:start_app'].invoke
Rake::Task['vlad:start_web'].invoke
end

remote_task :stop do
Rake::Task['vlad:stop_app'].invoke
Rake::Task['vlad:stop_web'].invoke
end
end
63 changes: 63 additions & 0 deletions lib/vlad/thin.rb
@@ -0,0 +1,63 @@
# $GEM_HOME/gems/vlad-1.2.0/lib/vlad/thin.rb
# Thin tasks for Vlad the Deployer
# By cnantais
require 'vlad'

namespace :vlad do
##
# Thin app server

set :thin_address, "127.0.0.1"
set :thin_command, 'thin'
set(:thin_conf) { "#{shared_path}/thin_cluster.conf" }
set :thin_environment, "production"
set :thin_group, nil
set :thin_log_file, nil
set :thin_pid_file, nil
set :thin_port, nil
set :thin_socket, "/tmp/thin.sock"
set :thin_prefix, nil
set :thin_servers, 2
set :thin_user, nil
set :thin_rackup, nil

desc "Prepares application servers for deployment. thin
configuration is set via the thin_* variables.".cleanup

remote_task :setup_app, :roles => :app do
cmd = [
"#{thin_command} config",
"-s #{thin_servers}",
"-S #{thin_socket}",
"-e #{thin_environment}",
"-c #{current_path}",
"-C #{thin_conf}",
("-a #{thin_address}" if thin_address)
("-R #{thin_rackup}" if thin_rackup )
("-P #{thin_pid_file}" if thin_pid_file),
("-l #{thin_log_file}" if thin_log_file),
("--user #{thin_user}" if thin_user),
("--group #{thin_group}" if thin_group),
("--prefix #{thin_prefix}" if thin_prefix),
("-p #{thin_port}" if thin_port),
].compact.join ' '

run cmd
end

def thin(cmd) # :nodoc:
"#{thin_command} #{cmd} -C #{thin_conf}"
end

desc "Restart the app servers"

remote_task :start_app, :roles => :app do
run thin("restart -s #{thin_servers}")
end

desc "Stop the app servers"

remote_task :stop_app, :roles => :app do
run thin("stop -s #{thin_servers}")
end
end
12 changes: 12 additions & 0 deletions lib/vlad/web.rb
@@ -0,0 +1,12 @@
require 'vlad'

namespace :vlad do
namespace :web do
remote_task :enable, :roles => [:web] do
run "if [ -f #{shared_path}/system/maintenance.html ]; then rm -f #{shared_path}/system/maintenance.html; fi"
end
remote_task :disable, :roles => [:web] do
run "cp -f #{shared_path}/config/maintenance.html #{shared_path}/system/"
end
end
end

0 comments on commit 49dd1ee

Please sign in to comment.