capistrano-technogate 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/..gemspec +20 -0
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/capistrano-technogate.gemspec +22 -0
- data/lib/capistrano/technogate/base.rb +95 -0
- data/lib/capistrano/technogate/configurations.rb +31 -0
- data/lib/capistrano/technogate/contao.rb +191 -0
- data/lib/capistrano/technogate/god.rb +30 -0
- data/lib/capistrano/technogate/mysql.rb +132 -0
- data/lib/capistrano/technogate/rails.rb +40 -0
- data/lib/capistrano/technogate/unicorn.rb +27 -0
- data/lib/capistrano/technogate/version.rb +11 -0
- metadata +71 -0
data/..gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "./version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "."
|
7
|
+
s.version = .::VERSION
|
8
|
+
s.authors = ["Wael Nasreddine"]
|
9
|
+
s.email = ["wael.nasreddine@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{TODO: Write a gem summary}
|
12
|
+
s.description = %q{TODO: Write a gem description}
|
13
|
+
|
14
|
+
s.rubyforge_project = "."
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "capistrano/technogate/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "capistrano-technogate"
|
7
|
+
s.version = Capistrano::Technogate::Version::STRING.dup
|
8
|
+
s.authors = ["Wael Nasreddine"]
|
9
|
+
s.email = ["wael.nasreddine@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/TechnoGate/capistrano-technogate"
|
11
|
+
s.summary = %q{This gem provides some receipts for helping me in my every-day development}
|
12
|
+
s.description = s.summary
|
13
|
+
|
14
|
+
s.rubyforge_project = "capistrano-technogate"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency('capistrano', '>=1.0.0')
|
22
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
require 'highline'
|
3
|
+
|
4
|
+
# Verify that Capistrano is version 2
|
5
|
+
unless Capistrano::Configuration.respond_to?(:instance)
|
6
|
+
abort "This extension requires Capistrano 2"
|
7
|
+
end
|
8
|
+
|
9
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
10
|
+
# Taken from Stackoverflow
|
11
|
+
# http://stackoverflow.com/questions/1661586/how-can-you-check-to-see-if-a-file-exists-on-the-remote-server-in-capistrano
|
12
|
+
def remote_file_exists?(full_path)
|
13
|
+
'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
|
14
|
+
end
|
15
|
+
|
16
|
+
def link_file(source_file, destination_file)
|
17
|
+
if remote_file_exists?(source_file)
|
18
|
+
run "#{try_sudo} ln -nsf #{source_file} #{destination_file}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def link_config_file(config_file, config_path = nil)
|
23
|
+
config_path ||= "#{File.join release_path, 'config'}"
|
24
|
+
link_file("#{File.join shared_path, 'config', config_file}", "#{File.join config_path, config_file}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def blank?(var)
|
28
|
+
var.nil? or var == false or var.empty?
|
29
|
+
end
|
30
|
+
|
31
|
+
def ask(what)
|
32
|
+
ui = HighLine.new
|
33
|
+
ui.ask("#{what}? ") do |q|
|
34
|
+
q.overwrite = false
|
35
|
+
q.default = 'No'
|
36
|
+
q.validate = /(y(es)?)|(no?)|(a(bort)?|\n)/i
|
37
|
+
q.responses[:not_valid] = what
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
namespace :deploy do
|
42
|
+
if defined?(skip_deploy_restart) and skip_deploy_restart
|
43
|
+
task :restart do
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
if defined?(finalize_update) and finalize_update
|
48
|
+
task :finalize_update do
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "Check if the branch is ready"
|
53
|
+
task :check_if_branch_is_ready, :roles => :web do
|
54
|
+
unless `git rev-parse #{branch}` == `git rev-parse origin/#{branch}`
|
55
|
+
puts "ERROR: #{branch} is not the same as origin/#{branch}"
|
56
|
+
puts "Run `git push` to sync changes."
|
57
|
+
exit
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
desc "Check if this revision has already been deployed."
|
62
|
+
task :check_revision, :roles => :web do
|
63
|
+
if remote_file_exists?("#{deploy_to}/current/REVISION")
|
64
|
+
if `git rev-parse #{branch}`.strip == capture("cat #{deploy_to}/current/REVISION").strip
|
65
|
+
response = ask("The verison you are trying to deploy is already deployed, should I continue (Yes, [No], Abort)")
|
66
|
+
if response =~ /(no?)|(a(bort)?|\n)/i
|
67
|
+
exit
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
desc "Check if the remote is ready, should we run cap deploy:setup?"
|
74
|
+
task :check_if_remote_ready, :roles => :web do
|
75
|
+
unless remote_file_exists?("#{shared_path}")
|
76
|
+
puts "ERROR: The project is not ready for deployment."
|
77
|
+
puts "please run `cap deploy:setup"
|
78
|
+
exit
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
namespace :bundle do
|
84
|
+
if :skip_bundle_install
|
85
|
+
task :install do
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Dependencies
|
91
|
+
before "deploy", "deploy:check_if_remote_ready"
|
92
|
+
after "deploy:check_if_remote_ready", "deploy:check_if_branch_is_ready"
|
93
|
+
after "deploy:check_if_branch_is_ready", "deploy:check_revision"
|
94
|
+
after "deploy", "deploy:cleanup" # keeps only last 5 releases
|
95
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
|
3
|
+
# Verify that Capistrano is version 2
|
4
|
+
unless Capistrano::Configuration.respond_to?(:instance)
|
5
|
+
abort "This extension requires Capistrano 2"
|
6
|
+
end
|
7
|
+
|
8
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
9
|
+
unless ENV['DEPLOY'].nil? or ENV['DEPLOY'].empty?
|
10
|
+
# Set the operation were doing
|
11
|
+
set :deploying, ENV['DEPLOY'].to_sym
|
12
|
+
|
13
|
+
if configurations[deploying].nil?
|
14
|
+
puts "ERROR: #{ENV['DEPLOY']} has not been configured yet, please open up 'config/deploy.rb' and configure it"
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
|
18
|
+
# Parse configurations
|
19
|
+
configurations[deploying].each { |config, value| set config, value }
|
20
|
+
|
21
|
+
# Set the current path
|
22
|
+
set :current_path, "#{File.join deploy_to, 'current'}"
|
23
|
+
end
|
24
|
+
|
25
|
+
# Some helpers
|
26
|
+
if defined?(skip_bundle_install) and skip_bundle_install
|
27
|
+
set :try_bundle_exec, ""
|
28
|
+
else
|
29
|
+
set :try_bundle_exec, "bundle exec"
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
|
3
|
+
# Verify that Capistrano is version 2
|
4
|
+
unless Capistrano::Configuration.respond_to?(:instance)
|
5
|
+
abort "This extension requires Capistrano 2"
|
6
|
+
end
|
7
|
+
|
8
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
9
|
+
|
10
|
+
namespace :contao do
|
11
|
+
task :setup, :roles => :web do
|
12
|
+
run <<-CMD
|
13
|
+
#{try_sudo} mkdir -p #{shared_path}/log &&
|
14
|
+
#{try_sudo} mkdir -p #{shared_path}/contenu &&
|
15
|
+
#{try_sudo} mkdir -p #{shared_path}/contenu/images &&
|
16
|
+
#{try_sudo} mkdir -p #{shared_path}/contenu/videos &&
|
17
|
+
#{try_sudo} mkdir -p #{shared_path}/contenu/son &&
|
18
|
+
#{try_sudo} mkdir -p #{shared_path}/contenu/pdfs
|
19
|
+
CMD
|
20
|
+
end
|
21
|
+
|
22
|
+
task :setup_localconfig, :roles => :web do
|
23
|
+
mysql_credentials = TechnoGate::Contao.instance.mysql_credentials
|
24
|
+
mysql_db_name = TechnoGate::Contao.instance.mysql_database_name
|
25
|
+
localconfig = File.read("public/system/config/localconfig.php.sample")
|
26
|
+
|
27
|
+
# Add MySQL credentials
|
28
|
+
unless blank?(localconfig) or blank?(mysql_credentials)
|
29
|
+
localconfig.gsub!(/#DB_USER#/, mysql_credentials[:user])
|
30
|
+
localconfig.gsub!(/#DB_PASS#/, mysql_credentials[:pass])
|
31
|
+
localconfig.gsub!(/#DB_NAME#/, mysql_db_name)
|
32
|
+
end
|
33
|
+
|
34
|
+
# localconfig
|
35
|
+
if blank?(mysql_credentials)
|
36
|
+
puts "WARNING: The mysql credential file can't be found, localconfig has just been copied from the sample file"
|
37
|
+
end
|
38
|
+
|
39
|
+
put localconfig, "#{shared_path}/localconfig.php"
|
40
|
+
end
|
41
|
+
|
42
|
+
task :setup_db, :roles => :db do
|
43
|
+
mysql_credentials = TechnoGate::Contao.instance.mysql_credentials
|
44
|
+
mysql_db_name = TechnoGate::Contao.instance.mysql_database_name
|
45
|
+
|
46
|
+
unless blank?(mysql_credentials)
|
47
|
+
begin
|
48
|
+
run <<-CMD
|
49
|
+
mysqladmin --user='#{mysql_credentials[:user]}' --password='#{mysql_credentials[:pass]}' create '#{mysql_db_name}'
|
50
|
+
CMD
|
51
|
+
rescue
|
52
|
+
puts "WARNING: The database already exists, it hasn't been modified, drop it manually if necessary."
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
task :fix_links, :roles => :web do
|
58
|
+
run <<-CMD
|
59
|
+
#{try_sudo} rm -rf #{latest_release}/public/tl_files/durable/contenu &&
|
60
|
+
#{try_sudo} rm -rf #{latest_release}/log &&
|
61
|
+
#{try_sudo} ln -nsf #{shared_path}/contenu #{latest_release}/public/tl_files/durable/contenu &&
|
62
|
+
#{try_sudo} ln -nsf #{shared_path}/htaccess.txt #{latest_release}/public/.htaccess &&
|
63
|
+
#{try_sudo} ln -nsf #{shared_path}/localconfig.php #{latest_release}/public/system/config/localconfig.php &&
|
64
|
+
#{try_sudo} ln -nsf #{shared_path}/log #{latest_release}/log
|
65
|
+
CMD
|
66
|
+
end
|
67
|
+
|
68
|
+
task :fix_permissions, :roles => :web do
|
69
|
+
run <<-CMD
|
70
|
+
#{try_sudo} chown -R www-data:www-data #{deploy_to} &&
|
71
|
+
#{try_sudo} chmod -R g+w #{latest_release}
|
72
|
+
CMD
|
73
|
+
end
|
74
|
+
|
75
|
+
desc "Copy master database to staging"
|
76
|
+
task :replicate_master_database, :roles => :web do
|
77
|
+
mysql_credentials = TechnoGate::Contao.instance.mysql_credentials
|
78
|
+
mysql_master_db_name = TechnoGate::Contao.instance.mysql_database_name("master")
|
79
|
+
mysql_staging_db_name = TechnoGate::Contao.instance.mysql_database_name("staging")
|
80
|
+
|
81
|
+
mysql_staging_db_backup_path = "#{configurations[:staging][:deploy_to]}/backups/#{mysql_staging_db_name}_#{Time.now.strftime('%d-%m-%Y_%H-%M-%S')}.sql"
|
82
|
+
|
83
|
+
begin
|
84
|
+
run <<-CMD
|
85
|
+
mysqldump \
|
86
|
+
--user='#{mysql_credentials[:user]}' \
|
87
|
+
--password='#{mysql_credentials[:pass]}' \
|
88
|
+
--default-character-set=utf8 \
|
89
|
+
'#{mysql_staging_db_name}' > \
|
90
|
+
'#{mysql_staging_db_backup_path}'
|
91
|
+
CMD
|
92
|
+
|
93
|
+
run <<-CMD
|
94
|
+
bzip2 -9 '#{mysql_staging_db_backup_path}'
|
95
|
+
CMD
|
96
|
+
|
97
|
+
run <<-CMD
|
98
|
+
mysqladmin --user='#{mysql_credentials[:user]}' --password='#{mysql_credentials[:pass]}' drop --force '#{mysql_staging_db_name}'
|
99
|
+
CMD
|
100
|
+
rescue
|
101
|
+
puts "NOTICE: #{application}'s staging database does not exist, continuing under this assumption."
|
102
|
+
end
|
103
|
+
|
104
|
+
run <<-CMD
|
105
|
+
mysqladmin --user='#{mysql_credentials[:user]}' --password='#{mysql_credentials[:pass]}' create '#{mysql_staging_db_name}'
|
106
|
+
CMD
|
107
|
+
|
108
|
+
run <<-CMD
|
109
|
+
mysqldump \
|
110
|
+
--user='#{mysql_credentials[:user]}' \
|
111
|
+
--password='#{mysql_credentials[:pass]}' \
|
112
|
+
--default-character-set=utf8 \
|
113
|
+
'#{mysql_master_db_name}' > \
|
114
|
+
'/tmp/#{mysql_master_db_name}.sql'
|
115
|
+
CMD
|
116
|
+
|
117
|
+
run <<-CMD
|
118
|
+
mysql \
|
119
|
+
--user='#{mysql_credentials[:user]}' \
|
120
|
+
--password='#{mysql_credentials[:pass]}' \
|
121
|
+
--default-character-set=utf8 \
|
122
|
+
'#{mysql_staging_db_name}' < \
|
123
|
+
/tmp/#{mysql_master_db_name}.sql
|
124
|
+
CMD
|
125
|
+
|
126
|
+
run <<-CMD
|
127
|
+
rm -f '/tmp/#{mysql_master_db_name}.sql'
|
128
|
+
CMD
|
129
|
+
end
|
130
|
+
|
131
|
+
desc "Copy master contents to staging"
|
132
|
+
task :replicate_master_contents, :roles => :web do
|
133
|
+
run <<-CMD
|
134
|
+
cp -R #{configurations[:development][:deploy_to]}/shared/contenu #{configurations[:staging][:deploy_to]}/shared/
|
135
|
+
CMD
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# This module serve as a placeholder for mysql credentials
|
140
|
+
# and other stuff that would go around in contao.
|
141
|
+
module TechnoGate
|
142
|
+
class Contao
|
143
|
+
|
144
|
+
attr_accessor :config
|
145
|
+
|
146
|
+
def self.instance(deploy_to = nil)
|
147
|
+
@@instance ||= Contao.new
|
148
|
+
|
149
|
+
@@instance
|
150
|
+
end
|
151
|
+
|
152
|
+
def mysql_credentials
|
153
|
+
return @mysql_credentials unless @mysql_credentials.nil?
|
154
|
+
|
155
|
+
begin
|
156
|
+
mysql_credentials_file = @config.capture "cat #{@config.deploy_to}/.mysql_password"
|
157
|
+
rescue
|
158
|
+
return false
|
159
|
+
end
|
160
|
+
|
161
|
+
unless mysql_credentials_file.nil? or mysql_credentials_file.empty?
|
162
|
+
@mysql_credentials = {
|
163
|
+
:user => mysql_credentials_file.match(/username: (.*)$/o)[1].chomp,
|
164
|
+
:pass => mysql_credentials_file.match(/password: (.*)$/o)[1].chomp,
|
165
|
+
}
|
166
|
+
end
|
167
|
+
|
168
|
+
@mysql_credentials
|
169
|
+
end
|
170
|
+
|
171
|
+
def mysql_database_name(branch = nil)
|
172
|
+
branch ||= @config.branch
|
173
|
+
"#{@config.application}_co_#{branch}"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
# Dependencies
|
179
|
+
after "deploy:setup", "contao:setup"
|
180
|
+
after "contao:setup", "contao:setup_localconfig"
|
181
|
+
after "contao:setup_localconfig", "contao:setup_db"
|
182
|
+
after "deploy:finalize_update", "contao:fix_links"
|
183
|
+
after "contao:fix_links", "deploy:cleanup"
|
184
|
+
|
185
|
+
if branch == 'staging'
|
186
|
+
before "deploy:restart", "contao:replicate_master_database"
|
187
|
+
after "contao:replicate_master_database", "contao:replicate_master_contents"
|
188
|
+
end
|
189
|
+
|
190
|
+
after "deploy:restart", "contao:fix_permissions"
|
191
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
|
3
|
+
# Verify that Capistrano is version 2
|
4
|
+
unless Capistrano::Configuration.respond_to?(:instance)
|
5
|
+
abort "This extension requires Capistrano 2"
|
6
|
+
end
|
7
|
+
|
8
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
9
|
+
namespace :god do
|
10
|
+
desc "start god, this starts up unicorn server"
|
11
|
+
task :start, :roles => :app, :except => {:no_release => true} do
|
12
|
+
run "cd #{current_path} && #{god_binary} -c #{god_config} --log /var/log/god.log --no-syslog --log-level warn"
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "stop god, this shutdowns unicorn server"
|
16
|
+
task :stop, :roles => :app, :except => {:no_release => true} do
|
17
|
+
run "cd #{current_path} && #{god_binary} terminate"
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "restart god, this restarts the unicorn server"
|
21
|
+
task :restart, :roles => :app, :except => {:no_release => true} do
|
22
|
+
run "cd #{current_path} && #{god_binary} restart"
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "check if god is already running"
|
26
|
+
task :check_if_running, :roles => :app, :except => {:no_release => true} do
|
27
|
+
'true' == capture("if #{god_binary} status; then echo 'true'; fi").strip
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
|
3
|
+
# Verify that Capistrano is version 2
|
4
|
+
unless Capistrano::Configuration.respond_to?(:instance)
|
5
|
+
abort "This extension requires Capistrano 2"
|
6
|
+
end
|
7
|
+
|
8
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
9
|
+
namespace :mysql do
|
10
|
+
desc "Backup database"
|
11
|
+
task :backup_db do
|
12
|
+
mysql_credentials = TechnoGate::Contao.instance.mysql_credentials
|
13
|
+
mysql_db_name = TechnoGate::Contao.instance.mysql_database_name
|
14
|
+
MYSQL_DB_BACKUP_PATH = "#{deploy_to}/backups/#{mysql_db_name}_#{Time.now.strftime('%d-%m-%Y_%H-%M-%S')}.sql"
|
15
|
+
|
16
|
+
unless blank?(mysql_credentials)
|
17
|
+
begin
|
18
|
+
run <<-CMD
|
19
|
+
mysqldump \
|
20
|
+
--user='#{mysql_credentials[:user]}' \
|
21
|
+
--password='#{mysql_credentials[:pass]}' \
|
22
|
+
--default-character-set=utf8 \
|
23
|
+
'#{mysql_db_name}' > \
|
24
|
+
'#{MYSQL_DB_BACKUP_PATH}'
|
25
|
+
CMD
|
26
|
+
|
27
|
+
run <<-CMD
|
28
|
+
bzip2 -9 '#{MYSQL_DB_BACKUP_PATH}'
|
29
|
+
CMD
|
30
|
+
rescue
|
31
|
+
puts "WARNING: The database doesn't exist."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "drop database"
|
37
|
+
task :drop_db do
|
38
|
+
mysql_credentials = TechnoGate::Contao.instance.mysql_credentials
|
39
|
+
mysql_db_name = TechnoGate::Contao.instance.mysql_database_name
|
40
|
+
|
41
|
+
begin
|
42
|
+
run <<-CMD
|
43
|
+
mysqladmin --user='#{mysql_credentials[:user]}' --password='#{mysql_credentials[:pass]}' drop --force '#{mysql_db_name}'
|
44
|
+
CMD
|
45
|
+
rescue
|
46
|
+
puts "WARNING: The database doesn't exist."
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "create database"
|
51
|
+
task :create_db do
|
52
|
+
mysql_credentials = TechnoGate::Contao.instance.mysql_credentials
|
53
|
+
mysql_db_name = TechnoGate::Contao.instance.mysql_database_name
|
54
|
+
|
55
|
+
begin
|
56
|
+
run <<-CMD
|
57
|
+
mysqladmin --user='#{mysql_credentials[:user]}' --password='#{mysql_credentials[:pass]}' create '#{mysql_db_name}'
|
58
|
+
CMD
|
59
|
+
rescue
|
60
|
+
puts "WARNING: The database doesn't exist."
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "Import a database dump"
|
65
|
+
task :import_db_dump do
|
66
|
+
mysql_credentials = TechnoGate::Contao.instance.mysql_credentials
|
67
|
+
mysql_db_name = TechnoGate::Contao.instance.mysql_database_name
|
68
|
+
|
69
|
+
unless ARGV.size >=2 and File.exists?(ARGV[1])
|
70
|
+
puts "ERROR: please run 'cap mysql:import_db_dump <sql dump>'"
|
71
|
+
exit 1
|
72
|
+
else
|
73
|
+
# The database dump name
|
74
|
+
dump_sql_file = ARGV.delete_at(1)
|
75
|
+
|
76
|
+
unless blank?(mysql_credentials)
|
77
|
+
drop_db
|
78
|
+
create_db
|
79
|
+
put File.read(dump_sql_file), "/tmp/#{mysql_db_name}_dump.sql"
|
80
|
+
|
81
|
+
run <<-CMD
|
82
|
+
mysql \
|
83
|
+
--user='#{mysql_credentials[:user]}' \
|
84
|
+
--password='#{mysql_credentials[:pass]}' \
|
85
|
+
--default-character-set=utf8 \
|
86
|
+
'#{mysql_db_name}' < \
|
87
|
+
/tmp/#{mysql_db_name}_dump.sql
|
88
|
+
CMD
|
89
|
+
|
90
|
+
run <<-CMD
|
91
|
+
rm -f '/tmp/#{mysql_db_name}_dump.sql'
|
92
|
+
CMD
|
93
|
+
|
94
|
+
exit 0
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
desc "Export a database dump"
|
100
|
+
task :export_db_dump do
|
101
|
+
mysql_credentials = TechnoGate::Contao.instance.mysql_credentials
|
102
|
+
mysql_db_name = TechnoGate::Contao.instance.mysql_database_name
|
103
|
+
|
104
|
+
unless ARGV.size >=2 or File.exists?(ARGV[1])
|
105
|
+
puts "ERROR: please run 'cap mysql:import_db_dump <sql dump>'"
|
106
|
+
puts " <sql dump> should not exist"
|
107
|
+
exit 1
|
108
|
+
else
|
109
|
+
# The database dump name
|
110
|
+
dump_sql_file = ARGV.delete_at(1)
|
111
|
+
|
112
|
+
unless blank?(mysql_credentials)
|
113
|
+
run <<-CMD
|
114
|
+
cp #{MYSQL_DB_BACKUP_PATH}.bz2 /tmp &&
|
115
|
+
bunzip2 /tmp/#{File.basename MYSQL_DB_BACKUP_PATH}.bz2
|
116
|
+
CMD
|
117
|
+
|
118
|
+
get "/tmp/#{File.basename MYSQL_DB_BACKUP_PATH}", dump_sql_file
|
119
|
+
|
120
|
+
run <<-CMD
|
121
|
+
rm -f /tmp/#{File.basename MYSQL_DB_BACKUP_PATH}
|
122
|
+
CMD
|
123
|
+
|
124
|
+
exit 0
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
before "mysql:import_db_dump", "mysql:backup_db"
|
131
|
+
before "mysql:export_db_dump", "mysql:backup_db"
|
132
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
|
3
|
+
# Verify that Capistrano is version 2
|
4
|
+
unless Capistrano::Configuration.respond_to?(:instance)
|
5
|
+
abort "This extension requires Capistrano 2"
|
6
|
+
end
|
7
|
+
|
8
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
9
|
+
|
10
|
+
namespace :rails do
|
11
|
+
desc "Install configuration files"
|
12
|
+
task :install_configuration_files, :roles => :app do
|
13
|
+
unless blank?(configuration_files)
|
14
|
+
configuration_files.each { |configuration_file| link_config_file(configuration_file) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Install rvm config file"
|
19
|
+
task :install_rvmrc_file, :roles => :app do
|
20
|
+
link_file(File.join(shared_path, 'rvmrc'), File.join(release_path, '.rvmrc'))
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Fix permissions"
|
24
|
+
task :fix_permissions, :roles => :app do
|
25
|
+
unless blank?(app_owner) or blank?(app_group)
|
26
|
+
run "#{try_sudo} chown -R #{app_owner}:#{app_group} #{deploy_to}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
namespace :deploy do
|
32
|
+
task :restart, :roles => :app, :except => { :no_release => true } do
|
33
|
+
run "#{try_sudo} touch #{File.join(current_path, 'tmp', 'restart.txt')}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
after "deploy:finalize_update", "rails:install_configuration_files"
|
38
|
+
after "rails:install_configuration_files", "rails:install_rvmrc_file"
|
39
|
+
after "deploy:restart", "rails:fix_permissions"
|
40
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
namespace :unicorn do
|
2
|
+
desc "start unicorn"
|
3
|
+
task :start, :roles => :app, :except => {:no_release => true} do
|
4
|
+
run "cd #{current_path} && #{unicorn_binary} -c #{unicorn_config} -E #{rails_env} -D"
|
5
|
+
end
|
6
|
+
|
7
|
+
desc "stop unicorn"
|
8
|
+
task :stop, :roles => :app, :except => {:no_release => true} do
|
9
|
+
run "#{try_sudo} kill `cat #{unicorn_pid}`"
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "unicorn reload"
|
13
|
+
task :reload, :roles => :app, :except => {:no_release => true} do
|
14
|
+
run "#{try_sudo} kill -s USR2 `cat #{unicorn_pid}`"
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "graceful stop unicorn"
|
18
|
+
task :graceful_stop, :roles => :app, :except => {:no_release => true} do
|
19
|
+
run "#{try_sudo} kill -s QUIT `cat #{unicorn_pid}`"
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "restart unicorn"
|
23
|
+
task :restart, :roles => :app, :except => {:no_release => true} do
|
24
|
+
stop
|
25
|
+
start
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-technogate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Wael Nasreddine
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-31 00:00:00.000000000 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: capistrano
|
17
|
+
requirement: &2152070100 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2152070100
|
26
|
+
description: This gem provides some receipts for helping me in my every-day development
|
27
|
+
email:
|
28
|
+
- wael.nasreddine@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ..gemspec
|
34
|
+
- .gitignore
|
35
|
+
- Gemfile
|
36
|
+
- Rakefile
|
37
|
+
- capistrano-technogate.gemspec
|
38
|
+
- lib/capistrano/technogate/base.rb
|
39
|
+
- lib/capistrano/technogate/configurations.rb
|
40
|
+
- lib/capistrano/technogate/contao.rb
|
41
|
+
- lib/capistrano/technogate/god.rb
|
42
|
+
- lib/capistrano/technogate/mysql.rb
|
43
|
+
- lib/capistrano/technogate/rails.rb
|
44
|
+
- lib/capistrano/technogate/unicorn.rb
|
45
|
+
- lib/capistrano/technogate/version.rb
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: https://github.com/TechnoGate/capistrano-technogate
|
48
|
+
licenses: []
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project: capistrano-technogate
|
67
|
+
rubygems_version: 1.6.2
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: This gem provides some receipts for helping me in my every-day development
|
71
|
+
test_files: []
|