12

The Go language provides handlers for serving HTTP responses. It is easy enough to start up a Go program on the command prompt, that listens for incoming HTTP requests.

What are the deployment options for running such a Go program in the background on a Windows Server machine? For example, is there a standard method for creating a Windows Service that runs the Go program in the background?

spindles
  • 137
  • 1
  • 3
  • 3
    Can you not just create a service and set its target to the Go executable? – Simon Whitehead Jun 23 '14 at 03:08
  • 3
    possible duplicate of [Create Windows service from executable](http://stackoverflow.com/questions/3582108/create-windows-service-from-executable) – Elwinar Jun 23 '14 at 06:59
  • @SimonWhitehead, thanks for the tip. I'll try to create a service using the Sv.exe command to run the Go program – spindles Jun 23 '14 at 13:35

2 Answers2

14

There is an excellent golang package kardianos/service that will allow you to create a service whatever the platform you are targeting.

As you can see here (it is in french but what is interesting is the code sample at the begginning of the page), it is easy to extend your program with command line options such as :

  • install install the service.
  • remove remove the service.
  • run simply run the program (not as a service).
  • start/stop the service
Benjamin BALET
  • 919
  • 1
  • 11
  • 31
  • 1
    @EthanMick I fixed the link to an archive : http://decouvric.cluster013.ovh.net/golang/thirdparty/divers/creer-un-service-golang-avec-kardianos.html – Benjamin BALET Mar 12 '17 at 19:28
1
  1. Use NSSM (create service from any executable)

nssm install MyService d:\MyService.exe

  1. Use golang.org/x/sys/windows/svc package

... others ...

Afriza N. Arief
  • 7,696
  • 5
  • 47
  • 74