<p>Hi, new to Go here :)</p>
<p>I've built small http daemon in Go using <a href="https://github.com/facebookgo/grace">https://github.com/facebookgo/grace</a> to handle the restarts, but now I need to be able to control it from web (restart namely). I looked at the source of the library and I can't see any exported methods to deal with such situation. It uses channels internally which are not accessible from outside (or i don't know how).</p>
<p>So I came with this approach:</p>
<pre><code>mux.HandleFunc("/restart", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Restaring pid %d.\n", os.Getpid())
syscall.Kill(os.Getpid(), syscall.SIGUSR2)
return
})
</code></pre>
<p>Here is my question: It works but is this the right and idiomatic way to do it?
Cheers and sorry if the question is too noobish :)</p>
<hr/>**评论:**<br/><br/>tclineks: <pre><p>Your approach is valid.</p>
<p>SIGUSR2 is the only 'entrypoint' here.</p>
<p><a href="https://github.com/facebookgo/grace/blob/053ab5d25436faedf3fe76fbf3da797c8c27c659/gracehttp/http.go#L99">https://github.com/facebookgo/grace/blob/053ab5d25436faedf3fe76fbf3da797c8c27c659/gracehttp/http.go#L99</a></p></pre>code-chimp: <pre><p>Thank you very much, was having second thoughts since worked from first try, and per Murphy's law this is wrong :)</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传