为了账号安全,请及时绑定邮箱和手机立即绑定

ExecStart 在 Golang webapp 的 systemd 服务中失败

ExecStart 在 Golang webapp 的 systemd 服务中失败

Go
杨魅力 2022-12-19 11:47:03
我是 golang 的新手,正在尝试在我的服务器上托管一个简单的网站。我在 Ubuntu 18.04我的域根目录在/var/www/vhosts/mydomain.com/mydomain.com我有一个main.go文件,它在浏览器中呈现一个简单的 Hello World。当我go run main.go离开这个目录时,网页工作正常。现在我正在尝试创建一项服务,以便在我关闭我的shell.为此,我创建了一个新service的golangweb.serviceat /etc/systemd/system。该文件的内容是:[Unit]Description = Go Server[Service]ExecStart=/var/www/vhosts/mydomain.com/mydomain.comType=simpleRestart=alwaysRestartSec=5[Install]WantedBy=multi-user.target保存文件后,我按顺序插入以下命令:sudo systemctl daemon-reloadsudo systemctl enable golangweb.servicesudo systemctl start golangweb.servicesudo systemctl status golangweb.service当我尝试获取状态时,出现以下错误(我在那里删除了一些数据): golangweb.service - Go Server   Loaded: loaded (/etc/systemd/system/golangweb.service; enabled; vendor preset: enabl   Active: activating (auto-restart) (Result: exit-code) since Fri xx-xx-xx 23:43:52  **Process: xx ExecStart=/var/www/vhosts/mydomain.com/mydomain.com (code=exited, sta Main PID: xx (code=exited, status=203/EXEC)**Mai xx xx:xx:xx xxxxx.xxxx.xxxx.systemd[1]: golangweb.service: Failed with reWarning: Journal has been rotated since unit was started. Log output is incomplete or ulines 1-8/8 (END)● golangweb.service - Go Server   Loaded: loaded (/etc/systemd/system/golangweb.service; enabled; vendor preset: enabled)   Active: activating (auto-restart) (Result: exit-code) since Fri xx-xx-xx xx:xx:xx CEST; 3s ago  Process: xx ExecStart=/var/www/vhosts/mydomain.com/mydomain.com (code=exited, status=203/EXEC) Main PID: xx (code=exited, status=203/EXEC)Mai xx xx:xx:xx xxxx.xx.xx xx[1]: golangweb.service: Failed with result 'exit-code'.Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.有人知道为什么会这样吗?
查看完整描述

1 回答

?
慕虎7371278

TA贡献1802条经验 获得超4个赞

第一个参数ExecStart需要是一个可执行文件。看起来你已经将它设置为一个目录。如果您尝试/var/www/vhosts/mydomain.com/mydomain.com在 shell 提示符下键入,您会看到类似的行为:您无法运行目录。

可以设置:

WorkingDirectory=/var/www/vhosts/mydomain.com/mydomain.com
ExecStart=/usr/bin/go run main.go

或者,您可以编译代码 ( go build),然后设置ExecStart为已编译二进制文件的完整路径:

ExecStart=/var/www/vhosts/mydomain.com/mydomain.com/compiledprogramname


查看完整回答
反对 回复 2022-12-19
  • 1 回答
  • 0 关注
  • 266 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号