{"id":1677,"date":"2007-08-28T00:32:22","date_gmt":"2007-08-27T16:32:22","guid":{"rendered":"http:\/\/ihower.idv.tw\/blog\/archives\/1677"},"modified":"2013-01-25T11:47:33","modified_gmt":"2013-01-25T03:47:33","slug":"capistrano-deployment","status":"publish","type":"post","link":"https:\/\/ihower.tw\/blog\/1677-capistrano-deployment","title":{"rendered":"Capistrano \u81ea\u52d5\u5316 deploy Rails"},"content":{"rendered":"<p> <a href=\"http:\/\/www.capify.org\/\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.rubyinside.com\/wp-content\/uploads\/2007\/06\/capistrano-logo-small.png\" height=\"70\" width=\"185\" \/><\/a><\/p>\n<p>\u4eca\u5929\u82b1\u4e86\u9ede\u6642\u9593\u5728\u81ea\u5df1\u7684 server(FreeBSD) \u4e0a\u8a66\u7528 Capistrano\uff0c\u9019\u662f\u4e00\u5957\u8b93\u4f60\u5728 local \u900f\u904e SSH \u81ea\u52d5\u57f7\u884c\u9060\u7aef\u4efb\u52d9\u7684 deployment system\uff0c\u7576\u7136\u6700\u5e38\u898b\u7684\u61c9\u7528\u5c31\u662f deploying Rails applications \u4e86\u3002<\/p>\n<p>\u8001\u5be6\u8aaa\uff0c\u7b2c\u4e00\u6b21\u7684\u8a2d\u5b9a\u9084\u771f\u8b93\u6211 try and error\uff0c\u5c24\u5176\u524d\u4e00\u9663\u5b50\u525b\u51fa Capistrano 2.0 \u7248\uff0c\u8b8a\u66f4\u4e86\u4e00\u4e9b\u7528\u6cd5\uff0c\u6240\u4ee5\u5f88\u591a\u820a\u7bc4\u4f8b\u5c31\u4e0d\u6562\u7528\u4e86\uff0c\u800c\u5b98\u7db2\u4e0a\u7684\u6587\u4ef6\u4e5f\u5be6\u5728\u6709\u9ede\u7c21\u7565\u8aaa&#8230; ^^@ \u5176\u4e2d\u95dc\u65bc the &#8220;spin&#8221; script \u7684\u90e8\u4efd\u4e0d\u751a\u89e3\u539f\u7406(?)\uff0c\u6700\u5f8c\u7684\u505a\u6cd5\u9664\u4e86\u8b93\u767b\u5165\u7684\u5e33\u865f\u6709 sudo \u6b0a\u9650\uff0c\u4e5f\u9700\u8981\u5148\u624b\u52d5\u767b\u5165\u57f7\u884c\u7b2c\u4e00\u6b21\u7684\u555f\u52d5 sudo script\/process\/spin\u3002<\/p>\n<p>anyway&#8230; \u9084\u662f\u7167\u8457 <a href=\"http:\/\/www.capify.org\/getting-started\/rails\">Getting Started<\/a> \u914d\u8457\u904e\u6642\u7684 AWDwR 2nd. Chap 27 \u4f86\u505a\uff0c\u503c\u5f97\u6ce8\u610f\u7684\u6709<\/p>\n<p>svn \u7684\u5e33\u865f\u5bc6\u78bc\u8981\u9019\u6a23\u8a2d\u5b9a<\/p>\n<blockquote><p>set :scm_username, &#8220;username&#8221; # svn user name<br \/>\nset :scm_password, &#8220;password&#8221;<\/p><\/blockquote>\n<p>\u53e6\u5916\u4f60\u61c9\u8a72\u4e0d\u6703\u628a database.yml \u7d66 commit \u51fa\u53bb\uff0c\u6240\u4ee5\u5148\u5efa\u7acb\u597d\u4e00\u4efd\u4f86\u505a\u8907\u88fd\u3002<\/p>\n<blockquote><p>namespace :deploy do<br \/>\ndesc &#8220;Create database.yml &#8221;<br \/>\ntask :after_update_code, :roles =&gt; [:web] do<br \/>\ndb_config = &#8220;#{shared_path}\/config\/database.yml.production&#8221;<br \/>\nrun &#8220;cp #{db_config} #{release_path}\/config\/database.yml;&#8221;<br \/>\nend<br \/>\nend<\/p><\/blockquote>\n<p>\u6700\u5f8c\u7684\u6210\u679c\u662f\u53ea\u8981\u6253 cap deploy\uff0c\u5c31\u6703\u81ea\u52d5\u9023\u5230 server \u4e0a\uff0c\u57f7\u884c svn checkout \u51fa\u6700\u65b0\u7248\u672c\uff0c\u8dd1\u4e9b\u5ba2\u88fd\u7684 script\uff0c\u7136\u5f8c\u91cd\u65b0 restart mongrel cluster\u3002<\/p>\n<p>\u70ba\u751a\u9ebc Capistrano \u9019\u9ebc\u88ab\u91cd\u8996\u5462? \u9019\u7a2e  deploy \u7684\u904e\u7a0b\uff0c\u5176\u5be6\u5fc5\u5b9a\u662f\u500b\u4e00\u518d\u57f7\u884c\u7684\u904e\u7a0b(\u55ef\uff0c\u9664\u975e\u4e0d\u9700\u8981\u518d\u958b\u767c\u5347\u7d1a\u4e86)\uff0c\u800c\u4e14\u96a8\u8005\u6642\u9593\u6f14\u9032\uff0c\u9019\u500b\u904e\u7a0b\u5e38\u5e38\u6703\u6709\u5404\u7a2e\u5ba2\u88fd\u7684 script \u8981\u57f7\u884c\uff0c\u4f8b\u5982\u6a94\u6848\u8b8a\u66f4\/\u91cd\u65b0\u8f09\u5165 config\/\u6e05\u9664 cache&#8230;etc<\/p>\n<p>\u7136\u800c\u5728\u767c\u884c\u65b0\u7248\u672c\u7684\u6642\u5019\uff0c\u5f80\u5f80\u537b\u4e5f\u662f\u5df2\u7d93\u5beb\u4e86\u597d\u591a\u7a0b\u5f0f\uff0c\u7d2f\u7684\u8981\u547d\u7684\u6642\u5019\uff0c\u9019\u6642\u5019\u4e00\u500b\u5df2\u7d93\u81ea\u52d5\u5316\u7684 deploy process \u5c31\u50cf\u7518\u9716\u9732\u6c34\uff0c\u4f60\u4e0d\u6703\u60f3\u4e00\u500b\u500b\u624b\u52d5\u57f7\u884c\u90a3\u4e9b\u8907\u96dc\u6b65\u9a5f\u7684(\u800c\u4e14\u842c\u4e00\u6f0f\u505a\u4e86\u751a\u9ebc\uff0c\u90fd\u662f\u7121\u53ef\u9810\u671f\u7684 disaster )\u3002<\/p>\n<p>Update(2007\/9\/1): \u6539\u5728 Mac \u4e0a\u505a deploy\uff0c\u53c8\u5361\u95dc\u4e86\u597d\u4e45:<\/p>\n<p>\u628a \/script\/process\/spin \u7684\u5167\u5bb9\u6539\u6210\u6163\u7528\u7684 mongrel_rails cluster::restart\u3002<\/p>\n<p>depoly.rb \u4e2d\u6240\u6709  run rake \u7684\u5730\u65b9\uff0c\u591a\u52a0\u5b8c\u6574 rake \u8def\u5f91\u3002\u4ee5\u53ca set :rake, &#8220;\/opt\/local\/bin\/rake&#8221;<\/p>\n<p>\u6211\u66ab\u6642\u6c92\u6709\u958b sudo \u6b0a\u9650\uff0c\u6240\u4ee5 cap deploy \u7684\u6700\u5f8c\u4e00\u6b65 restart \u6703\u5931\u6557\uff0c\u5230\u9019\u88e1\u5c31\u53ea\u597d\u624b\u52d5\u56c9\u3002<\/p>\n<p>Update(2007\/9\/4): \u95dc\u65bc sudo\uff0c\u61c9\u8a72\u518d\u65b0\u589e\u4ee5\u4e0b\u8a2d\u5b9a<\/p>\n<blockquote><p>set :use_sudo, false<\/p><\/blockquote>\n<p><strike>\u81f3\u6b64\u61c9\u8a72\u4e00\u6b65 cap deploy  \u5c31\u53ef\u4ee5\u641e\u5b9a\u4e86&#8230; :)<\/strike><\/p>\n<p>Update(2007\/9\/5): \u771f\u662f\u4e00\u5929\u4e00\u725b\u6b65\u5728\u4fee\u9019\u500b script\uff0c\u8acb\u518d\u52a0\u4e0a\u74b0\u5883\u8b8a\u6578 (\u56e0\u70ba Capistrano \u7528 SSH \u767b\u5165\u5f8c\u4e26\u4e0d\u6703\u8b80\u53d6\u4f60\u7684\u74b0\u5883\u8b8a\u6578\u554a~)\uff0c\u9084\u6709 deploy:restart \u4e5f\u91cd\u5beb\u904e\u5427\uff0c\u4e0d\u9700\u8981\u4f7f\u7528 \/script\/process\/spin :<\/p>\n<blockquote><p>default_environment[&#8220;PATH&#8221;] = &#8220;\/Users\/ihower\/bin:\/opt\/local\/bin:\/bin:\/sbin:\/usr\/bin:\/usr\/sbin&#8221;<\/p><\/blockquote>\n<blockquote><p> desc &#8220;Restart Mongrel&#8221;<br \/>\ntask :restart, :roles =&gt; [:app] do<br \/>\nrun &lt;&lt;-EOF<br \/>\ncd #{current_path} &amp;&amp; mongrel_rails cluster::restart<br \/>\nEOF<br \/>\nend<\/p><\/blockquote>\n<p>\u81f3\u6b64\u7d42\u65bc\u4e00\u6b65 cap deploy  \u5c31\u53ef\u4ee5\u641e\u5b9a\u4e86(Mac)&#8230; :)<\/p>\n<p>by the way&#8230;\u89e3\u91cb\u4e00\u4e0b\u67b6\u69cb\uff0c\u9019\u908a\u662f\u7528 mongrel_rails cluster \u8dd1\u5728\u4e00\u7fa4 ports \u4e0a(\u4f8b\u59828000~8002)\uff0c\u518d\u642d\u914d Apache Proxy \u6a5f\u5236\u628a HTTP request balance \u5230\u5404\u500b mongrel \u4e0a\u3002\u9019\u662f\u76ee\u524d deploy rails \u6700\u5efa\u8b70\u7684 solution\u3002<\/p>\n<p>\u95dc\u65bc apache settings \u7167\u6284 AWDwR 2nd. \u7684\u5c31\u53ef\u4ee5 work \u4e86\uff0c\u8dd1 cap deploy \u7684\u6642\u5019\u4e5f\u4e0d\u9700\u8981\u91cd\u958b apache\uff0c\u9019\u5169\u500b\u5143\u4ef6\u662f\u7368\u7acb\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u82b1\u4e86\u9ede\u6642\u9593\u5728\u81ea\u5df1\u7684 server(FreeBSD) \u4e0a\u8a66\u7528 Capistrano\uff0c\u9019\u662f\u4e00\u5957\u8b93\u4f60\u5728 loca &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/ihower.tw\/blog\/1677-capistrano-deployment\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008Capistrano \u81ea\u52d5\u5316 deploy Rails\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[68,53,31],"tags":[],"class_list":["post-1677","post","type-post","status-publish","format-standard","hentry","category-devops","category-rails","category-ruby","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1q6tG-r3","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/1677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/comments?post=1677"}],"version-history":[{"count":2,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/1677\/revisions"}],"predecessor-version":[{"id":7357,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/1677\/revisions\/7357"}],"wp:attachment":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/media?parent=1677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/categories?post=1677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/tags?post=1677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}