dourun2990 2017-08-16 12:33 采纳率: 100%
浏览 60
已采纳

Windows Service无法启动GO Lang exe

I have created an executable in GO and I am running it as a windows service.

I am using golang.org/x/sys/windows/svc package, and provide it with the Execute method which gets called by the SCM

run := svc.Run
_ = run(svcName, &myservice{})

func (m *myservice) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) {

    changes <- svc.Status{State: svc.StartPending}

    go mainmethod()

    changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}


}

The service works most of the time but the problem is that whenever I restart my system, the service gives me a Error 1053 : "The service did not respond to start or control request in a timely fashion" error and does not start,

After adding the log statements in my run and Execute methods, I figured out that when the service starts without error the logs get printed, but when the services gives a 1053 error the SCM does not even invoke my exe, since none of the log statements get printed. Has anyone tried creating a windows service in a similar way? Is it a problem with implementation or the windows svc package?

Thanks

  • 写回答

1条回答 默认 最新

  • dongqu9972 2017-08-23 10:59
    关注

    I have the GO exe deployed in Program Files, I changed the LogOnAs attribute of Windows Service to "Local Service" and gave "Local Service" complete Access to the installation folder in "Folder Security".

    This seems to fix the issue for windows10. The service starts on windows restart, But this fix still does not work for windows 7 and windows8.

    Edit:

    Making the service "Automatic Delayed" works, however you have to wait for the service start after boot which takes 2-3 minutes.

    The answer mentioned here helped: https://serverfault.com/questions/697608/automatic-windows-service-not-starting/697852#697852?newreg=788f7ab0bb084fec85d1ce2e51bf8317

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 qgcomp混合物线性模型分析的代码出现错误:Model aliasing occurred
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥15 小红薯封设备能解决的来
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答