How do you rebuild/restart your app on file changes?

blov · · 932 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m trying to use inotifywait. </p> <p>I have a web app I&#39;m building and I want to restart the server on each file change. My problem now is that after the first file change the server starts but it blocks inotifywait from running until I manually stop it. </p> <p>Anyone have a solution to this? </p> <p>edit: solutions here aren&#39;t bad but I found this solution for inotifywait:</p> <p><a href="https://stackoverflow.com/questions/12264238/restart-process-on-file-change-in-linux">https://stackoverflow.com/questions/12264238/restart-process-on-file-change-in-linux</a></p> <pre><code>#!/bin/sh while true; do go build $@ &amp; PID=$! inotifywait -r -e modify . kill $PID done </code></pre> <p>Run like <code>$ ./this_script ./your_binary</code> in the root of your project directory.</p> <hr/>**评论:**<br/><br/>wwader: <pre><p>I use <a href="https://github.com/cortesi/modd">https://github.com/cortesi/modd</a> and like it</p></pre>wwader: <pre><p>...can also be used together with <a href="https://github.com/cortesi/devd" rel="nofollow">https://github.com/cortesi/devd</a> in live reload mode to get browser reload/update on changes to go code, templates, stylesheet, javascript etc.</p> <p>Can post modd.conf example if someone is interested.</p></pre>MaxWayt: <pre><p>Maybe <a href="https://github.com/cespare/reflex" rel="nofollow">https://github.com/cespare/reflex</a> would fit your needs</p></pre>scottjbarr: <pre><p><code>reflex</code> is nice. I use it for running <code>go tests</code> on code changes.</p> <p>For deployment though I often use a Makefile which tests, builds, creates containers and deploys. The deploy process is often as simple as using ssh to copy config and binaries up to hosts, and restarting a process.</p></pre>bikemowman: <pre><p>I&#39;ve used <a href="https://github.com/codegangsta/gin" rel="nofollow">https://github.com/codegangsta/gin</a> before. Works really well for http servers.</p></pre>nikajon_es: <pre><p>I&#39;ve written up a solution that I&#39;ve used before on my blog <a href="http://blog.mobimic.com/posts/golang-composition-and-channels" rel="nofollow">http://blog.mobimic.com/posts/golang-composition-and-channels</a> the main thing I did was extend the ListenAndServe method to block on a channel and not the http.Serve method.</p></pre>arp242: <pre><p>The solution that I currently use it to watch the binary – and <em>only</em> the binary – the application was started from for changes, and recompile &amp; restart the application when that changes.</p> <p>I find that this works well for me; I can just use <code>go install</code> (or <code>:make</code> from Vim) to recompile and restart the application, and it doesn&#39;t do thousands of unnecessary (and sometimes unwanted) recompiles every day.</p> <p>It&#39;s also a <em>lot</em> more performant over &#34;remote&#34; network drives (e.g. when using Vagrant or Docker mounts).</p> <p>Here&#39;s the code I use; it&#39;s not a public repo (yet) as I need to remove the dependency on our very organisation-specific <code>log</code> package first; I put it in a gist for now (the code is very simple): <a href="https://gist.github.com/Carpetsmoker/983d6526307e0a08f78635474a7dc58d" rel="nofollow">https://gist.github.com/Carpetsmoker/983d6526307e0a08f78635474a7dc58d</a> You&#39;ll want to replace those two <code>log.*</code> lines. Start it in a goroutine.</p> <p>The downside of this method is that you need to modify the application&#39;s code.</p> <p>Some of my co-workers have been using <a href="https://github.com/canthefason/go-watcher" rel="nofollow">https://github.com/canthefason/go-watcher</a> .</p></pre>hell_0n_wheel: <pre><blockquote> <p>How do you rebuild/restart your app on file changes?</p> </blockquote> <p>Since you asked... using an orchestration tool like ansible or chef, chained into a continuous delivery pipeline. Build -&gt; unit test -&gt; integration test -&gt; staging deploy -&gt; canary test -&gt; production deploy.</p> <p>It&#39;s overkill for what you&#39;re trying to do, but if you want to see the other end of the spectrum, check out any of Chuck Rossi&#39;s talks about Facebook Release Engineering. Might inspire you to try something new.</p></pre>fmpwizard: <pre><p>if you are looking to rebuild/restart your app during dev mode, I have been using</p> <p><a href="https://github.com/sqs/rego" rel="nofollow">https://github.com/sqs/rego</a></p> <p>hasn&#39;t had updates in a long time because it just does one thing and does it well. If you are looking at production, +1 to what <a href="https://www.reddit.com/user/hell_0n_wheel" rel="nofollow">https://www.reddit.com/user/hell_0n_wheel</a> said. We use ansible, called from a jenkins instance</p></pre>junajted: <pre><p>Another tool for this job is <a href="https://github.com/tockins/realize" rel="nofollow">https://github.com/tockins/realize</a></p> <p>Can&#39;t say anything about how it compares to similar tools posted in here. </p></pre>try2think1st: <pre><p>also favoring realize as it does a really good job. It has many options, allows to define env variables and arguments and the ability to watch multiple projects at the same time. The Web interface is a also nice-to-have...</p></pre>everdev: <pre><p>Is this for development purposes? If so, Atom&#39;s Go package will do this automatically.</p></pre>a1454a: <pre><p>I was doing web dev before go. I got lazy and just configure gulp watch to run go build....</p></pre>zxo0oxz: <pre><p><a href="https://github.com/pilu/fresh" rel="nofollow">https://github.com/pilu/fresh</a></p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

932 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传