企业里实现代码自动部署、回滚的解决方案——Caphub

上周给大家介绍了capistrano,它可以帮助我们来解决代码自动部署与回滚的软件,但这个软件还是有点缺点,比如如果你同时有多个项目的时候,就得创建多个目录,然后每次进行代码更新的时候,进入到不同的目录中去,十分的麻烦,所以本文介绍的caphub就是为了解决这个问题。

目录

一、简介

二、安装

三、测试

四、capistrano或caphub在企业里真实环境软件自动化部署需求

一、简介

Caphub是一个适合企业应用的自动化部署与回滚软件,他的好处为:

Main idea of caphub is separate deployment and application code. So instead of capify your each project create one caphub repository and put all configurations/recipes there.
Benefits:
no deployment/application code mix.
all deployment located in place.
ability to deploy multiple projects
deployment is not limited application deployment - deploy your system configurations too! (nginx/haproxy/etc configs)
easy to share configurations/recipes among multiple deployment.
uptodate synchronizing with remote repository (with capistrano-uptodate).
generate layout with caphub or write it yourself from scratch with your own recipes

简单的话,如果你有多个项目需要自动化部署的话,多个项目配置文件可以集中放在一个地方,caphub更适合解决这样问题。具体情况看下面的测试。

二、安装

本文的测试环境为ubuntu server 12.04

gem install caphub
caphub caphub_test
root@server:~/capistrano# tree --dirsfirst caphub_test/
caphub_test/
|-- config
|   |-- deploy
|   `-- deploy.rb
|-- recipes
|-- Capfile
|-- Gemfile
`-- Gemfile.lock

初始化gems(initialize gems)

cd caphub_test
bundle install

安装完成后可以使用cap –vT查看任务信息

root@server:~/capistrano/caphub_test# cap -vT
cap deploy                   # Deploys your project.
cap deploy:check             # Test deployment dependencies.
cap deploy:cleanup           # Clean up old releases.
cap deploy:cold              # Deploys and starts a `cold' application.
cap deploy:create_symlink    # Updates the symlink to the most recently deployed version.
cap deploy:finalize_update   # [internal] Touches up the released code.
cap deploy:migrate           # Run the migrate rake task.
cap deploy:migrations        # Deploy and run pending migrations.
cap deploy:pending           # Displays the commits since your last deploy.
cap deploy:pending:diff      # Displays the `diff' since your last deploy.
cap deploy:restart           # Blank task exists as a hook into which to install your own environment specific behaviour.
cap deploy:rollback          # Rolls back to a previous version and restarts.
cap deploy:rollback:cleanup  # [internal] Removes the most recently deployed release.
cap deploy:rollback:code     # Rolls back to the previously deployed version.
cap deploy:rollback:revision # [internal] Points the current symlink at the previous revision.
cap deploy:setup             # Prepares one or more servers for deployment.
cap deploy:start             # Blank task exists as a hook into which to install your own environment specific behaviour.
cap deploy:stop              # Blank task exists as a hook into which to install your own environment specific behaviour.
cap deploy:symlink           # Deprecated API.
cap deploy:update            # Copies your project and updates the symlink.
cap deploy:update_code       # Copies your project to the remote servers.
cap deploy:upload            # Copy files to the currently deployed version.
cap deploy:web:disable       # Present a maintenance page to visitors.
cap deploy:web:enable        # Makes the application web-accessible again.
cap invoke                   # Invoke a single command on the remote servers.
cap multiconfig:ensure       # [internal] Ensure that a configuration has been selected
cap patch                    # Create, deliver and apply patch
cap patch:apply              # Apply patch
cap patch:create             # Create patch
cap patch:deliver            # Deliver patch
cap patch:revert             # Revert patch
cap shell                    # Begin an interactive Capistrano session.
cap uptodate                 # Automatically synchronize current repository
cap uptodate:git             #
Extended help may be available for these tasks.
Type `cap -e taskname' to view it.

由于当前没有创建都是空的

三、测试结合svn的部署

1、内容

先进入到deploy目录

root@server:~/capistrano/caphub_test# cd config/deploy
root@server:~/capistrano/caphub_test/config/deploy# ll
total 12
drwxr-xr-x 2 root root 4096 Jul 30 12:22 ./
drwxr-xr-x 3 root root 4096 Jul 30 10:18 ../
-rw-r--r-- 1 root root    0 Jul 30 10:18 .gitkeep

然后展示一下我的svn部署的内容

root@server:~/capistrano/caphub_test/config/deploy# cat svn.rb
set :application, "test_svn"
set :scm, :subversion
set :repository,  "https://192.168.1.56/svn/ops_manage"
set :scm_username, "denglei"
set :scm_password, "123456"
set :deploy_to, "/tmp/result_svn/ops_manage"
set :normalize_asset_timestamps, false
# set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names
role :web, "192.168.56.101"                          # Your HTTP server, Apache/etc
role :app, "192.168.56.101"                          # This may ber
role :db,  "192.168.56.101", :primary => true # This is where Rails migrations will run
root@server:~/capistrano/caphub_test/config/deploy# ll /tmp/red
redis/                redis.pl              redmine-2.3.1/        redmine-2.3.1.tar.gz  redmine1.sql
root@server:~/capistrano/caphub_test/config/deploy# ll /tmp/red
redis/                redis.pl              redmine-2.3.1/        redmine-2.3.1.tar.gz  redmine1.sql

在看看我的tmp目录下是否有result_svn目录

root@server:~/capistrano/caphub_test/config/deploy# ll /tmp/result_svn
ls: cannot access /tmp/result_svn: No such file or directory

可以看到没有

然后在看看当前的任务信息

root@server:~/capistrano/caphub_test/config/deploy# cap -vT
cap deploy                   # Deploys your project.
cap deploy:check             # Test deployment dependencies.
cap deploy:cleanup           # Clean up old releases.
cap deploy:cold              # Deploys and starts a `cold' application.
cap deploy:create_symlink    # Updates the symlink to the most recently deployed version.
cap deploy:finalize_update   # [internal] Touches up the released code.
cap deploy:migrate           # Run the migrate rake task.
cap deploy:migrations        # Deploy and run pending migrations.
cap deploy:pending           # Displays the commits since your last deploy.
cap deploy:pending:diff      # Displays the `diff' since your last deploy.
cap deploy:restart           # Blank task exists as a hook into which to install your own environment specific behaviour.
cap deploy:rollback          # Rolls back to a previous version and restarts.
cap deploy:rollback:cleanup  # [internal] Removes the most recently deployed release.
cap deploy:rollback:code     # Rolls back to the previously deployed version.
cap deploy:rollback:revision # [internal] Points the current symlink at the previous revision.
cap deploy:setup             # Prepares one or more servers for deployment.
cap deploy:start             # Blank task exists as a hook into which to install your own environment specific behaviour.
cap deploy:stop              # Blank task exists as a hook into which to install your own environment specific behaviour.
cap deploy:symlink           # Deprecated API.
cap deploy:update            # Copies your project and updates the symlink.
cap deploy:update_code       # Copies your project to the remote servers.
cap deploy:upload            # Copy files to the currently deployed version.
cap deploy:web:disable       # Present a maintenance page to visitors.
cap deploy:web:enable        # Makes the application web-accessible again.
cap invoke                   # Invoke a single command on the remote servers.
cap multiconfig:ensure       # [internal] Ensure that a configuration has been selected
cap patch                    # Create, deliver and apply patch
cap patch:apply              # Apply patch
cap patch:create             # Create patch
cap patch:deliver            # Deliver patch
cap patch:revert             # Revert patch
cap shell                    # Begin an interactive Capistrano session.
cap svn                      # Load svn configuration
cap uptodate                 # Automatically synchronize current repository
cap uptodate:git             #
Extended help may be available for these tasks.
Type `cap -e taskname' to view it.

可以看到svn已经被加载上了,下面来真实部署

2、部署

先部署目录

root@server:~/capistrano/caphub_test/config/deploy# cap svn deploy:setup
triggering load callbacks
* 2013-07-30 14:11:29 14:11:29 == Currently executing `uptodate'
* 2013-07-30 14:11:29 14:11:29 == Currently executing `uptodate:git'
* 2013-07-30 14:11:29 14:11:29 == Currently executing `svn'
triggering start callbacks for `deploy:setup'
* 2013-07-30 14:11:29 14:11:29 == Currently executing `multiconfig:ensure'
* 2013-07-30 14:11:29 14:11:29 == Currently executing `deploy:setup'
* executing "sudo -p 'sudo password: ' mkdir -p /tmp/result_svn/ops_manage /tmp/result_svn/ops_manage/releases /tmp/result_svn/ops_manage/shared /tmp/result_svn/ops_manage/shared/system /tmp/result_svn/ops_manage/shared/log /tmp/result_svn/ops_manage/shared/pids"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 3397ms
* executing "sudo -p 'sudo password: ' chmod g+w /tmp/result_svn/ops_manage /tmp/result_svn/ops_manage/releases /tmp/result_svn/ops_manage/shared /tmp/result_svn/ops_manage/shared/system /tmp/result_svn/ops_manage/shared/log /tmp/result_svn/ops_manage/shared/pids"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 146ms

在检测环境

root@server:~/capistrano/caphub_test/config/deploy# cap svn deploy:check
triggering load callbacks
* 2013-07-30 14:11:53 14:11:53 == Currently executing `uptodate'
* 2013-07-30 14:11:53 14:11:53 == Currently executing `uptodate:git'
* 2013-07-30 14:11:53 14:11:53 == Currently executing `svn'
triggering start callbacks for `deploy:check'
* 2013-07-30 14:11:53 14:11:53 == Currently executing `multiconfig:ensure'
* 2013-07-30 14:11:53 14:11:53 == Currently executing `deploy:check'
* executing "test -d /tmp/result_svn/ops_manage/releases"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 803ms
* executing "test -w /tmp/result_svn/ops_manage"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 15ms
* executing "test -w /tmp/result_svn/ops_manage/releases"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 15ms
* executing "which svn"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 20ms
You appear to have all necessary dependencies installed

可以发现没有问题

root@server: ~/capistrano/caphub_test/config/deploy# cap svn deploy:update
triggering load callbacks
* 2013-07-30 14:14:52 14:14:52 == Currently executing `uptodate'
* 2013-07-30 14:14:52 14:14:52 == Currently executing `uptodate:git'
* 2013-07-30 14:14:52 14:14:52 == Currently executing `svn'
triggering start callbacks for `deploy:update'
* 2013-07-30 14:14:52 14:14:52 == Currently executing `multiconfig:ensure'
* 2013-07-30 14:14:52 14:14:52 == Currently executing `deploy:update'
** transaction: start
* 2013-07-30 14:14:52 14:14:52 == Currently executing `deploy:update_code'
executing locally: "svn info https://192.168.1.56/svn/ops_manage --username denglei --password 123456 --no-auth-cache  -rHEAD"
command finished in 728ms
* executing "svn export -q --username denglei --password 123456 --no-auth-cache  -r6 https://192.168.1.56/svn/ops_manage /tmp/result_svn/ops_manage/releases/20130730061453 && (echo 6 > /tmp/result_svn/ops_manage/releases/20130730061453/REVISION)"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 30577ms
* 2013-07-30 14:15:23 14:15:23 == Currently executing `deploy:finalize_update'
* executing "chmod -R -- g+w /tmp/result_svn/ops_manage/releases/20130730061453 && rm -rf -- /tmp/result_svn/ops_manage/releases/20130730061453/public/system && mkdir -p -- /tmp/result_svn/ops_manage/releases/20130730061453/public/ && ln -s -- /tmp/result_svn/ops_manage/shared/system /tmp/result_svn/ops_manage/releases/20130730061453/public/system && rm -rf -- /tmp/result_svn/ops_manage/releases/20130730061453/log && ln -s -- /tmp/result_svn/ops_manage/shared/log /tmp/result_svn/ops_manage/releases/20130730061453/log && rm -rf -- /tmp/result_svn/ops_manage/releases/20130730061453/tmp/pids && mkdir -p -- /tmp/result_svn/ops_manage/releases/20130730061453/tmp/ && ln -s -- /tmp/result_svn/ops_manage/shared/pids /tmp/result_svn/ops_manage/releases/20130730061453/tmp/pids"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 102ms
* 2013-07-30 14:15:23 14:15:23 == Currently executing `deploy:create_symlink'
* executing "sudo -p 'sudo password: ' rm -f /tmp/result_svn/ops_manage/current && sudo -p 'sudo password: ' ln -s /tmp/result_svn/ops_manage/releases/20130730061453 /tmp/result_svn/ops_manage/current"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 295ms
** transaction: commit

从上面的结果可以看到部署成功

下面在到部署目录里看看

root@server:/tmp# cd /tmp/result_svn/ops_manage/
root@server:/tmp/result_svn/ops_manage# ll
total 16
drwxrwxr-x 4 root root 4096 Jul 30 14:15 ./
drwxr-xr-x 3 root root 4096 Jul 30 14:11 ../
lrwxrwxrwx 1 root root   50 Jul 30 14:15 current -> /tmp/result_svn/ops_manage/releases/20130730061453/
drwxrwxr-x 3 root root 4096 Jul 30 14:14 releases/
drwxrwxr-x 5 root root 4096 Jul 30 14:11 shared/
root@server:/tmp/result_svn/ops_manage# cd current
root@server:/tmp/result_svn/ops_manage/current# ll
total 32
drwxrwxr-x 7 root root 4096 Jul 30 14:15 ./
drwxrwxr-x 3 root root 4096 Jul 30 14:14 ../
-rw-rw-r-- 1 root root    2 Jul 30 14:15 REVISION
drwxrwxr-x 3 root root 4096 Jul 30 14:14 branches/
lrwxrwxrwx 1 root root   37 Jul 30 14:15 log -> /tmp/result_svn/ops_manage/shared/log/
drwxr-xr-x 2 root root 4096 Jul 30 14:15 public/
drwxrwxr-x 2 root root 4096 Jul 30 14:15 tags/
drwxr-xr-x 2 root root 4096 Jul 30 14:15 tmp/
drwxrwxr-x 2 root root 4096 Jul 30 14:14 trunk

可以看到有正确的current的连接,更新没有问题。

其他操作话基本就跟capistrano操作一样。

在真实环境部署的话,一般都是setup、check、update同时操作,也就是说可以运行一条命令,就完成之前的这些操作,可以使用namespace完成,下面是我的测试。

root@server:~/capistrano/caphub_test/config/deploy# ll
total 16
drwxr-xr-x 2 root root 4096 Jul 30 14:29 ./
drwxr-xr-x 3 root root 4096 Jul 30 10:18 ../
-rw-r--r-- 1 root root    0 Jul 30 10:18 .gitkeep
-rw-r--r-- 1 root root  400 Jul 30 12:07 ops_manage_from_svn_install.rb
-rw-r--r-- 1 root root  633 Jul 30 14:07 svn.rb
root@server:~/capistrano/caphub_test/config/deploy# vim ops_manage_from_svn_install.rb
root@server:~/capistrano/caphub_test/config/deploy# ll
total 16
drwxr-xr-x 2 root root 4096 Jul 30 14:30 ./
drwxr-xr-x 3 root root 4096 Jul 30 10:18 ../
-rw-r--r-- 1 root root    0 Jul 30 10:18 .gitkeep
-rw-r--r-- 1 root root  155 Jul 30 14:30 ops_manage_from_svn_install.rb
-rw-r--r-- 1 root root  633 Jul 30 14:07 svn.rb
root@server:~/capistrano/caphub_test/config/deploy# cat ops_manage_from_svn_install.rb
namespace :ops_manage do
task :install do
system("cap svn deploy:setup")
system("cap svn deploy:check")
system("cap svn deploy:update")
end
end

然后查看当前的任务信息

root@server:~/capistrano/caphub_test/config/deploy# cap -vT
cap deploy                      # Deploys your project.
cap deploy:check                # Test deployment dependencies.
cap deploy:cleanup              # Clean up old releases.
cap deploy:cold                 # Deploys and starts a `cold' application.
cap deploy:create_symlink       # Updates the symlink to the most recently deployed version.
cap deploy:finalize_update      # [internal] Touches up the released code.
cap deploy:migrate              # Run the migrate rake task.
cap deploy:migrations           # Deploy and run pending migrations.
cap deploy:pending              # Displays the commits since your last deploy.
cap deploy:pending:diff         # Displays the `diff' since your last deploy.
cap deploy:restart              # Blank task exists as a hook into which to install your own environment specific behaviour.
cap deploy:rollback             # Rolls back to a previous version and restarts.
cap deploy:rollback:cleanup     # [internal] Removes the most recently deployed release.
cap deploy:rollback:code        # Rolls back to the previously deployed version.
cap deploy:rollback:revision    # [internal] Points the current symlink at the previous revision.
cap deploy:setup                # Prepares one or more servers for deployment.
cap deploy:start                # Blank task exists as a hook into which to install your own environment specific behaviour.
cap deploy:stop                 # Blank task exists as a hook into which to install your own environment specific behaviour.
cap deploy:symlink              # Deprecated API.
cap deploy:update               # Copies your project and updates the symlink.
cap deploy:update_code          # Copies your project to the remote servers.
cap deploy:upload               # Copy files to the currently deployed version.
cap deploy:web:disable          # Present a maintenance page to visitors.
cap deploy:web:enable           # Makes the application web-accessible again.
cap invoke                      # Invoke a single command on the remote servers.
cap multiconfig:ensure          # [internal] Ensure that a configuration has been selected
cap ops_manage_from_svn_install # Load ops_manage_from_svn_install configuration
cap patch                       # Create, deliver and apply patch
cap patch:apply                 # Apply patch
cap patch:create                # Create patch
cap patch:deliver               # Deliver patch
cap patch:revert                # Revert patch
cap shell                       # Begin an interactive Capistrano session.
cap svn                         # Load svn configuration
cap uptodate                    # Automatically synchronize current repository
cap uptodate:git                #
Extended help may be available for these tasks.
Type `cap -e taskname' to view it.

然后使用cap ops_manage_from_svn_install ops_manage:install

root@ server:~/capistrano/caphub_test/config/deploy# cap ops_manage_from_svn_install ops_manage:install
triggering load callbacks
* 2013-07-30 14:32:23 14:32:23 == Currently executing `uptodate'
* 2013-07-30 14:32:23 14:32:23 == Currently executing `uptodate:git'
* 2013-07-30 14:32:23 14:32:23 == Currently executing `ops_manage_from_svn_install'
triggering start callbacks for `ops_manage:install'
* 2013-07-30 14:32:23 14:32:23 == Currently executing `multiconfig:ensure'
* 2013-07-30 14:32:23 14:32:23 == Currently executing `ops_manage:install'
triggering load callbacks
* 2013-07-30 14:32:24 14:32:24 == Currently executing `uptodate'
* 2013-07-30 14:32:24 14:32:24 == Currently executing `uptodate:git'
* 2013-07-30 14:32:24 14:32:24 == Currently executing `svn'
triggering start callbacks for `deploy:setup'
* 2013-07-30 14:32:24 14:32:24 == Currently executing `multiconfig:ensure'
* 2013-07-30 14:32:24 14:32:24 == Currently executing `deploy:setup'
* executing "sudo -p 'sudo password: ' mkdir -p /tmp/result_svn/ops_manage /tmp/result_svn/ops_manage/releases /tmp/result_svn/ops_manage/shared /tmp/result_svn/ops_manage/shared/system /tmp/result_svn/ops_manage/shared/log /tmp/result_svn/ops_manage/shared/pids"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 1100ms
* executing "sudo -p 'sudo password: ' chmod g+w /tmp/result_svn/ops_manage /tmp/result_svn/ops_manage/releases /tmp/result_svn/ops_manage/shared /tmp/result_svn/ops_manage/shared/system /tmp/result_svn/ops_manage/shared/log /tmp/result_svn/ops_manage/shared/pids"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 337ms
triggering load callbacks
* 2013-07-30 14:32:26 14:32:26 == Currently executing `uptodate'
* 2013-07-30 14:32:26 14:32:26 == Currently executing `uptodate:git'
* 2013-07-30 14:32:26 14:32:26 == Currently executing `svn'
triggering start callbacks for `deploy:check'
* 2013-07-30 14:32:26 14:32:26 == Currently executing `multiconfig:ensure'
* 2013-07-30 14:32:26 14:32:26 == Currently executing `deploy:check'
* executing "test -d /tmp/result_svn/ops_manage/releases"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 850ms
* executing "test -w /tmp/result_svn/ops_manage"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 21ms
* executing "test -w /tmp/result_svn/ops_manage/releases"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 19ms
* executing "which svn"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 24ms
You appear to have all necessary dependencies installed
triggering load callbacks
* 2013-07-30 14:32:28 14:32:28 == Currently executing `uptodate'
* 2013-07-30 14:32:28 14:32:28 == Currently executing `uptodate:git'
* 2013-07-30 14:32:28 14:32:28 == Currently executing `svn'
triggering start callbacks for `deploy:update'
* 2013-07-30 14:32:28 14:32:28 == Currently executing `multiconfig:ensure'
* 2013-07-30 14:32:28 14:32:28 == Currently executing `deploy:update'
** transaction: start
* 2013-07-30 14:32:28 14:32:28 == Currently executing `deploy:update_code'
executing locally: "svn info https://192.168.1.56/svn/ops_manage --username denglei --password 123456 --no-auth-cache  -rHEAD"
command finished in 740ms
* executing "svn export -q --username denglei --password 123456 --no-auth-cache  -r6 https://192.168.1.56/svn/ops_manage /tmp/result_svn/ops_manage/releases/20130730063229 && (echo 6 > /tmp/result_svn/ops_manage/releases/20130730063229/REVISION)"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 30404ms
* 2013-07-30 14:32:59 14:32:59 == Currently executing `deploy:finalize_update'
* executing "chmod -R -- g+w /tmp/result_svn/ops_manage/releases/20130730063229 && rm -rf -- /tmp/result_svn/ops_manage/releases/20130730063229/public/system && mkdir -p -- /tmp/result_svn/ops_manage/releases/20130730063229/public/ && ln -s -- /tmp/result_svn/ops_manage/shared/system /tmp/result_svn/ops_manage/releases/20130730063229/public/system && rm -rf -- /tmp/result_svn/ops_manage/releases/20130730063229/log && ln -s -- /tmp/result_svn/ops_manage/shared/log /tmp/result_svn/ops_manage/releases/20130730063229/log && rm -rf -- /tmp/result_svn/ops_manage/releases/20130730063229/tmp/pids && mkdir -p -- /tmp/result_svn/ops_manage/releases/20130730063229/tmp/ && ln -s -- /tmp/result_svn/ops_manage/shared/pids /tmp/result_svn/ops_manage/releases/20130730063229/tmp/pids"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 229ms
* 2013-07-30 14:32:59 14:32:59 == Currently executing `deploy:create_symlink'
* executing "sudo -p 'sudo password: ' rm -f /tmp/result_svn/ops_manage/current && sudo -p 'sudo password: ' ln -s /tmp/result_svn/ops_manage/releases/20130730063229 /tmp/result_svn/ops_manage/current"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 322ms
** transaction: commit

这样的好处是一个命令完成所有操作方便。

四、capistranocaphub在企业里真实环境软件自动化部署需求

1、之前测试的只是普通情况下,但如果在有更深入需求,比如部署关闭服务,然后在部署,完成后在启动服务,该如何解决?

可以使用namespace解决,可以使用类似下面的方式。

root@ server:~/capistrano/caphub_test/config/deploy#cat ops_manage_from_svn_install.rb
namespace :ops_manage do
task :install do
system("stop server")
system("cap svn deploy:setup")
system("cap svn deploy:check")
system("cap svn deploy:update")
system("start server")
end
end

2、如果还有更复杂的要求,除了上面要求的那些,还需要保存之前数据库连接文件的配置,其他的需要更新,也就是说比如之前的版本为1,需要更新的版本为2,版本1里的数据库连接文件为oldfile,版本2里数据库连接文件为newfile,此次有版本1更新到版本2,除了oldfile不更新,其他全部更新,该如何的做?

可以使用下面方法

root@ubuntu:/tmp/caphub/test/config/deploy# cat ops_manage_from_svn_install.rb
namespace :ops_manage do
task :install do
system("stop server")
system("mv path/oldfile /tmp/oldfile")
system("cap svn deploy:setup")
system("cap svn deploy:check")
system("cap svn deploy:update")
system("rm -rf path/newfile")
system("mv /tmp/oldfile path/oldfile")
system("start server")
end
end

更新前先把oldfile放到另外一个目录里保存,然后在更新,之后再把新的配置文件删除,在把更新前的旧配置文件复制回来。

总结:第2步还是比较简单,而且如果svn或者git的库非常大,但每次更新的时候就直说单独的更新几个文件,虽然使用第2步也可以实现,但性能比较低,而且部署完成后,如果你想测试,比如你部署完成后,想看看网页的返回码是否为200,或者其他结果,都需要你自己手动的写,所以感觉caphub还是有点欠缺,之后准备自己使用python写个web界面的代码部署软件,包括caohub的所有功能与完成后结果测试,所以希望大家能多提出一下你在自动部署代码与回滚软件的需求。

顺便说一下,目前github里有个软件webistrano,他是capistrano的web版本,大家也可以尝试看一下。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值