matthewgarysmith-ubuntu-machine 0.3.1.3 → 0.4.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/README +5 -1
- data/lib/capistrano/ext/ubuntu-machine/aptitude.rb +1 -9
- data/lib/capistrano/ext/ubuntu-machine/gems.rb +3 -2
- data/lib/capistrano/ext/ubuntu-machine/helpers.rb +36 -0
- data/lib/capistrano/ext/ubuntu-machine/machine.rb +6 -19
- data/lib/capistrano/ext/ubuntu-machine/mysql.rb +11 -17
- data/lib/capistrano/ext/ubuntu-machine/ruby.rb +23 -10
- data/lib/capistrano/ext/ubuntu-machine/utils.rb +7 -15
- metadata +3 -3
- data/lib/capistrano/ext/ubuntu-machine/render.rb +0 -6
data/README
CHANGED
@@ -37,15 +37,7 @@ namespace :aptitude do
|
|
37
37
|
# if it must overwrite this file, since it has been modified by OVH. \
|
38
38
|
# data =~ /^\*\*\*\sissue/ looks for the interactive prompt to enable you to answer
|
39
39
|
sudo 'aptitude hold console-setup -y'
|
40
|
-
|
41
|
-
if data =~ /^\*\*\*\sissue/
|
42
|
-
# prompt, and then send the response to the remote process
|
43
|
-
ch.send_data(Capistrano::CLI.password_prompt(data) + "\n")
|
44
|
-
else
|
45
|
-
# use the default handler for all other text
|
46
|
-
Capistrano::Configuration.default_io_proc.call(ch, stream, data)
|
47
|
-
end
|
48
|
-
end
|
40
|
+
sudo_and_watch_prompt("aptitude safe-upgrade -y", /^\*\*\*\sissue/)
|
49
41
|
end
|
50
42
|
|
51
43
|
desc <<-DESC
|
@@ -1,6 +1,7 @@
|
|
1
1
|
namespace :gems do
|
2
2
|
desc "Install RubyGems"
|
3
3
|
task :install_rubygems, :roles => :app do
|
4
|
+
run "cd /tmp"
|
4
5
|
run "curl -LO http://rubyforge.org/frs/download.php/45905/rubygems-#{rubygem_version}.tgz"
|
5
6
|
run "tar xvzf rubygems-#{rubygem_version}.tgz"
|
6
7
|
run "cd rubygems-#{rubygem_version} && sudo ruby setup.rb"
|
@@ -9,7 +10,7 @@ namespace :gems do
|
|
9
10
|
sudo "gem update --system"
|
10
11
|
run "rm -Rf rubygems-#{rubygem_version}*"
|
11
12
|
end
|
12
|
-
|
13
|
+
|
13
14
|
desc "List gems on remote server"
|
14
15
|
task :list, :roles => :app do
|
15
16
|
stream "gem list"
|
@@ -19,7 +20,7 @@ namespace :gems do
|
|
19
20
|
task :update, :roles => :app do
|
20
21
|
sudo "gem update"
|
21
22
|
end
|
22
|
-
|
23
|
+
|
23
24
|
desc "Update gem system on remote server"
|
24
25
|
task :update_system, :roles => :app do
|
25
26
|
sudo "gem update --system"
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
# render a template
|
4
|
+
def render(file, binding)
|
5
|
+
template = File.read("#{File.dirname(__FILE__)}/templates/#{file}.erb")
|
6
|
+
result = ERB.new(template).result(binding)
|
7
|
+
end
|
8
|
+
|
9
|
+
# allows to sudo a command which require the user input via the prompt
|
10
|
+
def sudo_and_watch_prompt(cmd, regex_to_watch)
|
11
|
+
sudo cmd, :pty => true do |ch, stream, data|
|
12
|
+
watch_prompt(ch, stream, data, regex_to_watch)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# allows to run a command which require the user input via the prompt
|
17
|
+
def run_and_watch_prompt(cmd, regex_to_watch)
|
18
|
+
run cmd, :pty => true do |ch, stream, data|
|
19
|
+
watch_prompt(ch, stream, data, regex_to_watch)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# utility method called by sudo_and_watch_prompt and run_and_watch_prompt
|
24
|
+
def watch_prompt(ch, stream, data, regex_to_watch)
|
25
|
+
|
26
|
+
# the regex can be an array or a single regex -> we force it to always be an array with [*xx]
|
27
|
+
if [*regex_to_watch].find { |regex| data =~ regex}
|
28
|
+
# prompt, and then send the response to the remote process
|
29
|
+
ch.send_data(Capistrano::CLI.password_prompt(data) + "\n")
|
30
|
+
else
|
31
|
+
# use the default handler for all other text
|
32
|
+
Capistrano::Configuration.default_io_proc.call(ch, stream, data)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
@@ -3,33 +3,20 @@ namespace :machine do
|
|
3
3
|
desc "Change the root password, create a new user and allow him to sudo and to SSH"
|
4
4
|
task :initial_setup do
|
5
5
|
set :user_to_create , user
|
6
|
-
|
6
|
+
username = Capistrano::CLI.ui.ask("Username to login as (#{root_user}) : ")
|
7
|
+
set :user, (username.nil? || username.empty?) ? root_user : username
|
8
|
+
puts "-- logging in as #{user}"
|
9
|
+
run "whoami"
|
7
10
|
sure = Capistrano::CLI.ui.ask("Change the password for #{user}? (y/N) : ")
|
8
11
|
if sure.to_s.strip.downcase == 'y'
|
9
|
-
|
10
|
-
if data =~ /UNIX password/
|
11
|
-
# prompt, and then send the response to the remote process
|
12
|
-
ch.send_data(Capistrano::CLI.password_prompt(data) + "\n")
|
13
|
-
else
|
14
|
-
# use the default handler for all other text
|
15
|
-
Capistrano::Configuration.default_io_proc.call(ch, stream, data)
|
16
|
-
end
|
17
|
-
end
|
12
|
+
run_and_watch_prompt("passwd", [/UNIX password/])
|
18
13
|
end
|
19
14
|
|
20
15
|
users = capture('cat /etc/passwd | cut -d":" -f1').split(/\s+/)
|
21
16
|
if users.include?(user_to_create)
|
22
17
|
puts "-- user: #{user_to_create.inspect} already exists."
|
23
18
|
else
|
24
|
-
|
25
|
-
if data =~ /UNIX password/ || data=~/\[\]\:/ || data=~/\[y\/N\]/i
|
26
|
-
# prompt, and then send the response to the remote process
|
27
|
-
ch.send_data(Capistrano::CLI.password_prompt(data) + "\n")
|
28
|
-
else
|
29
|
-
# use the default handler for all other text
|
30
|
-
Capistrano::Configuration.default_io_proc.call(ch, stream, data)
|
31
|
-
end
|
32
|
-
end
|
19
|
+
run_and_watch_prompt("adduser #{user_to_create}", [/UNIX password/, /\[\]\:/, /\[y\/N\]/i])
|
33
20
|
end
|
34
21
|
|
35
22
|
sudoers_file = capture("cat /etc/sudoers", :via => :sudo)
|
@@ -19,16 +19,7 @@ namespace :mysql do
|
|
19
19
|
desc "Export MySQL database"
|
20
20
|
task :export, :roles => :db do
|
21
21
|
database = Capistrano::CLI.ui.ask("Which database should we export: ")
|
22
|
-
|
23
|
-
sudo "mysqldump -u root -p #{database} > #{database}.sql", :pty => true do |ch, stream, data|
|
24
|
-
if data =~ /Enter\spassword/
|
25
|
-
# prompt, and then send the response to the remote process
|
26
|
-
ch.send_data(Capistrano::CLI.password_prompt(data) + "\n")
|
27
|
-
else
|
28
|
-
# use the default handler for all other text
|
29
|
-
Capistrano::Configuration.default_io_proc.call(ch, stream, data)
|
30
|
-
end
|
31
|
-
end
|
22
|
+
sudo_and_watch_prompt("mysqldump -u root -p #{database} > #{database}.sql", /Enter\spassword/)
|
32
23
|
download "#{database}.sql", "#{default_local_files_path}/database.sql"
|
33
24
|
run "rm #{database}.sql"
|
34
25
|
end
|
@@ -39,22 +30,25 @@ namespace :mysql do
|
|
39
30
|
db_name = Capistrano::CLI.ui.ask("Which database should we create: ")
|
40
31
|
db_username = Capistrano::CLI.ui.ask("Which database username should we create: ")
|
41
32
|
db_user_password = Capistrano::CLI.ui.ask("Choose a password for the new database username: ")
|
42
|
-
|
43
|
-
|
44
|
-
|
33
|
+
file_to_upload = Capistrano::CLI.ui.ask("Do you want to import a database file? (y/n) : ")
|
34
|
+
if file_to_upload == "y"
|
35
|
+
file = Capistrano::CLI.ui.ask("Which database file should we import (it must be located in #{default_local_files_path}): ")
|
36
|
+
upload "#{default_local_files_path}/#{file}", "#{file}"
|
37
|
+
end
|
45
38
|
create_db_tmp_file = "create_#{db_name}.sql"
|
46
39
|
put render("new_db", binding), create_db_tmp_file
|
47
40
|
run "mysql -u root -p#{db_root_password} < #{create_db_tmp_file}"
|
48
|
-
|
49
|
-
|
50
|
-
|
41
|
+
if file_to_upload == "y"
|
42
|
+
run "mysql -u root -p#{db_root_password} #{db_name} < #{file}"
|
43
|
+
run "rm #{file}"
|
44
|
+
end
|
45
|
+
run "rm #{create_db_tmp_file}"
|
51
46
|
end
|
52
47
|
|
53
48
|
desc "Install MySQL"
|
54
49
|
task :install, :roles => :db do
|
55
50
|
db_root_password = Capistrano::CLI.ui.ask("Choose a MySQL root password : ")
|
56
51
|
sudo "aptitude install -y mysql-server mysql-client libmysqlclient15-dev"
|
57
|
-
sudo "aptitude install -y libmysql-ruby1.8"
|
58
52
|
restart
|
59
53
|
run "mysqladmin -u root password #{db_root_password}"
|
60
54
|
end
|
@@ -1,7 +1,10 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
1
3
|
namespace :ruby do
|
2
4
|
desc "Install Ruby 1.8"
|
3
5
|
task :install, :roles => :app do
|
4
6
|
sudo "aptitude install -y ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby sqlite3 libsqlite3-ruby1.8"
|
7
|
+
sudo "aptitude install -y libmysql-ruby1.8"
|
5
8
|
|
6
9
|
sudo "ln -s /usr/bin/ruby1.8 /usr/bin/ruby"
|
7
10
|
sudo "ln -s /usr/bin/ri1.8 /usr/bin/ri"
|
@@ -9,27 +12,37 @@ namespace :ruby do
|
|
9
12
|
sudo "ln -s /usr/bin/irb1.8 /usr/bin/irb"
|
10
13
|
end
|
11
14
|
|
15
|
+
|
16
|
+
set :ruby_enterprise_url do
|
17
|
+
Net::HTTP.get('www.rubyenterpriseedition.com', '/download.html').scan(/http:.*\.tar\.gz/).first
|
18
|
+
end
|
19
|
+
|
20
|
+
set :ruby_enterprise_version do
|
21
|
+
"#{ruby_enterprise_url[/(ruby-enterprise.*)(.tar.gz)/, 1]}"
|
22
|
+
end
|
23
|
+
|
12
24
|
desc "Install Ruby Enterpise Edition"
|
13
25
|
task :install_enterprise, :roles => :app do
|
14
26
|
sudo "apt-get install libssl-dev -y"
|
15
27
|
sudo "apt-get install libreadline5-dev -y"
|
16
|
-
|
28
|
+
|
17
29
|
run "test ! -d /opt/#{ruby_enterprise_version}"
|
18
|
-
run "curl -LO http://rubyforge.org/frs/download.php/50087/#{ruby_enterprise_version}.tar.gz"
|
30
|
+
# run "curl -LO http://rubyforge.org/frs/download.php/50087/#{ruby_enterprise_version}.tar.gz"
|
31
|
+
run "curl -LO #{ruby_enterprise_url}"
|
19
32
|
run "tar xzvf #{ruby_enterprise_version}.tar.gz"
|
20
33
|
run "rm #{ruby_enterprise_version}.tar.gz"
|
21
34
|
sudo "./#{ruby_enterprise_version}/installer --auto /opt/#{ruby_enterprise_version}"
|
22
35
|
sudo "rm -rf #{ruby_enterprise_version}/"
|
23
|
-
|
36
|
+
|
24
37
|
# create a "permanent" link to the current REE install
|
25
|
-
sudo "ln -s /opt/#{ruby_enterprise_version} /opt/ruby-enterprise"
|
26
|
-
|
38
|
+
sudo "ln -s /opt/#{ruby_enterprise_version} /opt/ruby-enterprise"
|
39
|
+
|
27
40
|
# add REE bin to the path
|
28
41
|
run "cat /etc/environment > ~/environment.tmp"
|
29
42
|
run 'echo PATH="/opt/ruby-enterprise/bin:$PATH" >> ~/environment.tmp'
|
30
43
|
sudo 'mv ~/environment.tmp /etc/environment'
|
31
44
|
end
|
32
|
-
|
45
|
+
|
33
46
|
desc "Install Phusion Passenger"
|
34
47
|
task :install_passenger, :roles => :app do
|
35
48
|
# because passenger-install-apache2-module do not find the rake installed by REE
|
@@ -40,9 +53,9 @@ namespace :ruby do
|
|
40
53
|
sudo "apt-get install apache2-prefork-dev -y"
|
41
54
|
|
42
55
|
sudo "/opt/#{ruby_enterprise_version}/bin/ruby /opt/#{ruby_enterprise_version}/bin/gem install passenger"
|
43
|
-
|
56
|
+
|
44
57
|
run "echo -en '\n\n\n\n\n' | sudo /opt/#{ruby_enterprise_version}/bin/ruby /opt/#{ruby_enterprise_version}/bin/passenger-install-apache2-module"
|
45
|
-
|
58
|
+
|
46
59
|
put render("passenger.load", binding), "/home/#{user}/passenger.load"
|
47
60
|
put render("passenger.conf", binding), "/home/#{user}/passenger.conf"
|
48
61
|
|
@@ -51,6 +64,6 @@ namespace :ruby do
|
|
51
64
|
|
52
65
|
sudo "a2enmod passenger"
|
53
66
|
apache.force_reload
|
54
|
-
end
|
55
|
-
|
67
|
+
end
|
68
|
+
|
56
69
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
namespace :utils do
|
2
|
-
|
2
|
+
|
3
3
|
desc "Reboot the system."
|
4
4
|
task :reboot, :roles => :gateway do
|
5
5
|
sure = Capistrano::CLI.ui.ask("Are you sure you want to reboot now? (y/n) : ")
|
6
6
|
sudo "reboot" if sure=="y"
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
desc "Force a reboot of the system."
|
10
10
|
task :force_reboot, :roles => :gateway do
|
11
11
|
sudo "reboot"
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
desc "Show the amount of free disk space."
|
15
15
|
task :disk_space, :roles => :gateway do
|
16
16
|
run "df -h /"
|
@@ -29,20 +29,12 @@ namespace :utils do
|
|
29
29
|
desc "Display passenger memory usage information."
|
30
30
|
task :passenger_memory, :roles => :gateway do
|
31
31
|
sudo "/opt/ruby-enterprise/bin/passenger-memory-stats"
|
32
|
-
end
|
32
|
+
end
|
33
33
|
|
34
34
|
desc "Activate Phusion Passenger Enterprise Edition."
|
35
35
|
task :passenger_enterprise, :roles => :gateway do
|
36
|
-
|
37
|
-
|
38
|
-
if data =~ /Key\:/ || data =~ /again\:/
|
39
|
-
# prompt, and then send the response to the remote process
|
40
|
-
ch.send_data(Capistrano::CLI.password_prompt(data) + "\n")
|
41
|
-
else
|
42
|
-
# use the default handler for all other text
|
43
|
-
Capistrano::Configuration.default_io_proc.call(ch, stream, data)
|
44
|
-
end
|
45
|
-
end
|
36
|
+
|
37
|
+
sudo_and_watch_prompt("/opt/ruby-enterprise/bin/passenger-make-enterprisey", [/Key\:/, /again\:/])
|
46
38
|
end
|
47
|
-
|
39
|
+
|
48
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matthewgarysmith-ubuntu-machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Balthazar
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-10 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- lib/capistrano/ext/ubuntu-machine.rb
|
36
36
|
- lib/capistrano/ext/ubuntu-machine
|
37
37
|
- lib/capistrano/ext/ubuntu-machine/curl.rb
|
38
|
+
- lib/capistrano/ext/ubuntu-machine/helpers.rb
|
38
39
|
- lib/capistrano/ext/ubuntu-machine/ruby.rb
|
39
40
|
- lib/capistrano/ext/ubuntu-machine/gems.rb
|
40
41
|
- lib/capistrano/ext/ubuntu-machine/git.rb
|
@@ -42,7 +43,6 @@ files:
|
|
42
43
|
- lib/capistrano/ext/ubuntu-machine/php.rb
|
43
44
|
- lib/capistrano/ext/ubuntu-machine/ssh.rb
|
44
45
|
- lib/capistrano/ext/ubuntu-machine/machine.rb
|
45
|
-
- lib/capistrano/ext/ubuntu-machine/render.rb
|
46
46
|
- lib/capistrano/ext/ubuntu-machine/apache.rb
|
47
47
|
- lib/capistrano/ext/ubuntu-machine/iptables.rb
|
48
48
|
- lib/capistrano/ext/ubuntu-machine/mysql.rb
|