gitpusshuten 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/.bundle/config +2 -0
- data/.gitignore +4 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +53 -0
- data/README.md +7 -0
- data/bin/gitpusshuten +4 -0
- data/bin/heavenly +4 -0
- data/bin/ten +4 -0
- data/gitpusshuten.gemspec +26 -0
- data/lib/gitpusshuten/cli.rb +78 -0
- data/lib/gitpusshuten/command.rb +147 -0
- data/lib/gitpusshuten/commands/base.rb +246 -0
- data/lib/gitpusshuten/commands/delete.rb +27 -0
- data/lib/gitpusshuten/commands/help.rb +36 -0
- data/lib/gitpusshuten/commands/initialize.rb +61 -0
- data/lib/gitpusshuten/commands/push.rb +54 -0
- data/lib/gitpusshuten/commands/remote.rb +29 -0
- data/lib/gitpusshuten/commands/user.rb +252 -0
- data/lib/gitpusshuten/commands/version.rb +21 -0
- data/lib/gitpusshuten/configuration.rb +122 -0
- data/lib/gitpusshuten/environment.rb +70 -0
- data/lib/gitpusshuten/gem.rb +33 -0
- data/lib/gitpusshuten/git.rb +111 -0
- data/lib/gitpusshuten/helpers/environment/installers.rb +59 -0
- data/lib/gitpusshuten/helpers/environment/packages.rb +21 -0
- data/lib/gitpusshuten/helpers/environment/scp.rb +57 -0
- data/lib/gitpusshuten/helpers/environment/ssh.rb +77 -0
- data/lib/gitpusshuten/helpers/environment/ssh_key.rb +79 -0
- data/lib/gitpusshuten/helpers/environment/user.rb +70 -0
- data/lib/gitpusshuten/helpers/spinner.rb +98 -0
- data/lib/gitpusshuten/hook.rb +26 -0
- data/lib/gitpusshuten/hooks.rb +147 -0
- data/lib/gitpusshuten/initializer.rb +95 -0
- data/lib/gitpusshuten/local.rb +35 -0
- data/lib/gitpusshuten/log.rb +83 -0
- data/lib/gitpusshuten/modules/active_record/hooks.rb +19 -0
- data/lib/gitpusshuten/modules/apache/command.rb +354 -0
- data/lib/gitpusshuten/modules/bundler/command.rb +43 -0
- data/lib/gitpusshuten/modules/bundler/hooks.rb +8 -0
- data/lib/gitpusshuten/modules/mysql/command.rb +192 -0
- data/lib/gitpusshuten/modules/nanoc/hooks.rb +9 -0
- data/lib/gitpusshuten/modules/nginx/command.rb +447 -0
- data/lib/gitpusshuten/modules/passenger/command.rb +310 -0
- data/lib/gitpusshuten/modules/passenger/hooks.rb +4 -0
- data/lib/gitpusshuten/modules/rvm/command.rb +277 -0
- data/lib/gitpusshuten.rb +21 -0
- data/lib/templates/config.rb +37 -0
- data/lib/templates/hooks.rb +40 -0
- data/spec/cli_spec.rb +83 -0
- data/spec/command_spec.rb +76 -0
- data/spec/configuration_spec.rb +45 -0
- data/spec/environment_spec.rb +64 -0
- data/spec/fixtures/combined_hooks.rb +23 -0
- data/spec/fixtures/config.rb +23 -0
- data/spec/fixtures/hooks.rb +37 -0
- data/spec/fixtures/passenger.json +1 -0
- data/spec/gem_spec.rb +28 -0
- data/spec/git_spec.rb +59 -0
- data/spec/gitpusshuten_spec.rb +9 -0
- data/spec/hook_spec.rb +48 -0
- data/spec/hooks_spec.rb +150 -0
- data/spec/initializer_spec.rb +26 -0
- data/spec/log_spec.rb +20 -0
- data/spec/spec_helper.rb +43 -0
- metadata +220 -0
@@ -0,0 +1,354 @@
|
|
1
|
+
module GitPusshuTen
|
2
|
+
module Commands
|
3
|
+
class Apache < GitPusshuTen::Commands::Base
|
4
|
+
description "[Module] Apache commands."
|
5
|
+
usage "apache <command> <for|from|to> <environment> (environment)"
|
6
|
+
example "heavenly apache install to staging # Installs the Apache2 web server"
|
7
|
+
example "heavenly apache update-configuration for staging # Only for Passenger users, when updating Ruby/Passenger versions."
|
8
|
+
example "heavenly apache download-configuration from staging # Downloads the Apache2 configuration file from the specified environment."
|
9
|
+
example "heavenly apache upload-configuration to staging # Uploads the Apache2 configuration file to the specified environment."
|
10
|
+
example "heavenly apache create-vhost for production # Creates a local vhost template for the specified environment."
|
11
|
+
example "heavenly apache delete-vhost from production # Deletes the remote vhost for the specified environment."
|
12
|
+
example "heavenly apache upload-vhost to staging # Uploads your local vhost to the server for the specified environment."
|
13
|
+
example "heavenly apache download-vhost from production # Downloads the remote vhost from the specified environment."
|
14
|
+
example "heavenly apache start staging environment # Starts the Apache webserver."
|
15
|
+
example "heavenly apache stop production environment # Stops the Apache webserver."
|
16
|
+
example "heavenly apache restart production environment # Restarts the Apache webserver."
|
17
|
+
example "heavenly apache reload production environment # Reloads the Apache webserver."
|
18
|
+
|
19
|
+
def initialize(*objects)
|
20
|
+
super
|
21
|
+
|
22
|
+
@command = cli.arguments.shift
|
23
|
+
|
24
|
+
help if command.nil? or e.name.nil?
|
25
|
+
|
26
|
+
@command = @command.underscore
|
27
|
+
|
28
|
+
##
|
29
|
+
# Default Configuration
|
30
|
+
@installation_dir = "/etc/apache2"
|
31
|
+
@configuration_directory = @installation_dir
|
32
|
+
@configuration_file = File.join(@configuration_directory, 'apache2.conf')
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Installs the Apache2 web server
|
37
|
+
def perform_install!
|
38
|
+
warning "If you are planning to use #{y('Ruby')} and #{y('Passenger')} then #{r("DON'T")} use this Apache2 installer."
|
39
|
+
warning "Instead, use the Passenger module to install it."
|
40
|
+
standard "\n\s\s#{y("heavenly passenger install to #{y(e.name)}")}\n\n"
|
41
|
+
|
42
|
+
message "If you do not plan on using #{y('Ruby')} on this server, then this stand-alone installation should be fine."
|
43
|
+
message "Do you want to continue?"
|
44
|
+
exit unless yes?
|
45
|
+
|
46
|
+
prompt_for_root_password!
|
47
|
+
|
48
|
+
Spinner.return :message => "Installing Apache2 web server.." do
|
49
|
+
e.install!('apache2')
|
50
|
+
g('Done!')
|
51
|
+
end
|
52
|
+
message "Apache2 has been installed in #{y('/etc/apache2')}."
|
53
|
+
message "Creating #{y('Apache')} vhost template."
|
54
|
+
GitPusshuTen::Initializer.new('apache', 'create-vhost', 'for', "#{e.name}")
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# Starts Apache
|
59
|
+
def perform_start!
|
60
|
+
message "Starting Apache."
|
61
|
+
puts e.execute_as_root("/etc/init.d/apache2 start")
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Stops Apache
|
66
|
+
def perform_stop!
|
67
|
+
message "Stopping Apache."
|
68
|
+
puts e.execute_as_root("/etc/init.d/apache2 stop")
|
69
|
+
end
|
70
|
+
|
71
|
+
##
|
72
|
+
# Restarts Apache
|
73
|
+
def perform_restart!
|
74
|
+
message "Restarting Apache."
|
75
|
+
puts e.execute_as_root("/etc/init.d/apache2 restart")
|
76
|
+
end
|
77
|
+
|
78
|
+
##
|
79
|
+
# Reload Apache
|
80
|
+
def perform_reload!
|
81
|
+
message "Reloading Apache Configuration."
|
82
|
+
puts e.execute_as_root("/etc/init.d/apache2 reload")
|
83
|
+
end
|
84
|
+
|
85
|
+
##
|
86
|
+
# Downloads the Apache2 configuration file
|
87
|
+
def perform_download_config!
|
88
|
+
if not e.file?('/etc/apache2/apache2.conf')
|
89
|
+
error "Could not find the Apache2 configuration file in #{y('/etc/apache2/apache2.conf')}"
|
90
|
+
exit
|
91
|
+
end
|
92
|
+
|
93
|
+
local_apache_dir = File.join(local.gitpusshuten_dir, 'apache')
|
94
|
+
local.execute("mkdir -p '#{local_apache_dir}'")
|
95
|
+
Spinner.return :message => "Downloading Apache2 configuration file to #{y(local_apache_dir)}.." do
|
96
|
+
scp_as_root(:download, "/etc/apache2/apache2.conf", local_apache_dir)
|
97
|
+
g('Done!')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
##
|
102
|
+
# Uploads the Apache2 configuration file
|
103
|
+
def perform_upload_config!
|
104
|
+
if not e.directory?('/etc/apache2')
|
105
|
+
error "Could not find the Apache2 installation directory in #{y('/etc/apache2')}"
|
106
|
+
exit
|
107
|
+
end
|
108
|
+
|
109
|
+
local_configuration_file = File.join(local.gitpusshuten_dir, 'apache', 'apache2.conf')
|
110
|
+
if not File.exist?(local_configuration_file)
|
111
|
+
error "Could not find the local Apache2 configuration file in #{y(local_configuration_file)}"
|
112
|
+
exit
|
113
|
+
end
|
114
|
+
|
115
|
+
Spinner.return :message => "Uploading Apache2 configuration file #{y(local_configuration_file)}.." do
|
116
|
+
scp_as_root(:upload, local_configuration_file, "/etc/apache2/apache2.conf")
|
117
|
+
g('Done!')
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def perform_download_vhost!
|
122
|
+
remote_vhost = File.join(@configuration_directory, "sites-enabled", "#{e.sanitized_app_name}.#{e.name}.vhost")
|
123
|
+
if not e.file?(remote_vhost) #prompts root
|
124
|
+
error "There is no vhost currently present in #{y(remote_vhost)}."
|
125
|
+
exit
|
126
|
+
end
|
127
|
+
|
128
|
+
local.execute("mkdir -p #{File.join(local.gitpusshuten_dir, 'apache')}")
|
129
|
+
local_vhost = File.join(local.gitpusshuten_dir, 'apache', "#{e.name}.vhost")
|
130
|
+
if File.exist?(local_vhost)
|
131
|
+
warning "#{y(local_vhost)} already exists. Do you want to overwrite it?"
|
132
|
+
exit unless yes?
|
133
|
+
end
|
134
|
+
|
135
|
+
Spinner.return :message => "Downloading vhost.." do
|
136
|
+
e.scp_as_root(:download, remote_vhost, local_vhost)
|
137
|
+
g("Finished downloading!")
|
138
|
+
end
|
139
|
+
message "You can find the vhost in: #{y(local_vhost)}."
|
140
|
+
end
|
141
|
+
|
142
|
+
##
|
143
|
+
# Uploads a local vhost
|
144
|
+
def perform_upload_vhost!
|
145
|
+
vhost_file = File.join(local.gitpusshuten_dir, 'apache', "#{e.name}.vhost")
|
146
|
+
if File.exist?(vhost_file)
|
147
|
+
message "Uploading #{y(vhost_file)} to " +
|
148
|
+
y(File.join(@configuration_directory, 'sites-enabled', "#{e.sanitized_app_name}.#{e.name}.vhost!"))
|
149
|
+
|
150
|
+
prompt_for_root_password!
|
151
|
+
|
152
|
+
Spinner.return :message => "Uploading vhost.." do
|
153
|
+
e.scp_as_root(:upload, vhost_file, File.join(@configuration_directory, 'sites-enabled', "#{e.sanitized_app_name}.#{e.name}.vhost"))
|
154
|
+
g("Finished uploading!")
|
155
|
+
end
|
156
|
+
|
157
|
+
perform_restart!
|
158
|
+
else
|
159
|
+
error "Could not locate vhost file #{y(vhost_file)}."
|
160
|
+
error "Download an existing one from your server with:"
|
161
|
+
standard "\n\s\s#{y("heavenly apache download-vhost for #{e.name}")}\n\n"
|
162
|
+
error "Or create a new template by running:"
|
163
|
+
standard "\n\s\s#{y("heavenly apache create-vhost for #{e.name}")}\n\n"
|
164
|
+
exit
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
##
|
169
|
+
# Deletes a vhost
|
170
|
+
def perform_delete_vhost!
|
171
|
+
vhost_file = File.join(@configuration_directory, 'sites-enabled', "#{e.sanitized_app_name}.#{e.name}.vhost")
|
172
|
+
if e.file?(vhost_file) # prompts root
|
173
|
+
message "Deleting #{y(vhost_file)}!"
|
174
|
+
e.execute_as_root("rm #{vhost_file}")
|
175
|
+
perform_reload!
|
176
|
+
else
|
177
|
+
message "#{y(vhost_file)} does not exist."
|
178
|
+
exit
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
##
|
183
|
+
# Creates a vhost
|
184
|
+
def perform_create_vhost!
|
185
|
+
create_vhost_template_file!
|
186
|
+
end
|
187
|
+
|
188
|
+
##
|
189
|
+
# Performs the Update Configuration command
|
190
|
+
# This is particularly used when you change Passenger or Ruby versions
|
191
|
+
# so these are updated in the apache2.conf file.
|
192
|
+
def perform_update_configuration!
|
193
|
+
message "Checking the #{y(@configuration_file)} for current Passenger configuration."
|
194
|
+
config_contents = e.execute_as_root("cat '#{@configuration_file}'") # prompts root
|
195
|
+
if not config_contents.include? 'PassengerRoot' or not config_contents.include?('PassengerRuby') or not config_contents.include?('passenger_module')
|
196
|
+
error "Could not find Passenger configuration, has it ever been set up?"
|
197
|
+
exit
|
198
|
+
end
|
199
|
+
|
200
|
+
message "Checking if Passenger is installed under the #{y('default')} Ruby."
|
201
|
+
if not e.installed?('passenger')
|
202
|
+
message "Passenger isn't installed for the current Ruby"
|
203
|
+
Spinner.return :message => "Installing latest Phusion Passenger Gem.." do
|
204
|
+
e.execute_as_root('gem install passenger --no-ri --no-rdoc')
|
205
|
+
g("Done!")
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
Spinner.return :message => "Finding current Phusion Passenger Gem version..." do
|
210
|
+
if e.execute_as_root('passenger-config --version') =~ /(\d+\.\d+\..+)/
|
211
|
+
@passenger_version = $1.chomp.strip
|
212
|
+
g('Found!')
|
213
|
+
else
|
214
|
+
r('Could not find the current Passenger version.')
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
exit if @passenger_version.nil?
|
219
|
+
|
220
|
+
Spinner.return :message => "Finding current Ruby version for the current Phusion Passenger Gem.." do
|
221
|
+
if e.execute_as_root('passenger-config --root') =~ /\/usr\/local\/rvm\/gems\/(.+)\/gems\/passenger-.+/
|
222
|
+
@ruby_version = $1.chomp.strip
|
223
|
+
g('Found!')
|
224
|
+
else
|
225
|
+
r("Could not find the current Ruby version under which the Passenger Gem has been installed.")
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
exit if @ruby_version.nil?
|
230
|
+
|
231
|
+
puts <<-INFO
|
232
|
+
|
233
|
+
|
234
|
+
[Detected Versions]
|
235
|
+
|
236
|
+
Ruby Version: #{@ruby_version}
|
237
|
+
Phusion Passenger Version: #{@passenger_version}
|
238
|
+
|
239
|
+
|
240
|
+
INFO
|
241
|
+
|
242
|
+
message "Apache will now be configured to work with the above versions. Is this correct?"
|
243
|
+
exit unless yes?
|
244
|
+
|
245
|
+
##
|
246
|
+
# Checks to see if Passengers WatchDog is available in the current Passenger gem
|
247
|
+
# If it is not, then Passenger needs to run the "passenger-install-nginx-module" so it gets installed
|
248
|
+
if not e.directory?("/usr/local/rvm/gems/#{@ruby_version}/gems/passenger-#{@passenger_version}/agents")
|
249
|
+
message "Phusion Passenger has not yet been installed for this Ruby's Passenger Gem."
|
250
|
+
message "You need to update #{y('Apache')} and #{y('Passenger')} to proceed with the configuration.\n\n"
|
251
|
+
message "Would you like to update #{y('Apache')} and #{y('Phusion Passenger')} #{y(@passenger_version)} for #{y(@ruby_version)}?"
|
252
|
+
message "NOTE: Your current #{y('Apache')} configuration will #{g('not')} be lost."
|
253
|
+
|
254
|
+
if yes?
|
255
|
+
Spinner.return :message => "Ensuring #{y('Phusion Passenger')} and #{y('Apache')} dependencies are installed.." do
|
256
|
+
e.install!("build-essential libcurl4-openssl-dev bison openssl libreadline5 libreadline5-dev curl git-core zlib1g zlib1g-dev libssl-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev")
|
257
|
+
e.install!("apache2-mpm-prefork apache2-prefork-dev libapr1-dev libaprutil1-dev")
|
258
|
+
g("Done!")
|
259
|
+
end
|
260
|
+
|
261
|
+
message "Installing Apache with the Phusion Passenger Module."
|
262
|
+
Spinner.return :message => "Installing, this may take a while.." do
|
263
|
+
e.execute_as_root("passenger-install-apache2-module --auto")
|
264
|
+
g("Done!")
|
265
|
+
end
|
266
|
+
else
|
267
|
+
exit
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
##
|
272
|
+
# Creates a tmp dir
|
273
|
+
local.create_tmp_dir!
|
274
|
+
|
275
|
+
##
|
276
|
+
# Downloads the Apache configuration file to tmp dir
|
277
|
+
message "Updating Phusion Passenger paths in the Apache Configuration."
|
278
|
+
Spinner.return :message => "Configuring Apache.." do
|
279
|
+
e.scp_as_root(:download, @configuration_file, local.tmp_dir)
|
280
|
+
@configuration_file_name = @configuration_file.split('/').last
|
281
|
+
|
282
|
+
local_configuration_file = File.join(local.tmp_dir, @configuration_file_name)
|
283
|
+
update = File.read(local_configuration_file)
|
284
|
+
|
285
|
+
update.sub! /LoadModule passenger_module \/usr\/local\/rvm\/gems\/(.+)\/gems\/passenger-(.+)\/ext\/apache2\/mod_passenger\.so/,
|
286
|
+
"LoadModule passenger_module /usr/local/rvm/gems/#{@ruby_version}/gems/passenger-#{@passenger_version}/ext/apache2/mod_passenger.so"
|
287
|
+
|
288
|
+
update.sub! /PassengerRoot \/usr\/local\/rvm\/gems\/(.+)\/gems\/passenger-(.+)/,
|
289
|
+
"PassengerRoot /usr/local/rvm/gems/#{@ruby_version}/gems/passenger-#{@passenger_version}"
|
290
|
+
|
291
|
+
update.sub! /PassengerRuby \/usr\/local\/rvm\/wrappers\/(.+)\/ruby/,
|
292
|
+
"PassengerRuby /usr/local/rvm/wrappers/#{@ruby_version}/ruby"
|
293
|
+
|
294
|
+
File.open(local_configuration_file, 'w') do |file|
|
295
|
+
file << update
|
296
|
+
end
|
297
|
+
|
298
|
+
##
|
299
|
+
# Create a backup of the current configuration file
|
300
|
+
e.execute_as_root("cp '#{@configuration_file}' '#{@configuration_file}.backup.#{Time.now.to_i}'")
|
301
|
+
|
302
|
+
##
|
303
|
+
# Upload the updated NginX configuration file
|
304
|
+
e.scp_as_root(:upload, local_configuration_file, @configuration_file)
|
305
|
+
|
306
|
+
##
|
307
|
+
# Remove the local tmp directory
|
308
|
+
local.remove_tmp_dir!
|
309
|
+
|
310
|
+
g("Done!")
|
311
|
+
end
|
312
|
+
|
313
|
+
message "Apache configuration file has been updated!"
|
314
|
+
message "#{y(@configuration_file)}\n\n"
|
315
|
+
|
316
|
+
warning "If you changed #{y('Ruby versions')}, be sure that all your application gems are installed."
|
317
|
+
warning "If you only updated #{y('Phusion Passenger')} and did not change #{y('Ruby versions')}"
|
318
|
+
warning "then you should be able to just restart #{y('Apache')} right away since all application gems should still be in tact.\n\n"
|
319
|
+
|
320
|
+
message "When ready, run the following command to restart #{y('Apache')} and have the applied updates take effect:"
|
321
|
+
standard "\n\s\s#{y("heavenly apache restart for #{e.name}")}"
|
322
|
+
end
|
323
|
+
|
324
|
+
##
|
325
|
+
# Creates a vhost template file if it doesn't already exist.
|
326
|
+
def create_vhost_template_file!
|
327
|
+
local.execute("mkdir -p '#{File.join(local.gitpusshuten_dir, 'apache')}'")
|
328
|
+
vhost_file = File.join(local.gitpusshuten_dir, 'apache', "#{e.name}.vhost")
|
329
|
+
|
330
|
+
create_file = true
|
331
|
+
if File.exist?(vhost_file)
|
332
|
+
warning "#{y(vhost_file)} already exists, do you want to overwrite it?"
|
333
|
+
create_file = yes?
|
334
|
+
end
|
335
|
+
|
336
|
+
if create_file
|
337
|
+
File.open(vhost_file, 'w') do |file|
|
338
|
+
file << "<VirtualHost *:80>\n"
|
339
|
+
file << "\s\sServerName mydomain.com\n"
|
340
|
+
file << "\s\sServerAlias www.mydomain.com\n"
|
341
|
+
file << "\s\sDocumentRoot #{e.app_dir}/public\n"
|
342
|
+
file << "\s\s<Directory #{e.app_dir}/public>\n"
|
343
|
+
file << "\s\s\s\sAllowOverride all\n"
|
344
|
+
file << "\s\s\s\sOptions -MultiViews\n"
|
345
|
+
file << "\s\s</Directory>\n"
|
346
|
+
file << "</VirtualHost>\n"
|
347
|
+
end
|
348
|
+
message "The vhost has been created in #{y(vhost_file)}."
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module GitPusshuTen
|
2
|
+
module Commands
|
3
|
+
class Bundler < GitPusshuTen::Commands::Base
|
4
|
+
description "[Module] Bundler commands."
|
5
|
+
usage "bundler <command> <environment> environment"
|
6
|
+
example "heavenly bundler bundle staging environment # Bundles an application's gems for the specified environment."
|
7
|
+
|
8
|
+
def initialize(*objects)
|
9
|
+
super
|
10
|
+
|
11
|
+
@command = cli.arguments.shift
|
12
|
+
|
13
|
+
help if command.nil? or e.name.nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
##
|
17
|
+
# Bundles gems
|
18
|
+
def perform_bundle!
|
19
|
+
GitPusshuTen::Log.message "Bundling Gems for #{y(c.application)} (#{y(e.name)} environment)."
|
20
|
+
installed = e.installed?('bundle')
|
21
|
+
if not installed
|
22
|
+
GitPusshuTen::Log.message "Couldn't find Bundler, installing the gem."
|
23
|
+
Spinner.return :message => "Installing Bundler.." do
|
24
|
+
e.execute_as_user('gem install bundler --no-ri --no-rdoc')
|
25
|
+
installed = e.installed?('bundle')
|
26
|
+
if not installed
|
27
|
+
r("Unable to install Bundler.")
|
28
|
+
else
|
29
|
+
g("Done!")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
exit if not installed
|
35
|
+
|
36
|
+
Spinner.return :message => "Bundling Gems for #{y(c.application)}", :put => true do
|
37
|
+
e.execute_as_user("cd '#{e.app_dir}'; bundle install --without test development")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
##
|
2
|
+
# Post Deploy Hook for installing gems
|
3
|
+
# Checks if the bundle command is available before attemping
|
4
|
+
# and installs the Bundler gem if it is not available before proceeding
|
5
|
+
post "Install dependencies (Bundler)" do
|
6
|
+
run "if [[ $(which bundle) == '' ]]; then gem install bundler; fi"
|
7
|
+
run "bundle install --without development test"
|
8
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
module GitPusshuTen
|
2
|
+
module Commands
|
3
|
+
class Mysql < GitPusshuTen::Commands::Base
|
4
|
+
description "[Module] MySQL installer and manager."
|
5
|
+
usage "mysql <command> <environment>"
|
6
|
+
example "heavenly mysql install on staging # Installs MySQL to the staging environment."
|
7
|
+
example "heavenly mysql uninstall from staging # Uninstalls MySQL from the staging environment."
|
8
|
+
example "heavenly mysql add-user to staging # Adds the user to MySQL on the production environment."
|
9
|
+
example "heavenly mysql remove-user from staging # Remvoes the user from MySQL on the production environment."
|
10
|
+
example "heavenly mysql change-root-password on staging # Changes the root password of MySQL on the staging environment."
|
11
|
+
|
12
|
+
def initialize(*objects)
|
13
|
+
super
|
14
|
+
|
15
|
+
@command = cli.arguments.shift
|
16
|
+
|
17
|
+
help if command.nil? or e.name.nil?
|
18
|
+
|
19
|
+
@command = @command.underscore
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Install MySQL
|
24
|
+
def perform_install!
|
25
|
+
if e.installed?('mysql')
|
26
|
+
error "MySQL is already installed."
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
|
30
|
+
message "Please provide a new password for your MySQL database #{y('root')} user."
|
31
|
+
prompt_for_new_password!
|
32
|
+
|
33
|
+
e.ensure_aptitude_installed!
|
34
|
+
|
35
|
+
command = "export DEBIAN_FRONTEND=noninteractive; aptitude update;"
|
36
|
+
command += "aptitude install -y mysql-client mysql-server libmysqlclient15off libmysqlclient15-dev mysql-common;"
|
37
|
+
command += "mysqladmin -u root password '#{@new_password}'"
|
38
|
+
|
39
|
+
Spinner.return :message => "Installing #{y('MySQL')} to #{y(e.name)}.." do
|
40
|
+
e.execute_as_root(command)
|
41
|
+
g('Done!')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Changes the root password of the MySQL Server
|
47
|
+
def perform_change_root_password!
|
48
|
+
if not e.installed?('mysql')
|
49
|
+
error "MySQL isn't installed."
|
50
|
+
exit
|
51
|
+
end
|
52
|
+
|
53
|
+
message "Please provide your MySQL #{y('root')} password."
|
54
|
+
@existing_password = ask('') { |q| q.echo = false }
|
55
|
+
confirm_access!
|
56
|
+
|
57
|
+
message "Please provide a new password for your MySQL database #{y('root')} user."
|
58
|
+
prompt_for_new_password!
|
59
|
+
|
60
|
+
Spinner.return :message => "Changing root password of #{y('MySQL')} on #{y(e.name)} environment.." do
|
61
|
+
e.execute_as_root("mysqladmin -u root --password='#{@existing_password}' password '#{@new_password}'")
|
62
|
+
g('Done!')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# Uninstalls the MySQL server
|
68
|
+
def perform_uninstall!
|
69
|
+
if not e.installed?('mysql')
|
70
|
+
error "MySQL isn't installed."
|
71
|
+
exit
|
72
|
+
end
|
73
|
+
|
74
|
+
message "Please provide your MySQL #{y('root')} password."
|
75
|
+
@existing_password = ask('') { |q| q.echo = false }
|
76
|
+
confirm_access!
|
77
|
+
|
78
|
+
Spinner.return :message => "Uninstalling #{y('MySQL')} from #{y(e.name)} environment.." do
|
79
|
+
e.execute_as_root("mysqladmin -u root --password='#{@existing_password}' password ''")
|
80
|
+
e.execute_as_root("aptitude remove -y mysql-client mysql-server")
|
81
|
+
g('Done!')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
##
|
86
|
+
# Adds the environment user to the database
|
87
|
+
def perform_add_user!
|
88
|
+
if not e.installed?('mysql')
|
89
|
+
error "MySQL isn't installed."
|
90
|
+
exit
|
91
|
+
end
|
92
|
+
|
93
|
+
##
|
94
|
+
# Confirm Root Password
|
95
|
+
message "Please provide your MySQL #{y('root')} password."
|
96
|
+
@existing_password = ask('') { |q| q.echo = false }
|
97
|
+
confirm_access!
|
98
|
+
|
99
|
+
##
|
100
|
+
# Ask password for the new user
|
101
|
+
message "Please provide a new password for your MySQL database user."
|
102
|
+
prompt_for_new_password!
|
103
|
+
|
104
|
+
command = "\"CREATE USER '#{c.user}'@'localhost' IDENTIFIED BY '#{@new_password}';"
|
105
|
+
command += "GRANT ALL ON *.* TO '#{c.user}'@'localhost';\""
|
106
|
+
|
107
|
+
response = e.execute_as_root("mysql -u root --password='#{@existing_password}' -e #{command}")
|
108
|
+
if not response =~ /ERROR 1396/
|
109
|
+
message "User #{y(c.user)} has been added!"
|
110
|
+
else
|
111
|
+
error "User #{y(c.user)} already exists."
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
##
|
117
|
+
# Removes the user from the database
|
118
|
+
def perform_remove_user!
|
119
|
+
if not e.installed?('mysql')
|
120
|
+
error "MySQL isn't installed."
|
121
|
+
exit
|
122
|
+
end
|
123
|
+
|
124
|
+
##
|
125
|
+
# Confirm Root Password
|
126
|
+
message "Please provide your MySQL #{y('root')} password."
|
127
|
+
@existing_password = ask('') { |q| q.echo = false }
|
128
|
+
confirm_access!
|
129
|
+
|
130
|
+
response = e.execute_as_root("mysql -u root --password='#{@existing_password}' -e \"DROP USER '#{c.user}'@'localhost';\"")
|
131
|
+
if response =~ /ERROR 1396/
|
132
|
+
error "User #{y(c.user)} does not exist."
|
133
|
+
elsif response.nil?
|
134
|
+
message "User #{y(c.user)} has been removed!"
|
135
|
+
else
|
136
|
+
puts response
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
##
|
141
|
+
# Prompts the user to fill in a new password
|
142
|
+
def prompt_for_new_password!
|
143
|
+
while not @mysql_new_password_confirmed
|
144
|
+
@new_password = ask('') { |q| q.echo = false }
|
145
|
+
message "Please enter your password again."
|
146
|
+
@password_confirmation = ask('') { |q| q.echo = false }
|
147
|
+
|
148
|
+
if not @new_password.empty? and @new_password == @password_confirmation
|
149
|
+
@mysql_new_password_confirmed = true
|
150
|
+
else
|
151
|
+
if @new_password.empty? or @password_confirmation.empty?
|
152
|
+
error "Please provide a password."
|
153
|
+
else
|
154
|
+
error "Password and Password confirmation do not match."
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
##
|
161
|
+
# Prompts the user to fill in it's existing password
|
162
|
+
def prompt_for_existing_password!
|
163
|
+
while not @mysql_existing_password_confirmed
|
164
|
+
message "Please provide your password for your MySQL database root user."
|
165
|
+
@existing_password = ask('') { |q| q.echo = false }
|
166
|
+
message "Please enter your password again."
|
167
|
+
@password_confirmation = ask('') { |q| q.echo = false }
|
168
|
+
|
169
|
+
if not @existing_password.empty? and @existing_password == @password_confirmation
|
170
|
+
@mysql_existing_password_confirmed = true
|
171
|
+
else
|
172
|
+
if @existing_password.empty? or @password_confirmation.empty?
|
173
|
+
error "Please provide a password."
|
174
|
+
else
|
175
|
+
error "Password and Password confirmation do not match."
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
##
|
182
|
+
# Confirms whether the provided password is correct
|
183
|
+
def confirm_access!
|
184
|
+
if e.execute_as_root("mysqladmin -u root --password='#{@existing_password}' ping") =~ /Access denied for user/
|
185
|
+
error "Incorrect password."
|
186
|
+
exit
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
##
|
2
|
+
# Post Deploy Hook for compiling the html files
|
3
|
+
# Checks if nanoc has been installed before attempting to compile
|
4
|
+
post "Compile HTML Files (Nanoc)" do
|
5
|
+
run "if [[ -x $(which nanoc) ]]; then gem install nanoc; fi"
|
6
|
+
run "rm -rf output public"
|
7
|
+
run "nanoc compile"
|
8
|
+
run "mv output public"
|
9
|
+
end
|