恐慌;模式与VPS服务上的无文件匹配

我目前正在尝试在Linux VPS上将我的golang应用程序设置为服务。golang应用程序在我的本地主机上平稳运行。在服务器本身上,我可以启动它,并且应用程序可以通过IP地址调用。go run main.go


服务配置:


[Unit]

Description=vfreight


[Service]

Type=simple

Restart=always

RestartSec=5s

ExecStart=/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:374

May 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 +0x9e

May 13 20:10:31 srv.vfreight.com systemd[1]: vfreight.service: main process exited, code=exited, status=2/INVALIDARGUMENT

May 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


希望有人有一个想法来解决这个问题。


问候克里斯


繁花如伊
浏览 66回答 1
1回答

犯罪嫌疑人X

您需要添加到应用程序所在的目录。WorkingDirectory=template来自 systemd.exec(5):如果未设置,则当 systemd 作为系统实例运行时,默认为根目录因此,您的问题正在(根)上运行,并试图在 中查找内容。main/ParseGlob/template/*.tmpl
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go