<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>capistrano mina deployment on random thoughts</title><link>https://awesomeprogrammer.com/categories/capistrano-mina-deployment/</link><description>Recent content in capistrano mina deployment on random thoughts</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sun, 19 May 2013 00:00:00 +0000</lastBuildDate><atom:link href="https://awesomeprogrammer.com/categories/capistrano-mina-deployment/index.xml" rel="self" type="application/rss+xml"/><item><title>How to migrate from Mina to Capistrano</title><link>https://awesomeprogrammer.com/blog/2013/05/19/how-to-migrate-from-mina-to-capistrano/</link><pubDate>Sun, 19 May 2013 00:00:00 +0000</pubDate><guid>https://awesomeprogrammer.com/blog/2013/05/19/how-to-migrate-from-mina-to-capistrano/</guid><description><![CDATA[<p>It&rsquo;s been a while since I last posted here. I&rsquo;ve been pretty busy with work, I&rsquo;ve also moved to Cracov in the meantime - so yeah, I can&rsquo;t really complaint about boredom ;).</p>
<p>Anyhow, some time ago I posted <a href="/blog/2012/10/27/super-fast-deployment-with-mina-capistrano-alternative/">about Mina</a> - neat little gem that allows super fast deployments. Unfortunately when your project grows you start adding additional bash scripts, you add more and more commands to your deploy script and it grows into something not-so-neat anymore.</p>
<p>That&rsquo;s why tempted with Capistrano&rsquo;s ready-to-use recipes I decided it&rsquo;s time to say hello to Capistrano. I&rsquo;ll provide here step-by-step migration process from Mina. I will be using here <a href="https://github.com/collectiveidea/delayed_job">delayed_job</a>, <a href="http://unicorn.bogomips.org/">unicorn</a> (with <a href="https://github.com/sosedoff/capistrano-unicorn">capistrano-unicorn</a> gem) and <a href="https://github.com/pat/thinking-sphinx">thinking-sphinx</a>.</p>
<p>First, install <a href="https://github.com/capistrano/capistrano">Capistrano</a> and capify your project with command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>capify .
</span></span></code></pre></div><p>(I assume you need only one deployment environment) Go to <code>config/deploy.rb</code> and add some recipes that are provided by thinking-sphinx, delayed_job and capistrano-unicorn:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>require <span style="color:#e6db74">&#34;delayed/recipes&#34;</span>
</span></span><span style="display:flex;"><span>require <span style="color:#e6db74">&#34;thinking_sphinx/capistrano&#34;</span>
</span></span><span style="display:flex;"><span>require <span style="color:#e6db74">&#34;capistrano-unicorn&#34;</span>
</span></span></code></pre></div><p>When you run <code>cap -T</code> in your console you will get the list of available commands that should include newly added toys, isn&rsquo;t that nice? As always I recommend reading provided manual(s) before proceeding further (especially if you&rsquo;re using thinking-sphinx, a lot of stuff is happening after simply requiring its recipe).</p>
<p>Next setup your application repository:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>set <span style="color:#e6db74">:application</span>, <span style="color:#e6db74">&#34;app name&#34;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:repository</span>,  <span style="color:#e6db74">&#34;repo path&#34;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:scm</span>, <span style="color:#e6db74">:git</span> <span style="color:#75715e"># or whatever you use, this can be guessed by Capistrano if not provided</span>
</span></span></code></pre></div><p>Now we will setup a destination machine. I&rsquo;m running my app on shared host and I need to connect to my destination (web) server through shell server first. But in my case that is not enough - I&rsquo;ll need also provide separate ssh key and set proper PATH and RUBY_VER values so it all works nicely.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>server <span style="color:#e6db74">&#39;destination server&#39;</span>, <span style="color:#e6db74">:app</span>, <span style="color:#e6db74">:web</span>, <span style="color:#e6db74">:db</span>, <span style="color:#e6db74">:primary</span> <span style="color:#f92672">=&gt;</span> <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:gateway</span>, <span style="color:#e6db74">&#39;shell server&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:deploy_to</span>, <span style="color:#e6db74">&#39;my deploy path&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:user</span>, <span style="color:#e6db74">&#39;my login&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:use_sudo</span>, <span style="color:#66d9ef">false</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:default_environment</span>, {
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#39;PATH&#39;</span>     <span style="color:#f92672">=&gt;</span> <span style="color:#e6db74">&#39;path dependent values&#39;</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#39;RUBY_VER&#39;</span> <span style="color:#f92672">=&gt;</span> <span style="color:#e6db74">&#39;1.9&#39;</span> <span style="color:#75715e"># This is required by my shared host provider</span>
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:rake</span>, <span style="color:#e6db74">&#39;bundle exec rake&#39;</span> <span style="color:#75715e"># and I need to run everything through bundler,</span>
</span></span><span style="display:flex;"><span>                              <span style="color:#75715e"># because I&#39;m installing gem to my home directory</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>ssh_options<span style="color:#f92672">[</span><span style="color:#e6db74">:keys</span><span style="color:#f92672">]</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">%w(~/.ssh/my_private_key ~/.ssh/my_web_server_key)</span> <span style="color:#75715e"># Capistrano will try each key</span>
</span></span><span style="display:flex;"><span>                                                                        <span style="color:#75715e"># and I need a different one when</span>
</span></span><span style="display:flex;"><span>                                                                        <span style="color:#75715e"># connecting to destination server</span>
</span></span><span style="display:flex;"><span>                                                                        <span style="color:#75715e"># through shell server</span>
</span></span></code></pre></div><p>Now let&rsquo;s set some Rails env variables:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>set <span style="color:#e6db74">:default_env</span>, <span style="color:#e6db74">&#39;production&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:rails_env</span>, <span style="color:#66d9ef">ENV</span><span style="color:#f92672">[</span><span style="color:#e6db74">&#39;RAILS_ENV&#39;</span><span style="color:#f92672">]</span> <span style="color:#f92672">||</span> default_env
</span></span></code></pre></div><p>I liked that Mina provided <code>shared_paths</code> variable and just linked everything there as you would normally expect. Unfortunately in Capistrano it works a little bit different. You can override <code>shared_children</code> (with is set default to <code>%w(public/system log tmp/pids)</code>), so it would look like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>set <span style="color:#e6db74">:shared_content</span>, <span style="color:#e6db74">%w(config/database.yml config/something.yml)</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:shared_children</span>, shared_children <span style="color:#f92672">+</span> shared_content
</span></span></code></pre></div><p>But what I really don&rsquo;t like about this solution is that you have to keep your <code>shared/</code> directory structure flat - I would normally expect to put <em>database.yml</em> in <em>shared/config/database.yml</em>, not inside <em>shared/database.yml</em>, same goes for assets and everything else. So instead I decided to set <code>shared_children</code> to an empty array and create custom task that link all my files and compile assets in a way that I&rsquo;m used to.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>set <span style="color:#e6db74">:shared_children</span>, <span style="color:#f92672">[]</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:shared_content</span>, <span style="color:#f92672">[</span><span style="color:#e6db74">&#39;public/system&#39;</span>, <span style="color:#e6db74">&#39;public/assets&#39;</span>, <span style="color:#e6db74">&#39;tmp&#39;</span><span style="color:#f92672">]</span> <span style="color:#75715e"># and it goes on</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>namespace <span style="color:#e6db74">:deploy</span> <span style="color:#66d9ef">do</span>
</span></span><span style="display:flex;"><span>  task <span style="color:#e6db74">:precompile_assets</span> <span style="color:#66d9ef">do</span>
</span></span><span style="display:flex;"><span>    run <span style="color:#e6db74">&#34;cd -- </span><span style="color:#e6db74">#{</span>latest_release<span style="color:#e6db74">}</span><span style="color:#e6db74"> &amp;&amp; </span><span style="color:#e6db74">#{</span>rake<span style="color:#e6db74">}</span><span style="color:#e6db74"> RAILS_ENV=</span><span style="color:#e6db74">#{</span>rails_env<span style="color:#f92672">.</span>to_s<span style="color:#f92672">.</span>shellescape<span style="color:#e6db74">}</span><span style="color:#e6db74"> assets:precompile&#34;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">end</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  task <span style="color:#e6db74">:symlink_directories</span> <span style="color:#66d9ef">do</span>
</span></span><span style="display:flex;"><span>    shared_content<span style="color:#f92672">.</span>each <span style="color:#66d9ef">do</span> <span style="color:#f92672">|</span>file<span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span>      run <span style="color:#e6db74">&#34;ln -nfs </span><span style="color:#e6db74">#{</span>deploy_to<span style="color:#e6db74">}</span><span style="color:#e6db74">/</span><span style="color:#e6db74">#{</span>shared_dir<span style="color:#e6db74">}</span><span style="color:#e6db74">/</span><span style="color:#e6db74">#{</span>file<span style="color:#e6db74">}</span><span style="color:#e6db74"> </span><span style="color:#e6db74">#{</span>release_path<span style="color:#e6db74">}</span><span style="color:#e6db74">/</span><span style="color:#e6db74">#{</span>file<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span> <span style="color:#75715e"># you can pack it into once huge command if you want - execution will be much faster</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">end</span>
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">end</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">end</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>after <span style="color:#e6db74">&#39;deploy:update_code&#39;</span>, <span style="color:#e6db74">&#39;deploy:symlink_directories&#39;</span>, <span style="color:#e6db74">&#39;deploy:precompile_assets&#39;</span>
</span></span></code></pre></div><p>Now - I like it much better. What&rsquo;s let to to is to setup some tasks for delayed_job and for restarting our unicorns:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>after <span style="color:#e6db74">&#39;deploy:restart&#39;</span>,     <span style="color:#e6db74">&#39;unicorn:duplicate&#39;</span>
</span></span><span style="display:flex;"><span>after <span style="color:#e6db74">&#39;deploy:stop&#39;</span>,        <span style="color:#e6db74">&#39;delayed_job:stop&#39;</span>
</span></span><span style="display:flex;"><span>after <span style="color:#e6db74">&#39;deploy:start&#39;</span>,       <span style="color:#e6db74">&#39;delayed_job:start&#39;</span>
</span></span><span style="display:flex;"><span>after <span style="color:#e6db74">&#39;deploy:restart&#39;</span>,     <span style="color:#e6db74">&#39;delayed_job:restart&#39;</span>
</span></span></code></pre></div><p>Why <code>unicorn:duplicate</code> you ask? If you are using unicorn configuration provided by <a href="https://github.com/sosedoff/capistrano-unicorn/blob/master/examples/rails3.rb">this sample file</a> after sending USR2 signal to master process unicorn should restart itself smoothly and you will get zero downtime deployment.</p>
<p>That&rsquo;s more or less it when it comes to basic configuration, happy deploying!</p>]]></description><content:encoded><![CDATA[<p>It&rsquo;s been a while since I last posted here. I&rsquo;ve been pretty busy with work, I&rsquo;ve also moved to Cracov in the meantime - so yeah, I can&rsquo;t really complaint about boredom ;).</p>
<p>Anyhow, some time ago I posted <a href="/blog/2012/10/27/super-fast-deployment-with-mina-capistrano-alternative/">about Mina</a> - neat little gem that allows super fast deployments. Unfortunately when your project grows you start adding additional bash scripts, you add more and more commands to your deploy script and it grows into something not-so-neat anymore.</p>
<p>That&rsquo;s why tempted with Capistrano&rsquo;s ready-to-use recipes I decided it&rsquo;s time to say hello to Capistrano. I&rsquo;ll provide here step-by-step migration process from Mina. I will be using here <a href="https://github.com/collectiveidea/delayed_job">delayed_job</a>, <a href="http://unicorn.bogomips.org/">unicorn</a> (with <a href="https://github.com/sosedoff/capistrano-unicorn">capistrano-unicorn</a> gem) and <a href="https://github.com/pat/thinking-sphinx">thinking-sphinx</a>.</p>
<p>First, install <a href="https://github.com/capistrano/capistrano">Capistrano</a> and capify your project with command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>capify .
</span></span></code></pre></div><p>(I assume you need only one deployment environment) Go to <code>config/deploy.rb</code> and add some recipes that are provided by thinking-sphinx, delayed_job and capistrano-unicorn:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>require <span style="color:#e6db74">&#34;delayed/recipes&#34;</span>
</span></span><span style="display:flex;"><span>require <span style="color:#e6db74">&#34;thinking_sphinx/capistrano&#34;</span>
</span></span><span style="display:flex;"><span>require <span style="color:#e6db74">&#34;capistrano-unicorn&#34;</span>
</span></span></code></pre></div><p>When you run <code>cap -T</code> in your console you will get the list of available commands that should include newly added toys, isn&rsquo;t that nice? As always I recommend reading provided manual(s) before proceeding further (especially if you&rsquo;re using thinking-sphinx, a lot of stuff is happening after simply requiring its recipe).</p>
<p>Next setup your application repository:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>set <span style="color:#e6db74">:application</span>, <span style="color:#e6db74">&#34;app name&#34;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:repository</span>,  <span style="color:#e6db74">&#34;repo path&#34;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:scm</span>, <span style="color:#e6db74">:git</span> <span style="color:#75715e"># or whatever you use, this can be guessed by Capistrano if not provided</span>
</span></span></code></pre></div><p>Now we will setup a destination machine. I&rsquo;m running my app on shared host and I need to connect to my destination (web) server through shell server first. But in my case that is not enough - I&rsquo;ll need also provide separate ssh key and set proper PATH and RUBY_VER values so it all works nicely.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>server <span style="color:#e6db74">&#39;destination server&#39;</span>, <span style="color:#e6db74">:app</span>, <span style="color:#e6db74">:web</span>, <span style="color:#e6db74">:db</span>, <span style="color:#e6db74">:primary</span> <span style="color:#f92672">=&gt;</span> <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:gateway</span>, <span style="color:#e6db74">&#39;shell server&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:deploy_to</span>, <span style="color:#e6db74">&#39;my deploy path&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:user</span>, <span style="color:#e6db74">&#39;my login&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:use_sudo</span>, <span style="color:#66d9ef">false</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:default_environment</span>, {
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#39;PATH&#39;</span>     <span style="color:#f92672">=&gt;</span> <span style="color:#e6db74">&#39;path dependent values&#39;</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#39;RUBY_VER&#39;</span> <span style="color:#f92672">=&gt;</span> <span style="color:#e6db74">&#39;1.9&#39;</span> <span style="color:#75715e"># This is required by my shared host provider</span>
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:rake</span>, <span style="color:#e6db74">&#39;bundle exec rake&#39;</span> <span style="color:#75715e"># and I need to run everything through bundler,</span>
</span></span><span style="display:flex;"><span>                              <span style="color:#75715e"># because I&#39;m installing gem to my home directory</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>ssh_options<span style="color:#f92672">[</span><span style="color:#e6db74">:keys</span><span style="color:#f92672">]</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">%w(~/.ssh/my_private_key ~/.ssh/my_web_server_key)</span> <span style="color:#75715e"># Capistrano will try each key</span>
</span></span><span style="display:flex;"><span>                                                                        <span style="color:#75715e"># and I need a different one when</span>
</span></span><span style="display:flex;"><span>                                                                        <span style="color:#75715e"># connecting to destination server</span>
</span></span><span style="display:flex;"><span>                                                                        <span style="color:#75715e"># through shell server</span>
</span></span></code></pre></div><p>Now let&rsquo;s set some Rails env variables:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>set <span style="color:#e6db74">:default_env</span>, <span style="color:#e6db74">&#39;production&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:rails_env</span>, <span style="color:#66d9ef">ENV</span><span style="color:#f92672">[</span><span style="color:#e6db74">&#39;RAILS_ENV&#39;</span><span style="color:#f92672">]</span> <span style="color:#f92672">||</span> default_env
</span></span></code></pre></div><p>I liked that Mina provided <code>shared_paths</code> variable and just linked everything there as you would normally expect. Unfortunately in Capistrano it works a little bit different. You can override <code>shared_children</code> (with is set default to <code>%w(public/system log tmp/pids)</code>), so it would look like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>set <span style="color:#e6db74">:shared_content</span>, <span style="color:#e6db74">%w(config/database.yml config/something.yml)</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:shared_children</span>, shared_children <span style="color:#f92672">+</span> shared_content
</span></span></code></pre></div><p>But what I really don&rsquo;t like about this solution is that you have to keep your <code>shared/</code> directory structure flat - I would normally expect to put <em>database.yml</em> in <em>shared/config/database.yml</em>, not inside <em>shared/database.yml</em>, same goes for assets and everything else. So instead I decided to set <code>shared_children</code> to an empty array and create custom task that link all my files and compile assets in a way that I&rsquo;m used to.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>set <span style="color:#e6db74">:shared_children</span>, <span style="color:#f92672">[]</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:shared_content</span>, <span style="color:#f92672">[</span><span style="color:#e6db74">&#39;public/system&#39;</span>, <span style="color:#e6db74">&#39;public/assets&#39;</span>, <span style="color:#e6db74">&#39;tmp&#39;</span><span style="color:#f92672">]</span> <span style="color:#75715e"># and it goes on</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>namespace <span style="color:#e6db74">:deploy</span> <span style="color:#66d9ef">do</span>
</span></span><span style="display:flex;"><span>  task <span style="color:#e6db74">:precompile_assets</span> <span style="color:#66d9ef">do</span>
</span></span><span style="display:flex;"><span>    run <span style="color:#e6db74">&#34;cd -- </span><span style="color:#e6db74">#{</span>latest_release<span style="color:#e6db74">}</span><span style="color:#e6db74"> &amp;&amp; </span><span style="color:#e6db74">#{</span>rake<span style="color:#e6db74">}</span><span style="color:#e6db74"> RAILS_ENV=</span><span style="color:#e6db74">#{</span>rails_env<span style="color:#f92672">.</span>to_s<span style="color:#f92672">.</span>shellescape<span style="color:#e6db74">}</span><span style="color:#e6db74"> assets:precompile&#34;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">end</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  task <span style="color:#e6db74">:symlink_directories</span> <span style="color:#66d9ef">do</span>
</span></span><span style="display:flex;"><span>    shared_content<span style="color:#f92672">.</span>each <span style="color:#66d9ef">do</span> <span style="color:#f92672">|</span>file<span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span>      run <span style="color:#e6db74">&#34;ln -nfs </span><span style="color:#e6db74">#{</span>deploy_to<span style="color:#e6db74">}</span><span style="color:#e6db74">/</span><span style="color:#e6db74">#{</span>shared_dir<span style="color:#e6db74">}</span><span style="color:#e6db74">/</span><span style="color:#e6db74">#{</span>file<span style="color:#e6db74">}</span><span style="color:#e6db74"> </span><span style="color:#e6db74">#{</span>release_path<span style="color:#e6db74">}</span><span style="color:#e6db74">/</span><span style="color:#e6db74">#{</span>file<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span> <span style="color:#75715e"># you can pack it into once huge command if you want - execution will be much faster</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">end</span>
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">end</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">end</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>after <span style="color:#e6db74">&#39;deploy:update_code&#39;</span>, <span style="color:#e6db74">&#39;deploy:symlink_directories&#39;</span>, <span style="color:#e6db74">&#39;deploy:precompile_assets&#39;</span>
</span></span></code></pre></div><p>Now - I like it much better. What&rsquo;s let to to is to setup some tasks for delayed_job and for restarting our unicorns:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>after <span style="color:#e6db74">&#39;deploy:restart&#39;</span>,     <span style="color:#e6db74">&#39;unicorn:duplicate&#39;</span>
</span></span><span style="display:flex;"><span>after <span style="color:#e6db74">&#39;deploy:stop&#39;</span>,        <span style="color:#e6db74">&#39;delayed_job:stop&#39;</span>
</span></span><span style="display:flex;"><span>after <span style="color:#e6db74">&#39;deploy:start&#39;</span>,       <span style="color:#e6db74">&#39;delayed_job:start&#39;</span>
</span></span><span style="display:flex;"><span>after <span style="color:#e6db74">&#39;deploy:restart&#39;</span>,     <span style="color:#e6db74">&#39;delayed_job:restart&#39;</span>
</span></span></code></pre></div><p>Why <code>unicorn:duplicate</code> you ask? If you are using unicorn configuration provided by <a href="https://github.com/sosedoff/capistrano-unicorn/blob/master/examples/rails3.rb">this sample file</a> after sending USR2 signal to master process unicorn should restart itself smoothly and you will get zero downtime deployment.</p>
<p>That&rsquo;s more or less it when it comes to basic configuration, happy deploying!</p>]]></content:encoded></item></channel></rss>