我创建了一个 Golang 程序来执行一些功能。为了在 Linux(centos)上安装,我使用适当的操作系统和体系结构(GOOS=linux,GOARCH=amd64)构建了该应用程序。当我直接从 Linux 操作系统启动该应用程序时,该应用程序运行成功,但是当我尝试将其安装为服务文件时,它无法启动服务并引发以下错误。
May 22 14:30:19 a360monitoring.cloud.automationanywhere.net a360monitoringserver[27935]: goroutine 1 [running]:
May 22 14:30:19 a360monitoring.cloud.automationanywhere.net a360monitoringserver[27935]: a360monitoringserver/logger.(*Logger).setLogFile(0xc00001e240)
May 22 14:30:19 a360monitoring.cloud.automationanywhere.net a360monitoringserver[27935]: C:/My Work/GoLang/DemoCode/a360monitoring/logger/Logger.go:67 +0x4c5
May 22 14:30:19 a360monitoring.cloud.automationanywhere.net a360monitoringserver[27935]: a360monitoringserver/logger.GetLogger.func1()
May 22 14:30:19 a360monitoring.cloud.automationanywhere.net a360monitoringserver[27935]: C:/My Work/GoLang/DemoCode/a360monitoring/logger/Logger.go:26 +0x15d
May 22 14:30:19 a360monitoring.cloud.automationanywhere.net a360monitoringserver[27935]: sync.(*Once).doSlow(0xc0000761e0?, 0x6c8044?)
May 22 14:30:19 a360monitoring.cloud.automationanywhere.net a360monitoringserver[27935]: C:/Program Files/Go/src/sync/once.go:74 +0xc2
May 22 14:30:19 a360monitoring.cloud.automationanywhere.net a360monitoringserver[27935]: sync.(*Once).Do(...)
May 22 14:30:19 a360monitoring.cloud.automationanywhere.net a360monitoringserver[27935]: C:/Program Files/Go/src/sync/once.go:65
May 22 14:30:19 a360monitoring.cloud.automationanywhere.net a360monitoringserver[27935]: a360monitoringserver/logger.GetLogger()
May 22 14:30:19 a360monitoring.cloud.automationanywhere.net a360monitoringserver[27935]: C:/My Work/GoLang/DemoCode/a360monitoring/logger/Logger.go:19 +0x31
May 22 14:30:19 a360monitoring.cloud.automationanywhere.net a360monitoringserver[27935]: a360monitoringserver/requesthandler.init()
May 22 14:30:19 a360monitoring.cloud.automationanywhere.net a360monitoringserver[27935]: C:/My Work/GoLang/DemoCode/a360monitoring/requesthandler/RequestHandler.go:12 +0x17
May 22 14:30:19 a360monitoring.cloud.automationanywhere.net systemd[1]: a360monitoringserver.service: main process exited, code=exited, status=2/INVALIDARGUMENT
May 22 14:30:19 a360monitoring.cloud.automationanywhere.net systemd[1]: Unit a360monitoringserver.service entered failed state.
May 22 14:30:19 a360monitoring.cloud.automationanywhere.net systemd[1]: a360monitoringserver.service fai
答案1
问题已解决,我在服务配置文件中输入了错误的用户名。我替换了正确的名称,问题就解决了。
[Service]
WorkingDirectory=/tmp
Restart=on-abnormal
User=<username>
Group=<groupname>