<p>Hey <a href="/r/golang" rel="nofollow">/r/golang</a>!</p>
<p>I'm trying to deploy a quick web server I wrote. Everything works fine when I run it from the command line, but I'd like to be able to log out of my SSH session and still have the Gin app running.</p>
<p>Could anyone guide me to a solution?</p>
<hr/>**评论:**<br/><br/>postman_: <pre><p>screen/nohup/supervisord/thousands of other options</p></pre>alaskacodes: <pre><p>Don't use screen/tmux/nohup outside of development. :( If you want this to be production or semi-production, talk to ops (if it's not you), or use supervisord/upstart/systemd or deploy to your container or cloud platform of choice.</p></pre>knrz: <pre><p>Why not screen/tmux/nohup?
/Independent dev having his own fun, so no ops team :)</p></pre>alaskacodes: <pre><p>Well, note that I said "outside of development". If you're developing, tmux away, buddy! (still don't use nohup, though. nohup sucks)</p>
<p>If you're deploying something when you're not actively developing, all three methods mentioned above won't persist across a server reboot and in general are kind of a kludgy way to keep a process going.</p>
<p>What would you rather do for deployment?</p>
<p><strong>tmux</strong></p>
<pre><code>ssh me@mybox
tmux attach -t <session name (provided you gave it a meaningful one)>
ctrl-c
./mything > /var/log/mything.log 2>&1
ctrl-b n
ctrl-c
tail -f /var/log/mything.log (or look at syslog, depending)
crtl-b $ <and give it a nice name if you haven't>
ctrl-b d
</code></pre>
<p>And then have to reattach to check logs and whatnot, or:</p>
<p><strong>nohup</strong></p>
<pre><code>ssh me@mybox
ps (find my job's pid)
kill <job's pid>
cd /wherever/my/bin/is
nohup ./mything > /var/log/mything.log 2>&1 &
tail -f /var/log/mything.log
</code></pre>
<p>As opposed to:</p>
<p><strong>upstart</strong></p>
<pre><code>ssh me@mybox
service mythingd <start|stop|restart>
tail -f /var/log/mythingd.log
</code></pre>
<p>Or:</p>
<p><strong>supervisord</strong></p>
<pre><code>ssh me@mybox
supervisorctl restart mythingd
tail -f /var/log/mything.log
</code></pre>
<p>The latter two are just so much more convenient, IMHO, and much easier to transform into a deployable package, if you decide to go that route, because you've already done a lot of the footwork.</p>
<p>Plus, correct me someone if I'm wrong, but once you've run something with nohup, it does exactly that: ignore SIGHUP. So, if you've decided to get all fancy and provide SIGHUP-driven config reloading, you lose that. Small niggle, I know, and you always have like SIGUSR1, but it's one less signal you can use.</p></pre>010a: <pre><p><a href="http://supervisord.org/" rel="nofollow">Supervisor</a> is my favorite. </p></pre>strothjs: <pre><p>You can use your operating system's service manager to configure your app to start. Ubuntu uses Upstart or systemd.</p>
<p>You can install supervisord which can manage your service for you.</p>
<p>Other option is to detach the service from your she'll session. Common tool for that is screen.</p></pre>ecmdome: <pre><p>People mentioned screen which is a good choice.</p>
<p>Have you considered deploying using docker? </p></pre>mtanski: <pre><p>upstart / systemd can manage the process for you. and you get rotated log output in /var/log by default.</p></pre>anoland: <pre><p>Uhm... what do you need gin for after deployment? I use gin so that I get the log output for debugging and to recompile files after saving. But after I deploy I wouldn't use it. Just run the program.</p></pre>tofufish: <pre><p>I think he is referring to <a href="https://github.com/codegangsta/gin" rel="nofollow">https://github.com/codegangsta/gin</a> and not <a href="https://github.com/gin-gonic/gin" rel="nofollow">https://github.com/gin-gonic/gin</a></p></pre>alaskacodes: <pre><p>he (anoland) sounds like he's referring to codegangsta/gin and OP is indeed probably referring to gin-gonic/gin. Just clarifying, since your order above is not what I would expect.</p></pre>ZenSwordArts: <pre><p>If you decide to use something like screen have a look at <a href="http://byobu.co/" rel="nofollow">Byobu</a>. It should be in your distros repositories.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传