-
Notifications
You must be signed in to change notification settings - Fork 5
/
MagentoLTS-Recipe.rb
129 lines (110 loc) · 5.19 KB
/
MagentoLTS-Recipe.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
require 'nokogiri'
_cset (:app_symlinks) { ["/media", "/var", "/sitemaps"] }
_cset (:app_shared_dirs) { ["/app/etc", "/sitemaps", "/media", "/var"] }
_cset (:app_shared_files) { ["/app/etc/local.xml"] }
_cset (:app_path) { "" } # Path of the Magento app from the root of the project
_cset (:copy_exclude) { [] }
set :copy_exclude, copy_exclude.concat(['/.git', '/config', '/downloader', '/.gitignore', '/.htaccess.sample'])
def get_database_credentials
config_xml = capture "cat #{current_release}#{app_path}/app/etc/local.xml"
config_xml_file = Nokogiri::XML(config_xml)
db_credentials = Hash.new
["host", "username", "password", "dbname"].each do |credential|
db_credentials[credential] = config_xml_file.xpath("//config//global//resources//default_setup//#{credential}/text()").text
end
db_credentials
end
namespace :mage do
desc <<-DESC
Prepares one or more servers for deployment of Magento. Before you can use any \
of the Capistrano deployment tasks with your project, you will need to \
make sure all of your servers have been prepared with `cap deploy:setup'. When \
you add a new server to your cluster, you can easily run the setup task \
on just that server by specifying the HOSTS environment variable:
$ cap HOSTS=new.server.com mage:setup
It is safe to run this task on servers that have already been set up; it \
will not destroy any deployed revisions or data.
DESC
task :setup, :roles => :web, :except => { :no_release => true } do
if app_shared_dirs
app_shared_dirs.each { |link| run "#{try_sudo} mkdir -p #{shared_path}#{app_path}#{link} && #{try_sudo} chmod 777 #{shared_path}#{app_path}#{link}"}
end
if app_shared_files
app_shared_files.each { |link| run "#{try_sudo} touch #{shared_path}#{app_path}#{link} && #{try_sudo} chmod 777 #{shared_path}#{app_path}#{link}" }
end
end
desc <<-DESC
Touches up the released code. This is called by update_code \
after the basic deploy finishes.
Any directories deployed from the SCM are first removed and then replaced with \
symlinks to the same directories within the shared location.
DESC
task :finalize_update, :roles => :web, :except => { :no_release => true } do
run "chmod -R g+w #{latest_release}#{app_path}" if fetch(:group_writable, true)
if app_symlinks
# Remove the contents of the shared directories if they were deployed from SCM
app_symlinks.each { |link| run "#{try_sudo} rm -rf #{latest_release}#{app_path}#{link}" }
# Add symlinks the directoris in the shared location
app_symlinks.each { |link| run "ln -nfs #{shared_path}#{app_path}#{link} #{latest_release}#{app_path}#{link}" }
end
if app_shared_files
# Remove the contents of the shared directories if they were deployed from SCM
app_shared_files.each { |link| run "#{try_sudo} rm -rf #{latest_release}#{app_path}#{link}" }
# Add symlinks the directoris in the shared location
app_shared_files.each { |link| run "ln -s #{shared_path}#{app_path}#{link} #{latest_release}#{app_path}#{link}" }
end
end
desc <<-DESC
Clear the Magento Cache
DESC
task :cc, :roles => :web do
run "cd #{current_path}#{app_path} && rm -rf var/cache/*"
end
desc <<-DESC
Disable the Magento install by creating the maintenance.flag in the web root.
DESC
task :disable, :roles => :web do
run "cd #{current_path}#{app_path} && touch maintenance.flag"
end
desc <<-DESC
Enable the Magento stores by removing the maintenance.flag in the web root.
DESC
task :enable, :roles => :web do
run "cd #{current_path}#{app_path} && rm -f maintenance.flag"
end
desc <<-DESC
Run the Magento indexer
DESC
task :indexer, :roles => :app do
run "cd #{current_path}#{app_path}/shell && php -f indexer.php -- reindexall"
end
desc <<-DESC
Clean the Magento logs
DESC
task :clean_logs, :roles => :web do
run "cd #{current_path}#{app_path}/shell && php -f log.php -- clean"
end
# From https://github.com/augustash/capistrano-ash/
desc "Watch Magento system log"
task :watch_logs, :roles => :web, :except => { :no_release => true } do
run "tail -f #{shared_path}#{app_path}/var/log/system.log" do |channel, stream, data|
puts # for an extra line break before the host name
puts "#{channel[:host]}: #{data}"
break if stream == :err
end
end
desc "Watch Magento exception log"
task :watch_exceptions, :roles => :web, :except => { :no_release => true } do
run "tail -f #{shared_path}#{app_path}/var/log/exception.log" do |channel, stream, data|
puts # for an extra line break before the host name
puts "#{channel[:host]}: #{data}"
break if stream == :err
end
end
desc "Lauch Magento migrations / setups"
task :migrate, roles => :app do
run "cd #{current_path}#{app_path}/ && php -f index.php"
end
end
after 'deploy:setup', 'mage:setup'
after 'deploy:finalize_update', 'mage:finalize_update'