如何解决恐慌;模式匹配 VPS 服务上没有文件
我目前正在尝试将我的 golang 应用程序设置为 Linux VPS 上的服务。 golang 应用程序在我的本地主机上运行流畅。在服务器本身上,我可以使用 go run main.go
启动它,并且可以通过 IP 地址调用该应用程序。
服务配置:
[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
,但是没有用。
希望有人有办法解决这个问题。
您好 克里斯
解决方法
您需要将 WorkingDirectory=
添加到您的应用程序目录中,其中 template
目录存在。
如果不设置,systemd作为系统实例运行时默认为根目录
所以您的 main
问题在 /
(根)上运行,而 ParseGlob
正在尝试在 /template/*.tmpl
上查找内容。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。