Created
August 31, 2013 02:48
-
-
Save MarcosBL/6395943 to your computer and use it in GitHub Desktop.
Capistrano sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def prompt_with_default(var, default) | |
set(var) do | |
Capistrano::CLI.password_prompt "#{var} [#{default}] : " | |
end | |
set var, default if eval("#{var.to_s}.empty?") | |
end | |
namespace :misc do | |
desc "Remove problematic packages" | |
task :remove do | |
sudo "apt-get remove grub-pc" | |
sudo "apt-get -y autoremove" | |
end | |
desc "Update apt-get sources" | |
task :update do | |
sudo "apt-get update" | |
end | |
desc "Upgrade packages" | |
task :upgrade do | |
sudo "apt-get -y upgrade" | |
end | |
desc "Install Development Tools" | |
task :install_dev do | |
sudo "apt-get install build-essential -y" | |
end | |
desc "Install Git" | |
task :install_git do | |
sudo "apt-get install git-core git-svn -y" | |
end | |
end | |
namespace :mysql do | |
desc "Install Mysql-server" | |
task :install do | |
begin | |
# Ask user for a password to configure for external access | |
prompt_with_default(:mysql_admin_password, "DeFaUlTPwd") | |
# Create a temo text file on destination with the user creation, flush and users select (just as debug) | |
put %Q{ | |
GRANT ALL PRIVILEGES ON *.* TO "root"@"%" IDENTIFIED BY "#{mysql_admin_password}"; | |
FLUSH PRIVILEGES; | |
select CONCAT(User,"@",Host) as User, Password from user; | |
}, "/tmp/mysql-install-external-password.tmp" | |
# Silent install Mysql Server | |
sudo "DEBIAN_FRONTEND=noninteractive apt-get -qq -y install mysql-server" | |
# Comment bind line to listen on all interfaces | |
sudo "sed -i 's/^bind-address/#bind-address/g' /etc/mysql/my.cnf" | |
# Import the previously uploaded sql script | |
sudo "mysql -Dmysql < /tmp/mysql-install-external-password.tmp" | |
# Restart MySQL to apply changes | |
sudo "service mysql restart" | |
rescue | |
raise | |
ensure | |
# Delete temp file | |
sudo "rm /tmp/mysql-install-external-password.tmp" | |
end | |
end | |
end | |
desc "First time server tune" | |
task :first do | |
misc.remove | |
misc.update | |
misc.upgrade | |
misc.install_dev | |
misc.install_git | |
mysql.install | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment