ruby Capistrano样本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby Capistrano样本相关的知识,希望对你有一定的参考价值。

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

以上是关于ruby Capistrano样本的主要内容,如果未能解决你的问题,请参考以下文章

ruby Capistrano部署策略支持git子模块(需要Capistrano v3.1.0或更高版本)

部署后缺少宝石(Ruby,Ruby on Rails,Capistrano)

ruby Capistrano任务查看日志

ruby 周五为Capistrano部署脚本

ruby Capistrano +作曲家

ruby Capistrano的部署,Recipe.rb