Running a Go exe as a Windows Service

agolangf · · 457 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m pretty fresh to this, but I built a small webservice that Responds to JSON posts and compiled it as an exe. I&#39;d like to run it as a local windows service and I don&#39;t want to use any outside programs. I know outside programs exist to run exe as service, like NSSM, but it is a server that I&#39;d like to avoid outside programs on and I&#39;d like to know the &#34;correct&#34; way to go about this.</p> <p>It looks like the exe must implement the ServiceMain callback function. <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms685138(v=vs.85).aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/windows/desktop/ms685138(v=vs.85).aspx</a></p> <p>It would be cool if there was an option when compiling it also. Does anyone have experience doing this?</p> <hr/>**评论:**<br/><br/>lordnins: <pre><p>I&#39;m using <a href="https://github.com/kardianos/service" rel="nofollow">https://github.com/kardianos/service</a> you should check it out</p></pre>Hexodam: <pre><p>That or this <a href="https://nssm.cc/" rel="nofollow">https://nssm.cc/</a></p></pre>cesarliws: <pre><p>have you looked this:</p> <p><a href="https://github.com/golang/sys/blob/master/windows/svc/example/service.go" rel="nofollow">https://github.com/golang/sys/blob/master/windows/svc/example/service.go</a></p></pre>sleepyj222: <pre><p>I haven&#39;t, I&#39;ll check it out closer. Thanks!</p></pre>binaryblade: <pre><p><a href="http://maradns.blogspot.ca/2009/03/ive-got-working-windows-service-running.html?m=1" rel="nofollow">here</a> is a link to a very small c program that does it. Should be adaptable into go.</p></pre>

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

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