Capistrano and Jenkins can be used together to automate the build, deployment, and management of Java web applications on clusters of servers. Capistrano allows deploying code to multiple servers and managing services, while Jenkins provides continuous integration by automatically building, testing, and deploying code changes to different environments like development, testing, and production. When a build succeeds in Jenkins, it can trigger Capistrano tasks to deploy the new code to servers and restart services. This achieves automated and versioned software releases across server clusters.
28. Hello, world! #!/usr/bin/ruby load'deploy' role:app,"10.241.12.44","10.241.12.45","10.241.12.46" set:user,"tangliqun" namespace:hellodo task:worlddo run"echo Hello, world!" run"cat /etc/passwd" end end 执行: cap hello:world
29. 现实例子 #!/usr/bin/ruby load'deploy' require'cap_recipes/tasks/tomcat' set :application, "message-admin" set :war, File.dirname(__FILE__)+"/message/target/message-admin.war" role :webserver, "10.241.12.44","10.241.12.45","10.241.12.46" set :user, "tomcat6" set :tomcat_home, "/usr/local/apache-tomcat-6.0.29" set :tomcat_ctrl, "/etc/init.d/tomcat" set :deploy_dir, "/srv/applications"
41. 管理集群服务器上的服务 desc "start tomcat" task :start do sudo "#{tomcat_ctrl} start" end desc "stop tomcat" task :stop do sudo "#{tomcat_ctrl} stop" end desc "stop and start tomcat" task :restart do tomcat.stop tomcat.start end