如何在 Ubuntu 中让我的应用 运行 在后台运行

How to make my app run in background in Ubuntu

我在 Ubuntu 实例中创建了一个服务,方法是将其添加到 systemd,例如:

sudo systemctl enable myservice.service

Created symlink /etc/systemd/system/multi-user.target.wants/myservice.service → /etc/systemd/system/myservice.service. 

我的myservice.service里面的设置是:

[Unit]
Description=myserviceService

[Service]
Restart=always
Type=simple
ExecStart=/home/myservice-app/core/core

[Install]
WantedBy=multi-user.target

这是我检查状态时的错误:

Feb 02 06:51:16 myservice-ubuntu-app systemd[1]: myservice.service: Main process exited, code=exited, status=1/FAILURE
Feb 02 06:51:16 myservice-ubuntu-app systemd[1]: myservice.service: Failed with result 'exit-code'.
Feb 02 06:51:16 myservice-ubuntu-app systemd[1]: myservice.service: Scheduled restart job, restart counter is at 5.
Feb 02 06:51:16 myservice-ubuntu-app systemd[1]: Stopped myserviceService.
Feb 02 06:51:16 myservice-ubuntu-app systemd[1]: myservice.service: Start request repeated too quickly.
Feb 02 06:51:16 myservice-ubuntu-app systemd[1]: myservice.service: Failed with result 'exit-code'.
Feb 02 06:51:16 myservice-ubuntu-app systemd[1]: Failed to start myservice Service.

我做错了什么?服务 运行 正确地在前台运行,没有错误,它只是努力达到 运行 的服务。

如果您的 Go 程序能够正常启动(意味着不是作为服务,而是从命令行手动启动),请检查这是否是策略问题。

例如,如果 SELinux policy 未安装在系统路径中(如 /usr/local/bin),它可能会阻止您的 Go 二进制文件启动。
或者 service definition uses relative instead of absolute paths (same here).
或者用 wrong user.