我目前正在尝试在Linux VPS上将我的golang应用程序设置为服务。golang应用程序在我的本地主机上平稳运行。在服务器本身上,我可以启动它,并且应用程序可以通过IP地址调用。go run main.go服务配置:[Unit]Description=vfreight[Service]Type=simpleRestart=alwaysRestartSec=5sExecStart=/root/go/src/VFreight/main[Install]WantedBy=multi-user.target但是当我尝试将其作为服务运行时,该服务总是失败。May 13 20:10:31 srv.vfreight.com systemd[1]: Started vfreight.May 13 20:10:31 srv.vfreight.com main[3167]: panic: html/template: pattern matches no files: `template/*.tmpl`May 13 20:10:31 srv.vfreight.com main[3167]: goroutine 1 [running]:May 13 20:10:31 srv.vfreight.com main[3167]: html/template.Must(...)May 13 20:10:31 srv.vfreight.com main[3167]: /usr/lib/golang/src/html/template/template.go:374May 13 20:10:31 srv.vfreight.com main[3167]: VFreight/app/controller.init.0()May 13 20:10:31 srv.vfreight.com main[3167]: /root/go/src/VFreight/app/controller/control.go:21 +0x9eMay 13 20:10:31 srv.vfreight.com systemd[1]: vfreight.service: main process exited, code=exited, status=2/INVALIDARGUMENTMay 13 20:10:31 srv.vfreight.com systemd[1]: Unit vfreight.service entered failed state.May 13 20:10:31 srv.vfreight.com systemd[1]: vfreight.service failed.May 13 20:10:36 srv.vfreight.com systemd[1]: vfreight.service holdoff time over, scheduling restart.May 13 20:10:36 srv.vfreight.com systemd[1]: Stopped vfreight.func init() { tmpl = template.Must(template.ParseGlob("template/*.tmpl")) }我试图将更改为,但这不起作用。template/*.tmpl../template/*.tmpl去 env希望有人有一个想法来解决这个问题。问候克里斯
1 回答
犯罪嫌疑人X
TA贡献2080条经验 获得超4个赞
您需要添加到应用程序所在的目录。WorkingDirectory=
template
来自 systemd.exec(5):
如果未设置,则当 systemd 作为系统实例运行时,默认为根目录
因此,您的问题正在(根)上运行,并试图在 中查找内容。main
/
ParseGlob
/template/*.tmpl
- 1 回答
- 0 关注
- 60 浏览
添加回答
举报
0/150
提交
取消