以 root 以外的系统用户身份在 CentOS 上运行服务

以 root 以外的系统用户身份在 CentOS 上运行服务

我创建了一个系统用户jackett( useradd -r jackett),并尝试在 CentOS 7 上在该用户下运行 systemd 服务。

服务文件:

[Unit]
Description=Jackett Daemon
After=network-online.target

[Service]
Type=simple
user=jackett
group=jackett
ExecStart=/usr/bin/mono --debug /opt/Jackett/JackettConsole.exe --NoRestart

[Install]
WantedBy=multi-user.target

服务状态:

[root@server Jackett]# systemctl status jackett
● jackett.service - Jackett Daemon
   Loaded: loaded (/usr/lib/systemd/system/jackett.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2019-02-23 23:42:23 +03; 11min ago
 Main PID: 24735 (mono)
   CGroup: /system.slice/jackett.service
           └─24735 /usr/bin/mono --debug /opt/Jackett/JackettConsole.exe --NoRestart

Feb 23 23:42:24 server mono[24735]: 02-23 23:42:24 Info Loading Cardigann definition /opt/Jackett/Definitions/yourexotic.yml
Feb 23 23:42:24 server mono[24735]: 02-23 23:42:24 Info Loading Cardigann definition /opt/Jackett/Definitions/zamundanet.yml
Feb 23 23:42:24 server mono[24735]: 02-23 23:42:24 Info Loading Cardigann definition /opt/Jackett/Definitions/zelkaorg.yml
Feb 23 23:42:24 server mono[24735]: 02-23 23:42:24 Info Loading Cardigann definition /opt/Jackett/Definitions/zooqle.yml
Feb 23 23:42:24 server mono[24735]: 02-23 23:42:24 Info Loading Cardigann definition /opt/Jackett/Definitions/ztracker.yml
Feb 23 23:42:24 server mono[24735]: 02-23 23:42:24 Info Adding aggregate indexer
Feb 23 23:42:25 server mono[24735]: Hosting environment: Production
Feb 23 23:42:25 server mono[24735]: Content root path: /opt/Jackett/Content
Feb 23 23:42:25 server mono[24735]: Now listening on: http://[::]:9117
Feb 23 23:42:25 server mono[24735]: Application started. Press Ctrl+C to shut down.

htop 显示在 root 下运行的进程 在此输入图像描述

答案1

问题显然是 systemd 特别注重 case:User而不是user:

[Unit]
Description=Jackett Daemon
After=network-online.target

[Service]
Type=simple
User=jackett
Group=jackett
ExecStart=/usr/bin/mono --debug /opt/Jackett/JackettConsole.exe --NoRestart

[Install]
WantedBy=multi-user.target

参考:

相关内容