如何让我的 systemd 服务停止并在“停止会话”...“用户”...之前完成停止?

如何让我的 systemd 服务停止并在“停止会话”...“用户”...之前完成停止?

我看到这样的事情:

[  181.919605] preshutdown[3874]: Starting /home/ctor/bin/preshutdown
[  181.920611] crond[3284]: (CRON) INFO (Shutting down)
[  181.931087] systemd[1]: Stopping Session 2 of user ctor.
...
[  211.953070] systemd[1]: session-2.scope: Stopping timed out. Killing.
[  211.953183] systemd[1]: session-2.scope: Killing process 3584 (qubes-guid) with signal SIGKILL.
[  211.953372] systemd[1]: [email protected]: State 'stop-sigterm' timed out. Killing.
[  211.953742] systemd[1]: [email protected]: Killing process 3382 (systemd) with signal SIGKILL.
[  211.954105] systemd[1]: [email protected]: Killing process 3874 (preshutdown) with signal SIGKILL.
[  211.954153] systemd[1]: [email protected]: Killing process 4923 (sleep) with signal SIGKILL.
[  211.956105] systemd[1]: Stopped User Manager for UID 1000.
[  211.956164] systemd[1]: [email protected]: Unit entered failed state.
[  211.956186] systemd[1]: [email protected]: Failed with result 'timeout'.
[  211.956386] systemd[1]: Stopped Session 2 of user ctor.
[  211.956515] systemd[1]: session-2.scope: Unit entered failed state.
[  211.956877] systemd[1]: dev-disk-by\x2did-lvm\x2dpv\x2duuid\x2dpxC3ch\x2d0MF0\x2dOzJs\x2dJogd\x2d9rOz\x2dJkSt\x2dCf8G7m.device: Job dev-disk-by\x2did-lvm\x2dpv\x2duuid\x2dpxC3ch\x2d0MF0\x2dOzJs\x2dJogd\x2d9rOz\x2dJkSt\x2dCf8G7m.device/stop timed out.
[  211.956951] systemd[1]: Timed out stopping /dev/disk/by-id/lvm-pv-uuid-pxC3ch-0MF0-OzJs-Jogd-9rOz-JkSt-Cf8G7m.
[  211.957107] systemd[1]: dev-disk-by\x2did-lvm\x2dpv\x2duuid\x2dpxC3ch\x2d0MF0\x2dOzJs\x2dJogd\x2d9rOz\x2dJkSt\x2dCf8G7m.device: Job dev-disk-by\x2did-lvm\x2dpv\x2duuid\x2dpxC3ch\x2d0MF0\x2dOzJs\x2dJogd\x2d9rOz\x2dJkSt\x2dCf8G7m.device/stop failed with result 'timeout'.
[  211.957280] systemd[1]: dev-disk-by\x2did-dm\x2dname\x2dluks\x2d9ed952b5\x2d2aa8\x2d4564\x2db700\x2dfb23f5c9e94b.device: Job dev-disk-by\x2did-dm\x2dname\x2dluks\x2d9ed952b5\x2d2aa8\x2d4564\x2db700\x2dfb23f5c9e94b.device/stop timed out.
[  211.957335] systemd[1]: Timed out stopping /dev/disk/by-id/dm-name-luks-9ed952b5-2aa8-4564-b700-fb23f5c9e94b.
[  211.957398] systemd[1]: dev-disk-by\x2did-dm\x2dname\x2dluks\x2d9ed952b5\x2d2aa8\x2d4564\x2db700\x2dfb23f5c9e94b.device: Job dev-disk-by\x2did-dm\x2dname\x2dluks\x2d9ed952b5\x2d2aa8\x2d4564\x2db700\x2dfb23f5c9e94b.device/stop failed with result 'timeout'.
[  211.957611] systemd[1]: dev-block-253:0.device: Job dev-block-253:0.device/stop timed out.
[  211.957647] systemd[1]: Timed out stopping LVM PV pxC3ch-0MF0-OzJs-Jogd-9rOz-JkSt-Cf8G7m on /dev/dm-0.
[  211.957715] systemd[1]: dev-block-253:0.device: Job dev-block-253:0.device/stop failed with result 'timeout'.
[  211.957770] systemd[1]: dev-dm\x2d0.device: Job dev-dm\x2d0.device/stop timed out.
[  211.957798] systemd[1]: Timed out stopping /dev/dm-0.
[  211.957847] systemd[1]: dev-dm\x2d0.device: Job dev-dm\x2d0.device/stop failed with result 'timeout'.
[  211.957901] systemd[1]: dev-disk-by\x2did-dm\x2duuid\x2dCRYPT\x2dLUKS1\x2d9ed952b52aa84564b700fb23f5c9e94b\x2dluks\x2d9ed952b5\x2d2aa8\x2d4564\x2db700\x2dfb23f5c9e94b.device: Job dev-disk-by\x2did-dm\x2duuid\x2dCRYPT\x2dLUKS1\x2d9ed952b52aa84564b700fb23f5c9e94b\x2dluks\x2d9ed952b5\x2d2aa8\x2d4564\x2db700\x2dfb23f5c9e94b.device/stop timed out.
[  211.957972] systemd[1]: Timed out stopping /dev/disk/by-id/dm-uuid-CRYPT-LUKS1-9ed952b52aa84564b700fb23f5c9e94b-luks-9ed952b5-2aa8-4564-b700-fb23f5c9e94b.
[  211.958047] systemd[1]: dev-disk-by\x2did-dm\x2duuid\x2dCRYPT\x2dLUKS1\x2d9ed952b52aa84564b700fb23f5c9e94b\x2dluks\x2d9ed952b5\x2d2aa8\x2d4564\x2db700\x2dfb23f5c9e94b.device: Job dev-disk-by\x2did-dm\x2duuid\x2dCRYPT\x2dLUKS1\x2d9ed952b52aa84564b700fb23f5c9e94b\x2dluks\x2d9ed952b5\x2d2aa8\x2d4564\x2db700\x2dfb23f5c9e94b.device/stop failed with result 'timeout'.
[  211.958075] systemd[1]: sys-devices-virtual-block-dm\x2d0.device: Job sys-devices-virtual-block-dm\x2d0.device/stop timed out.
[  211.958174] systemd[1]: Timed out stopping /sys/devices/virtual/block/dm-0.
[  211.958222] systemd[1]: sys-devices-virtual-block-dm\x2d0.device: Job sys-devices-virtual-block-dm\x2d0.device/stop failed with result 'timeout'.
[  211.958774] systemd[1]: Removed slice User Slice of ctor.
[  211.958911] systemd[1]: Stopping Login Service...
[  211.960223] systemd[1]: Stopping Permit User Sessions...
[  211.964389] systemd[1]: Stopped Permit User Sessions.
[  211.964558] systemd[1]: Stopped Start Qubes VM sys-net.
[  211.964618] systemd[1]: Stopped Start Qubes VM sys-firewall.
[  211.966532] systemd[1]: Removed slice system-qubes\x2dvm.slice.
[  211.970050] systemd[1]: Stopping Qubes memory information reporter...
[  211.975886] systemd[1]: Stopped Qubes memory information reporter.
[  211.982513] systemd[1]: Stopping Qubes Dom0 startup setup...

以上preshutdown内容来自--user .service该日志中未提及的内容Stopping(我不知道为什么)。

但无论它是一个服务--user还是一个--system服务,我如何告诉 systemd 停止我的服务并在它尝试之前完成停止它Stopping Session X of user Y

如果你知道如何解决这个问题,那么你可能可以解决(或帮助我解决)也有一个,并收集那一点点赏金。

如果相关的话,这是我的--user服务(/usr/lib/systemd/user/mowron.service)生成了上述日志:

[Unit]
Description=Mowron
#Wants=
RequiresMountsFor=/home/ /dev/dm-0 /dev/disk/by-id/dm-uuid-CRYPT-LUKS1-9ed952b52aa84564b700fb23f5c9e94b-luks-9ed952b5-2aa8-4564-b700-fb23f5c9e94b /dev/disk/by-id/lvm-pv-uuid-pxC3ch-0MF0-OzJs-Jogd-9rOz-JkSt-Cf8G7m /dev/disk/by-id/dm-name-luks-9ed952b5-2aa8-4564-b700-fb23f5c9e94b /sys/devices/virtual/block/dm-0
After=qubes-db-dom0.service libvirtd.service xenconsoled.service qubesd.service qubes-qmemman.service systemd-udev-settle.service remote-fs.target remote-fs-pre.target systemd-user-sessions.service
Conflicts=shutdown.target reboot.target halt.target
#BindsTo=systemd-udev-settle.service systemd-user-sessions.service
#PartOf=systemd-user-sessions.service
#Wants=systemd-user-sessions.service
#Requires=systemd-user-sessions.service
#Failed to start mowron.service: Unit systemd-user-sessions.service not found.
#i mean, it's only here: /usr/lib/systemd/system/systemd-user-sessions.service



[Service]
Type=oneshow
RemainAfterExit=yes
ExecStart=/bin/true
ExecStop=/home/ctor/bin/preshutdown

[Install]
WantedBy=default.target

Fedora 25 systemd 版本(我无法升级):

[ctor@dom0 ~]$ systemctl --version
systemd 231
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN

相关内容