gpt4 book ai didi

go - 无法将go二进制文件作为systemctl守护程序运行

转载 作者:行者123 更新时间:2023-12-01 21:09:35 36 4
gpt4 key购买 nike

我有一个Go Web应用程序,它位于/home/me/go/src/myapp路径上。
当我在bash终端上使用./myapp运行可执行文件时,它运行良好。
但是,这需要一个开放的终端才能继续运行,这不切实际,因此我尝试在Debian服务器的/etc/systemd/system/myapp.service上创建一个systemd守护程序,如下所示:

[Unit]
Description=MyApp Daemon
StartLimitIntervalSec=0
[Service]
Type=simple
User= me
Group=www-data
ExecStart=/home/me/go/src/myapp/myapp
TimeoutStopSec=300
[Install]
WantedBy=multi-user.target
我已经启用并启动了守护程序:
systemctl enable myapp
启动它:
systemctl start myapp
但是,它无法运行daemn,并且出现此错误:
# systemctl status myapp
● myapp.service - MyApp Daemon
Loaded: loaded (/etc/systemd/system/myapp.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2020-07-17 05:42:18 CDT; 4s ago
Process: 19058 ExecStart=/home/me/go/src/myapp/myapp (code=exited, status=127)
Main PID: 19058 (code=exited, status=127)
CPU: 2ms
Jul 17 05:42:18 front systemd[1]: Started Myapp Daemon.
Jul 17 05:42:18 front systemd[1]: myapp.service: Main process exited, code=exited, status=127/n/a
Jul 17 05:42:18 front systemd[1]: myapp.service: Unit entered failed state.
Jul 17 05:42:18 front systemd[1]: myapp.service: Failed with result 'exit-code'.
我想知道什么可能是错误的,我该如何解决?

最佳答案

经过大量的试验和错误,此配置对我有用:

[Unit]
Description=Sai Go webapp Daemon
#After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
User= me
Group=www-data
WorkingDirectory=/home/me/go/src/myapp/
ExecStart=/home/me/go/src/myapp/myapp
TimeoutStopSec=300
[Install]
WantedBy=multi-user.target
显然 WorkingDirectory是必要的。

关于go - 无法将go二进制文件作为systemctl守护程序运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62952596/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com