execstart在Golang WebApp的SystemD服务中失败
我是Golang的新手,正在尝试在服务器上托管一个简单的网站。
我在ubuntu 18.04上,
我的域根目录在/var/www/vhosts/mydomain.com/mydomain.com/mydomain.com
我有一个main.go
file,在浏览器中渲染一个简单的Hello World。
当i 从此目录中运行main.go
时,该网页正常工作。
现在,当我关闭shell
时,我正在尝试创建一个服务以保持网页可用。
为此,我创建了一个新的服务
称为golangweb.service
at /etc/etc/systemd/systemd/system
。
该文件的内容是:
[Unit]
Description = Go Server
[Service]
ExecStart=/var/www/vhosts/mydomain.com/mydomain.com
Type=simple
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
保存文件后,我按顺序插入folling命令:
sudo systemctl daemon-reload
sudo systemctl enable golangweb.service
sudo systemctl start golangweb.service
sudo 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 re
Warning: Journal has been rotated since unit was started. Log output is incomplete or u
lines 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.
有人知道为什么会发生这种情况吗?
I'm new to golang and am trying to host a simple website on my server.
I'm on Ubuntu 18.04
My domain root directory is in /var/www/vhosts/mydomain.com/mydomain.com
There I have a main.go
file which is rendering a simple Hello World in the browser.
When I go run main.go
from this directory, the webpage is working correctly.
Now I'm trying to create a service to keep the webpage available when I close my shell
.
For that I created a new service
called golangweb.service
at /etc/systemd/system
.
The content at that file is:
[Unit]
Description = Go Server
[Service]
ExecStart=/var/www/vhosts/mydomain.com/mydomain.com
Type=simple
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
After saving the file I insert the folling commands in order:
sudo systemctl daemon-reload
sudo systemctl enable golangweb.service
sudo systemctl start golangweb.service
sudo systemctl status golangweb.service
When I try to get the status I get the following error (I xed out some data there):
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 re
Warning: Journal has been rotated since unit was started. Log output is incomplete or u
lines 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.
does anybody know why this is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
execstart
的第一个参数需要是可执行文件。看起来您已将其设置为目录。如果您尝试在Shell提示符下尝试键入/var/www/vhosts/mydomain.com/mydomain.com/mydomain.com
,您会看到类似的行为:您无法运行目录。您可以 set:
另外,您可以编译代码(
go Build
),然后将execstart
设置为到达编译的二进制文件:The first argument to
ExecStart
needs to be an executable file. It looks like you've set it to a directory. If you were to try typing/var/www/vhosts/mydomain.com/mydomain.com
at the shell prompt, you would see similar behavior: you can't run a directory.You could set:
Alternately, you could compile your code (
go build
), and then setExecStart
to the full path to the compiled binary: