duanchendu69495 2019-06-06 15:57
浏览 1325

在Windows Server 2008上部署Go Web项目

My project: go - 1.12.5; gin-gonic; vue-cli - 3.8.2.

On windows server 2008 go under the local account, run main.exe - works well. But when log off my account, all local account programs are closed, including my go server.

The first thing I did was try to configure IIS for my GO. Nothing good came of it.

Then I tried to run main.exe from the SYSTEM account psexec -s c:afd\main.exe. When log off the process does not close. But the frontend is in my account and SYSTEM does not see the local files (js, html, css) of my project

Tell me how to start the Go server, to after log off my project did not stop life

  • 写回答

2条回答 默认 最新

  • dongshenyu4638 2019-06-06 17:31
    关注

    Two ways to approach it.

    1. Go with ISS (or another web server).

      Should you pick this option, you have further choices:

      • Leave your project's code as is, but

        • Make sure it's able to be told which socket to listen for connections on—so that you can tell it to listen, say, on localhost:8080. For instance, teach your program to accept a command-line parameter for that—such as -listen or whatever.
        • Configure IIS in a way so that it reverse-proxies incoming HTTP requests on a certain virtual host and/or path prefix to a running instance of your server. You'll have to make the IIS configuration—the socket it proxies the requests to—and the way IIS starts your program agree with each other.
      • Rework the code to use FastCGI protocol instead. This basically amounts to using net/fastcgi instead of net/http.

        The upside is that IIS (even its dirt-old versions) support FastCGI out of the box. The downsides are that FastCGI is beleived to be slightly slower than plain HTTP in Go, and that you'll lose the ability to run your program in the standalone mode.

    2. Turn your program into a proper Windows™ service or "wrap" it with some helper tool to make it a Windows™ service.

      The former is cleaner as it allows your program to actually be aware of control requests the Windows Service Management subsystem would send to you. You could also easily turn your program into a shrink-wrapped product, if/when needed. You could start with golang.org/x/sys/windows/svc.

      The latter may be a bit easier, but YMMV. If you'd like to explore this way, look for tools like srvany, nssm, winsv etc.

      Note that of these, only srvany is provided by Microsoft® and, AFAIK, it's missing since Win7, W2k8, so your best built-in bet might be messing with sc.exe.

      In either case, should you pick this route, you'll have to deal with the question of setting up proper permissions on your app's assets. This question is reasonably complex in itself since there are many moving parts involved.

      For a start, you have to make sure your assets are tried to be accessed not from "the process' current directory"—which may be essentially random when it runs as a service—but either from the place the process was explicitly told about when run (via command-line option or whatever) or figured out somehow using a reasonably engeneered guess (and this is a complicated topic in itself).

      Next, you either have to make sure the account your Windows™ uses to run your service really has the permissions to access the place your assets are stored in. Another possibility is to add a dedicated account and make the SCM use it for running your service.

      Note that in either case proper error handling and their reporting is paramount: when your program is being run non-interactively, you want to know when something goes wrong: socket failed to be opened or listened on, assets not found, access was denied when trying to open an asset file, and so on—in all these cases you have to 1) handle the error, and 2) report it in a way you can deal with it. For a non-interactive Windows™ program the best way may be to use the Event Log (say, via golang.org/x/sys/windows/svc/eventlog).

    评论

报告相同问题?

悬赏问题

  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入