我的systemd服务文件的名称为,os.service
并具有以下配置行。
# This systemd service file will help supervise os service
[Unit]
Description=Os Server
After= network.target
[Service]
# Preferably configure a non-privileged user
# User=deploy
# Group=deploy
# Environment variables shared across the config
#EnvironmentFile= # environment file to be used, includes RACK_ENV
EnvironmentFile=/home/deploy/test/shared/.env
SyslogIdentifier=test
PIDFile=/home/deploy/test/shared/tmp/server.pid
# Specify the path to your test application root
# WorkingDirectory=/home/deploy/test/
# Start/Reload/Stop syntax
ExecStart=/home/deploy/test/current
# TimeoutSec=15
# TimeoutStopSec=10
RestartSec=5s
# Restart os, always if it dies for some reason
Restart=always
[Install]
WantedBy=multi-user.target
在服务器中,当我断开ssh连接时,服务会死机并导致502 Bad Gateway。我必须ssh并运行systemctl --user start os.service
才能启动并使其工作。再次,一旦我关闭我的终端,然后os.service再次死亡。
您正在通过用户管理器(--user
)运行该服务,显然您logind
没有为您启用徘徊。结果,每当您注销时,您的会话(包括其中启动的所有服务)都将关闭。
要更改此行为,您需要启用linginging:
sudo loginctl enable-linger $USER
这将在启动时为您启动一个用户管理器,并允许您的服务在您的登录会话后继续存在。
诸如此类的系统服务的更好方法实际上是将其作为自己的用户运行,并由主要systemd实例管理。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句