我创建并启用了一个手动启动的 systemd 服务,但重新启动后不会自动启动。我如何找出它无法自动启动的原因?

我创建并启用了一个手动启动的 systemd 服务,但重新启动后不会自动启动。我如何找出它无法自动启动的原因?

我创建并启用了一个 systemd 服务,该服务在 Tmux 中启动 CLI 应用程序(必须禁用 SELinux),但该服务需要在重新启动后手动启动。我如何找出它无法自动启动的原因?

以下是有关该服务的一些信息:

[itadmin@SRV-LNX-RHEL01 ~]$ systemctl cat aescripts-LicenseServer.service 
# /etc/systemd/system/aescripts-LicenseServer.service
[Unit]
Description="Service that keeps runing the aescripts license server from startup."
[Install]
WantedBy=rescue.target
[Service]
User=itadmin
Type=forking
ExecStart=/usr/bin/tmux new-session -s itadmin -d bash -c '/home/itadmin/Dev/aescriptsLicenseServer_v3.5.6/Linux/aescriptsLicenseServer'
WorkingDirectory=/home/itadmin/Dev/aescriptsLicenseServer_v3.5.6/Linux
Restart=always
RestartSec=5
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=%n

[itadmin@SRV-LNX-RHEL01 ~]$ systemctl status aescripts-LicenseServer.service 
● aescripts-LicenseServer.service - "Service that keeps runing the aescripts license server from s>
   Loaded: loaded (/etc/systemd/system/aescripts-LicenseServer.service; enabled; vendor preset: di>
   Active: active (running) since Tue 2021-10-05 17:21:04 PDT; 5min ago
  Process: 7723 ExecStart=/usr/bin/tmux new-session -s itadmin -d bash -c /home/itadmin/Dev/aescri>
 Main PID: 7725 (tmux: server)
    Tasks: 2 (limit: 8144)
   Memory: 2.3M
   CGroup: /system.slice/aescripts-LicenseServer.service
           ├─7725 /usr/bin/tmux new-session -s itadmin -d bash -c /home/itadmin/Dev/aescriptsLicen>
           └─7726 /home/itadmin/Dev/aescriptsLicenseServer_v3.5.6/Linux/aescriptsLicenseServer

Oct 05 17:21:04 SRV-LNX-RHEL01 systemd[1]: Starting "Service that keeps runing the aescripts licen>
Oct 05 17:21:04 SRV-LNX-RHEL01 systemd[1]: Started "Service that keeps runing the aescripts licens>

[itadmin@SRV-LNX-RHEL01 ~]$ systemctl list-dependencies aescripts-LicenseServer.service 
aescripts-LicenseServer.service
● ├─-.mount
● ├─home.mount
● ├─system.slice
● └─sysinit.target
●   ├─dev-hugepages.mount
●   ├─dev-mqueue.mount
●   ├─dracut-shutdown.service
●   ├─import-state.service
●   ├─iscsi-onboot.service
●   ├─kmod-static-nodes.service
●   ├─ldconfig.service
●   ├─loadmodules.service
●   ├─lvm2-lvmpolld.socket
●   ├─lvm2-monitor.service
●   ├─multipathd.service
●   ├─nis-domainname.service
●   ├─plymouth-read-write.service
●   ├─plymouth-start.service
●   ├─proc-sys-fs-binfmt_misc.automount
●   ├─selinux-autorelabel-mark.service
●   ├─sys-fs-fuse-connections.mount
●   ├─sys-kernel-config.mount
●   ├─sys-kernel-debug.mount
●   ├─systemd-ask-password-console.path
●   ├─systemd-binfmt.service
●   ├─systemd-firstboot.service
●   ├─systemd-hwdb-update.service
●   ├─systemd-journal-catalog-update.service
●   ├─systemd-journal-flush.service
●   ├─systemd-journald.service
●   ├─systemd-machine-id-commit.service
●   ├─systemd-modules-load.service
●   ├─systemd-random-seed.service
●   ├─systemd-sysctl.service
●   ├─systemd-sysusers.service
●   ├─systemd-tmpfiles-setup-dev.service
●   ├─systemd-tmpfiles-setup.service
●   ├─systemd-udev-trigger.service
●   ├─systemd-udevd.service
●   ├─systemd-update-done.service
●   ├─systemd-update-utmp.service
●   ├─cryptsetup.target
●   ├─local-fs.target
●   │ ├─-.mount
●   │ ├─boot-efi.mount
●   │ ├─boot.mount
●   │ ├─home.mount
●   │ └─systemd-remount-fs.service
●   └─swap.target
●     └─dev-mapper-rhel\x2dswap.swap

答案1

您的服务仅在启动进入救援模式时才会启动:

[Install]
WantedBy=rescue.target
rescue.target

    A special target unit that pulls in the base system (including system mounts) and spawns a rescue shell. Isolate to this target in order to administer the system in single-user mode with all file systems mounted but with no services running, except for the most basic.

(从https://www.freedesktop.org/software/systemd/man/systemd.special.html#rescue.target)。

您确实希望在激活 multi-user.target 时启动您的服务:

multi-user.target

    A special target unit for setting up a multi-user system (non-graphical). This is pulled in by graphical.target.

    Units that are needed for a multi-user system shall add Wants= dependencies for their unit to this unit during installation. This is best configured via WantedBy=multi-user.target in the unit's [Install] section.

https://www.freedesktop.org/software/systemd/man/systemd.special.html#multi-user.target

相关内容