forked from rubber/rubber
/
deploy-apache.rb
70 lines (53 loc) · 2.1 KB
/
deploy-apache.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
namespace :rubber do
namespace :apache do
rubber.allow_optional_tasks(self)
after "rubber:install_packages", "rubber:apache:install"
task :install, :roles => :apache do
rubber.sudo_script 'install_apache', <<-ENDSCRIPT
a2dissite default
# TODO: remove this once 12.04 is fixed
# https://bugs.launchpad.net/ubuntu/+source/mod-proxy-html/+bug/964397
if [[ ! -f /usr/lib/libxml2.so.2 ]]; then
ln -sf /usr/lib/x86_64-linux-gnu/libxml2.so.2 /usr/lib/libxml2.so.2
fi
ENDSCRIPT
end
after "rubber:bootstrap", "rubber:apache:bootstrap"
task :bootstrap, :roles => :apache do
exists = capture("grep 'empty ports file' /etc/apache2/ports.conf || true")
if exists.strip.size == 0
rubber.update_code_for_bootstrap
rubber.run_config(:file => "role/apache", :force => true, :deploy_path => release_path)
end
end
# serial_task can only be called after roles defined - not normally a problem, but
# rubber auto-roles don't get defined till after all tasks are defined
on :load do
rubber.serial_task self, :serial_restart, :roles => [:app, :apache] do
rsudo "service apache2 stop; service apache2 start"
end
rubber.serial_task self, :serial_reload, :roles => [:app, :apache] do
rsudo "if ! ps ax | grep -v grep | grep -c apache2 &> /dev/null; then service apache2 start; else service apache2 reload; fi"
end
end
before "deploy:stop", "rubber:apache:stop"
after "deploy:start", "rubber:apache:start"
after "deploy:restart", "rubber:apache:reload"
desc "Stops the apache web server"
task :stop, :roles => :apache do
rsudo "service apache2 stop || true"
end
desc "Starts the apache web server"
task :start, :roles => :apache do
rsudo "service apache2 start"
end
desc "Restarts the apache web server"
task :restart, :roles => :apache do
serial_restart
end
desc "Reloads the apache web server"
task :reload, :roles => :apache do
serial_reload
end
end
end