0

I see something like this:

[  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...

The preshutdown above is from a --user .service that isn't mentioned in that log as Stopping (I don't know why).

But regardless of whether it's a --user or --system service, how can I tell systemd to stop my service and finish stopping it BEFORE it attempts to Stopping Session X of user Y ?

If you know how to solve this question, then you can probably solve (or help me solve) this one too, and collect that tiny bounty.

If relevant, this is my --user service (/usr/lib/systemd/user/mowron.service) that generated the above log:

[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 version (I can't upgrade):

[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
  • Sounds-like an X-Y problem. Consider start this service process inside a session. – 炸鱼薯条德里克 Sep 10 '18 at 08:05
  • @神秘德里克 How do I do that? I believe it's already starting in a session due to it being a `--user` service, no? ie. `systemctl --user status mowron` shows `active`. It's in `/home/ctor/.config/systemd/user/default.target.wants/mowron.service`, well, that's a symlink to `/usr/lib/systemd/user/mowron.service`. –  Sep 10 '18 at 08:31
  • How could a user service be in a session?! People, it's service, SERVICE! You are using LOGIND. I'm just saying, I'm actually not quite sure about your needs, `Stopping Session X of user Y`? Do you know that as long as you don't reboot, session names are never re-used, so the name X will only appear once, it's closed, then it's gone forever. So your process is basically useless after the X session is closed. Remember, the name, X, will never com black. If so, why do you want to run it as a service? – 炸鱼薯条德里克 Sep 10 '18 at 09:53
  • And plus, /bin/true ? What kind of process will run such boring program, what kind of functionality it's providing? Sorry about the yelling, but you need to know what is considered as a service and a user session since you are using the damn systemd. By the way, kernel don't know the concept 'service', and really don't think 'session' as you or systemd. – 炸鱼薯条德里克 Sep 10 '18 at 09:57
  • @神秘德里克 I don't really know what a session is, I only need to know what to put in my `.service` file so that my service is stopped before that User Session :) My service is supposed to stop all running VMs so that the following DM devices can be stopped without timing out(which happens because the VMs are using those dm-0 etc devices) –  Sep 10 '18 at 10:00
  • Personal suggestions, just a script that communicate with your VM manager , requesting it to stop all VM and return the result to you. If all the termination succeed, you can then stop all DM devices. Why such client side functionality has to be a systemd service? – 炸鱼薯条德里克 Sep 10 '18 at 10:11
  • If your VM perfectly integrated with systemd-machined, you can easily do this by machinectl, if it doesn't, I believe there is some method to IPC with it and ask it to stop. – 炸鱼薯条德里克 Sep 10 '18 at 10:14
  • @神秘德里克 I don't actually know what is stopping those DM devices nor how I can run my script before they are stopped. I want to know exactly that, but that question is [here](https://unix.stackexchange.com/q/467232/306023). I don't have `machinectl` (did you mean `systemctl` ?) nor `systemd-machined`. The current question is about me trying to workaround not knowing how to run "the script that stops all running VMs" **before** those DM devices are attempted to be stopped (by systemd). Systemd is complicated stuff. –  Sep 10 '18 at 10:41
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/82955/discussion-between-marcus-linsner-and-). –  Sep 10 '18 at 10:41

0 Answers0