端末が閉じると、Systemd は終了します。

端末が閉じると、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 悪いゲートウェイ。私はsystemctl --user start os.serviceそれを起動して実行するためにsshを実行する必要がありました。端末を閉じるとすぐに os.service が再び終了します。

ベストアンサー1

--userユーザーマネージャ()でサービスを実行しており、logind遅延が有効になっていないようです。したがって、ログアウトするたびにセッション(開始されたすべてのサービスを含む)が閉じられます。

この動作を変更するには、次のものが必要です。遅延を有効にする:

sudo loginctl enable-linger $USER

これにより、起動時にユーザー管理者が起動し、サービスをログインセッションで維持できます。

このようなシステム・サービスの場合、より良いアプローチは、実際には基本システム・インスタンスで管理する独自のユーザーとして実行することです。

おすすめ記事