Need help to run web-server on Centos

blov · · 447 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I had created a web-server file hello.go with below content:</p> <p>package main</p> <p>import (</p> <pre><code>&#34;fmt&#34; &#34;net/http&#34; </code></pre> <p>)</p> <p>func helloWorld(w http.ResponseWriter, r *http.Request){</p> <pre><code>fmt.Fprintf(w, &#34;Hello World&#34;) </code></pre> <p>}</p> <p>func main() {</p> <pre><code>http.HandleFunc(&#34;/&#34;, helloWorld) http.ListenAndServe(&#34;:8080&#34;, nil) </code></pre> <p>}</p> <p>When i am running as go run hello.go from putty.</p> <p>I am able to access server is running fine and able to access <a href="http://93.188.165.37:8080/" rel="nofollow">http://93.188.165.37:8080/</a>.</p> <p><em>How we can run web-server on background process?</em></p> <p><strong>When I can close the putty session or after logged out from putty I m unable to access to my web-server.</strong></p> <hr/>**评论:**<br/><br/>partkyle: <pre><p><code>go run</code> is useful for running things quickly, but it isn&#39;t the best method for deploying an application. You will want to run <code>go build</code> to create an executable file that you will run. This way, you won&#39;t have to recompile everytime you run your program. You will have to run <code>go build</code> every time there is a code change. </p> <p>As for keeping a process running, for a real production app you will want to look in to using an init system. Assuming you are using CentOS 7, that would be systemd by default. </p> <p>If you don&#39;t want to go that far, look in to using screen or tmux to keep it running in a shell when you log out. </p> <p>Sorry for the brevity of my reply and my lack of links, I&#39;m ok mobile now. All of this should be easily searchable on Google. </p> <p>Happy coding!</p></pre>Cabraca: <pre><p><a href="https://www.cyberciti.biz/tips/nohup-execute-commands-after-you-exit-from-a-shell-prompt.html" rel="nofollow">https://www.cyberciti.biz/tips/nohup-execute-commands-after-you-exit-from-a-shell-prompt.html</a></p> <p>This should do the trick</p></pre>Gambletron: <pre><p>You can also put Linux processes on a background thread by ending the command with &#39;&amp;&#39;. The caveat is that the process is still part of you putty shell, so when you close the shell it will close. And the useful command is &#39;nohup&#39; (no-hang-up)</p> <p>So if you&#39;re looking to boot it up one-time (<a href="/u/partkyle" rel="nofollow">/u/partkyle</a> mentioned adding it to init.d, which is the permanent solution), you can either <code>nohup git run &amp;</code> or build the exe and <code>nohup ./server &amp;</code></p></pre>

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

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