私はRed Hat 7.2を使用しており、ユーザーデーモンを実行する必要があります。ここで言ったようにhttps://access.redhat.com/solutions/1293513Red Hat 7はsystemdのユーザーモードをサポートしていません。私の主な目的は、所有者ユーザーが使用する単一のデーモンのさまざまなインスタンスを起動することです。誰でもシステムユーザーモードなしで代替案を提案できますか?

ベストアンサー1

ほとんどのユースケース(たとえば、ユーザーが自分のユニットファイルを管理できるようにする)の場合は、RHEL7のsystemd 219が正しく機能するため、有効にするだけです。たとえば、Linux用のTableau Serverには、ユーザーインスタンスを有効にするユーザーサービスが付属しています。

# cat /etc/systemd/system/[email protected]
[Unit]
Description=User Manager for UID %i
After=systemd-user-sessions.service
# These are present in the RHEL8 version of this file except that the unit is Requires, not Wants.
# It's listed as Wants here so that if this file is used in a RHEL7 settings, it will not fail.
# If a user upgrades from RHEL7 to RHEL8, this unit file will continue to work until it's
# deleted the next time they upgrade Tableau Server itself.
After=user-runtime-dir@%i.service
Wants=user-runtime-dir@%i.service

[Service]
LimitNOFILE=infinity
LimitNPROC=infinity
User=%i
PAMName=systemd-user
Type=notify
# PermissionsStartOnly is deprecated and will be removed in future versions of systemd
# This is required for all systemd versions prior to version 231
PermissionsStartOnly=true
ExecStartPre=/bin/loginctl enable-linger %i
ExecStart=-/lib/systemd/systemd --user
Slice=user-%i.slice
KillMode=mixed
Delegate=yes
TasksMax=infinity
Restart=always
RestartSec=15

[Install]
WantedBy=default.target

インスタンスと対話するときは、.bashrcまだXDG_RUNTIME_DIRが必要です。.profile

# cat /home/$(id -un 29575)/.bashrc
#!/bin/bash

[ -z "${XDG_RUNTIME_DIR}" ] && export XDG_RUNTIME_DIR=/run/user/$(id -ru)

# systemctl daemon-reload
# systemctl enable [email protected]
Created symlink from /etc/systemd/system/default.target.wants/[email protected] to /etc/systemd/system/[email protected].
# systemctl start [email protected]

# su -l -s /bin/bash -c "systemctl --user status" $(id -un 29575)
● hostname
    State: running
     Jobs: 0 queued
   Failed: 0 units
    Since: Tue 2020-09-22 12:12:48 UTC; 5min ago
   CGroup: /user.slice/user-29575.slice/[email protected]
           ├─18802 /lib/systemd/systemd --user
           └─18804 (sd-pam)

感謝の言葉https://access.redhat.com/solutions/3461241

おすすめ記事