上周给大家介绍了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

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

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

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版本,大家也可以尝试看一下。

转载于:https://blog.51cto.com/dl528888/1276174

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

  1. Jenkins进阶-Gitlab使用Webhook实现Push代码自动部署(3)

    2019独角兽企业重金招聘Python工程师标准>>> Jenkins进阶-Gitlab使用Webhook实现Push代码自动部署(3) 博客分类: 运维 1.Jenkins 安装完 ...

  2. java 实现自动生成部署文档_jenkins的部署、实现自动拉取gitlab仓库代码、实现项目中代码自动部署以及项目关联触发......

    jenkins主机内存和gitlab主机内存最好配置4G及以上,防止各自的web端打不开 1.配置JDK环境 1)jdk解压到此目录 [root@localhost src]# pwd /usr/lo ...

  3. 在idea里如何实现Git项目回滚

    在idea里如何实现Git项目回滚 先我们要回滚的项目右键,如下: 点击Git,再点击Show History 选择你要回滚的分支 然后右键,如下: 点击Copy  Revision  Number ...

  4. GITLAB JENKINS代码自动部署

    1.前提 部署 jenkins 安装jenkins插件GitGitlabGitlab HookPublish Over SSHSSH AgentGit Paramete 部署 gitlab 2.JEN ...

  5. mysql自动生成回滚语句_如何根据sql语句逆向生成回滚语句?

    当启动Binlog后,事务会产生Binlog Event,这些Event被看做事务数据的一部分.因此要保证事务的Binlog Event和InnoDB引擎中的数据的一致性.所以带Binlog的Cras ...

  6. java 自定义异常 未回滚_抛出自定义异常,spring AOP事务不回滚的解决方案

    spring AOP 默认对RuntimeException()异常或是其子类进行事务回滚,也就是说 事务回滚:throw new RuntimeException("xxxxxxxxxxx ...

  7. 搭建Git服务器环境----Git hooks代码自动部署

    引言:自己想搭一套git的服务端环境,不想用github码云等.经多方资料整合,实验总结,以下是亲测有效的方式.可用于公司日常开发 一.搭建Git环境 ① 安装 Git Linux 做为服务器端系统, ...

  8. centos 7 备份代码,然后回滚

    1.先备份 tar cvf english.20190822.tar webapps/ 备份完后,就出现了该这个压缩文件了 2.把webapps 文件夹移到上一级目录或者直接删掉该目录 mv weba ...

  9. github代码虚拟服务器,把github代码自动部署到服务器

    MVC的JsonResult用法 在Asp.net Mvc 2中由于对数据的保护,默认情况下request为post,所以在前端请求的时候则需要以post方式request action方法: pub ...

最新文章

  1. java内部类gc_Java内部类持有外部类的引用详细分析与解决方案
  2. AI 在携程智能客服的应用
  3. 软件单元测试工具比较
  4. 被Facebook终止合作,被谷歌下架,股价营收皆腰斩,猎豹只剩AI一根救命稻草了...
  5. 【Linux】关于ffmpeg的一些常见用法
  6. 比特币详解3.0 ——区块链的救赎
  7. 计算机视觉 | 计算机视觉相关算法及工具
  8. c++ template笔记(1)模板函数
  9. Pythton3实例
  10. 启动django项目 默认启动与指定端口启动
  11. 是的,我们真的在遭遇有史以来最大的DDoS攻击,并且还在加剧
  12. Linux内核抢占实现机制分析
  13. pkg打包node工程
  14. Steven H. Simon《The Oxford Solid State Basics》(史蒂文·H·西蒙《牛津固态物理学基础》)中文目录
  15. 谢烟客---------Linux之用户
  16. JAVA——JAVA知识点集锦(上)
  17. 浅谈 Unity、iOS、Android 闭包的使用方法
  18. RUOYI 框架教程 1 |小白都能学会的 3 分钟搭建框架教程
  19. 递归函数的简单应用-第五个学生的年龄
  20. TITAN RTX 与 RTX 3090 参数的对比,探计单双精度的问题

热门文章

  1. 老大说,网上这种获取真实IP地址的方法不对,我不信...
  2. 惊:FastThreadLocal吞吐量居然是ThreadLocal的3倍!!!
  3. OpenResty 最佳实践
  4. 从0梳理1场CV大赛(Top 3%)!
  5. 机器学习中的L1与L2正则化图解!
  6. 一行命令堆出你的新垣结衣,不爆肝也能创作ASCII Art
  7. 精度45.9%,推理速度72.9FPS,百度飞桨推出工业级目标检测模型 PP-YOLO
  8. 给大家介绍一位中科院师兄,读研时通过实习和比赛收入五十万
  9. 重上热搜!北师大教授:给非洲留学生1年10万奖学金真的不算多!
  10. 1470篇!CVPR2020结果出炉(附13篇论文链接/开源代码/解读)