require'rubygems'require'mqtt'# Publish exampleMQTT::Client.connect('mqtt://glassx:glassxpw@127.0.0.1')do|c|pc.publish('topic','message')end# # Subscribe example# MQTT::Client.connect('test.mosquitto.org') do |c|# # If you pass a block to the get method, then it will loop# c.get('test') do |topic,message|# puts "#{topic}: #{message}"# end# end
set:domains,%w[192.168.0.12 192.168.0.13]desc"multi deploy"task:multi_deploydodomains.each_with_indexdo|domain,index|p"begin to deploy#{domain}"set:domain,domaininvoke:deployrun!=># 注意这里一定要加上 run! ,才会立即运行命令p"finish to deploy"endend
task:deploy_primarydop"begin to deploy primary #{primary_domain}"set:domain,primary_domaininvoke:deployinvoke:mysql_syncrun!p"finish to deploy primary #{primary_domain}"pcommandsend
task:deploy_alldoisolatedo2.timesdo|sequence|p"begin to deploy #{sequence}"ifsequence==0set:deploy_to,'/home/deploy/xshare_en'elseset:deploy_to,'/home/deploy/xshare_zh'endinvoke:deployrun!p"end to deploy #{sequence}"endendend
# Load DSL and Setup Up Stagesrequire'capistrano/setup'# Includes default deployment tasksrequire'capistrano/deploy'# 配置支持的插件require'capistrano/rvm'require'capistrano/bundler'require'capistrano/rails/assets'require'capistrano/rails/migrations'# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.Dir.glob('lib/capistrano/tasks/*.rake').each{|r|importr}
# config valid only for Capistrano 3.1lock'3.2.1'set:application,'student_lottery'set:repo_url,'git@bitbucket.org:linjunzhugg/student_lottery.git'# Default branch is :master# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call# Default deploy_to directory is /var/www/my_appset:deploy_to,'/home/deploy/student_lottery'# Default value for :scm is :gitset:scm,:git# Default value for :format is :pretty# set :format, :pretty# Default value for :log_level is :debug# set :log_level, :debug# Default value for :pty is false# set :pty, true# Default value for :linked_files is []set:linked_files,%w{config/database.yml}# Default value for linked_dirs is []set:linked_dirs,%w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}set:rvm_ruby_version,'ruby-2.0.0-p481@rails4.0.4'# Default value for default_env is {}# set :default_env, { path: "/opt/ruby/bin:$PATH" }# Default value for keep_releases is 5# set :keep_releases, 5namespace:deploydodesc'Restart application'task:restartdoonroles(:app),in::sequence,wait:5do# Your restart mechanism here, for example:# execute :touch, release_path.join('tmp/restart.txt')endend# 就是这里插入的任务after:publishing,:restartafter:restart,:clear_cachedoonroles(:web),in::groups,limit:3,wait:10do# Here we can do anything such as:# within release_path do# execute :rake, 'cache:clear'# endendendend
config/production.rb
1234
set:branch,'master'# roles 的存在是方便我们针对某个 role 来执行相应的 taskserver'192.168.0.13',user:'deploy',roles:%w{app, web}set:rails_env,:production