![登录后,手动重新启动用户管理器之前](https://linux22.com/image/214405/%E7%99%BB%E5%BD%95%E5%90%8E%EF%BC%8C%E6%89%8B%E5%8A%A8%E9%87%8D%E6%96%B0%E5%90%AF%E5%8A%A8%E7%94%A8%E6%88%B7%E7%AE%A1%E7%90%86%E5%99%A8%E4%B9%8B%E5%89%8D.png)
我在 WSL2 上运行 Ubuntu 22.04,并启用了 systemd 支持。我的配置直到两天前都运行良好。我使用 TMUX 及其插件 tmux-resurrect 和 tmux-continuum,后者已经添加了一项用户服务,该服务在我登录时启动我的 TMUX 服务器。几天来,我一直在编写一个自定义用户服务,该服务应该保存/恢复每个 TMUX 窗格的环境变量。脚本本身工作得很好,但是通过登录时的用户服务,我的tmux
(tmux-continuum)和我自己的服务之间存在计时或依赖关系问题,tmux-environments
并且它不起作用。所以我的想法是以 root 身份连接到另一个终端并监视服务日志,同时我使用我的用户登录和注销,并了解执行的时间和顺序。
为此,我运行了pkill -KILL -u $USER
,因为仅仅关闭所有终端和 Visual Studio Code 是不够的;仍然有一些进程在我的用户下运行。也许这是 WSL2 的症结所在,但自从我运行该命令以来,我的用户管理器似乎不再正确启动,尽管日志中没有可见的错误。
下面我添加了两个不同时间点的多个命令的输出。第一个时间点是在我启动 WSL2 之后并且我的用户登录之后。第二个时间点是在我手动重新启动用户管理器之后。
登录后,手动重新启动用户管理器之前
sebastian$ systemctl list-unit-files --type=service --user
Failed to connect to bus: No such file or directory
sebastian$ loginctl show-user sebastian
UID=1000
GID=1000
Name=sebastian
Timestamp=Fri 2022-12-09 16:56:47 CET
TimestampMonotonic=4543003
RuntimePath=/run/user/1000
[email protected]
Slice=user-1000.slice
Display=c1
State=active
Sessions=c1
IdleHint=no
IdleSinceHint=1670601410831279
IdleSinceHintMonotonic=7494053
Linger=yes
root$ systemctl status [email protected]
● [email protected] - User Manager for UID 1000
Loaded: loaded (/lib/systemd/system/[email protected]; static)
Drop-In: /usr/lib/systemd/system/[email protected]
└─timeout.conf
Active: active (running) since Fri 2022-12-09 16:56:48 CET; 19s ago
Docs: man:[email protected](5)
Main PID: 362 (systemd)
Status: "Startup finished in 65ms."
Tasks: 2
Memory: 4.1M
CGroup: /user.slice/user-1000.slice/[email protected]
└─init.scope
├─362 /lib/systemd/systemd --user
└─363 "(sd-pam)"
root$ journalctl --full -u [email protected]
...
Dec 09 16:56:48 vega systemd[1]: Starting User Manager for UID 1000...
Dec 09 16:56:48 vega systemd[362]: pam_unix(systemd-user:session): session opened for user sebastian(uid=1000) by (uid=0)
Dec 09 16:56:48 vega systemd[362]: Queued start job for default target Main User Target.
Dec 09 16:56:48 vega systemd[362]: Created slice User Application Slice.
Dec 09 16:56:48 vega systemd[362]: Reached target Paths.
Dec 09 16:56:48 vega systemd[362]: Reached target Timers.
Dec 09 16:56:48 vega systemd[362]: Starting D-Bus User Message Bus Socket...
Dec 09 16:56:48 vega systemd[362]: Listening on GnuPG network certificate management daemon.
Dec 09 16:56:48 vega systemd[362]: Listening on GnuPG cryptographic agent and passphrase cache (access for web browsers>
Dec 09 16:56:48 vega systemd[362]: Listening on GnuPG cryptographic agent and passphrase cache (restricted).
Dec 09 16:56:48 vega systemd[362]: Listening on GnuPG cryptographic agent (ssh-agent emulation).
Dec 09 16:56:48 vega systemd[362]: Listening on GnuPG cryptographic agent and passphrase cache.
Dec 09 16:56:48 vega systemd[362]: Listening on debconf communication socket.
Dec 09 16:56:48 vega systemd[362]: Listening on REST API socket for snapd user session agent.
Dec 09 16:56:48 vega systemd[362]: Listening on D-Bus User Message Bus Socket.
Dec 09 16:56:48 vega systemd[362]: Reached target Sockets.
Dec 09 16:56:48 vega systemd[362]: Reached target Basic System.
Dec 09 16:56:48 vega systemd[362]: Reached target Main User Target.
Dec 09 16:56:48 vega systemd[362]: Startup finished in 63ms.
Dec 09 16:56:48 vega systemd[1]: Started User Manager for UID 1000.
root$ ls -lah /run/user/1000
total 0
drwx------ 4 sebastian sebastian 120 Dec 9 16:56 .
drwxr-xr-x 4 root root 80 Dec 9 16:57 ..
drwx------ 3 sebastian sebastian 60 Dec 9 16:56 dbus-1
drwx------ 2 sebastian sebastian 80 Dec 9 16:56 pulse
srwxrwxrwx 1 sebastian sebastian 0 Dec 9 16:56 wayland-0
-rw-rw---- 1 sebastian sebastian 0 Dec 9 16:56 wayland-0.lock
然后我运行它来手动重新启动用户管理器
root$ systemctl restart [email protected]
手动重启用户管理器后
sebastian$ systemctl list-unit-files --type=service --user
UNIT FILE STATE VENDOR PRESET
app-snap\x2duserd\[email protected] generated -
dbus.service static -
dirmngr.service static -
gpg-agent.service static -
...
sebastian$ loginctl show-user sebastian
UID=1000
GID=1000
Name=sebastian
Timestamp=Fri 2022-12-09 16:56:47 CET
TimestampMonotonic=4543003
RuntimePath=/run/user/1000
[email protected]
Slice=user-1000.slice
Display=c1
State=active
Sessions=c1
IdleHint=no
IdleSinceHint=1670601410831279
IdleSinceHintMonotonic=7494053
Linger=yes
root$ systemctl status [email protected]
● [email protected] - User Manager for UID 1000
Loaded: loaded (/lib/systemd/system/[email protected]; static)
Drop-In: /usr/lib/systemd/system/[email protected]
└─timeout.conf
Active: active (running) since Fri 2022-12-09 17:06:43 CET; 23s ago
Docs: man:[email protected](5)
Main PID: 1315 (systemd)
Status: "Startup finished in 65ms."
Tasks: 2
Memory: 4.1M
CGroup: /user.slice/user-1000.slice/[email protected]
└─init.scope
├─1315 /lib/systemd/systemd --user
└─1316 "(sd-pam)"
root$ journalctl --full -u [email protected]
...
Dec 09 17:06:43 vega systemd[1]: Stopping User Manager for UID 1000...
Dec 09 17:06:43 vega systemd[362]: Stopped target Main User Target.
Dec 09 17:06:43 vega systemd[362]: Stopped target Basic System.
Dec 09 17:06:43 vega systemd[362]: Stopped target Paths.
Dec 09 17:06:43 vega systemd[362]: Stopped target Sockets.
Dec 09 17:06:43 vega systemd[362]: Stopped target Timers.
Dec 09 17:06:43 vega systemd[362]: Closed D-Bus User Message Bus Socket.
Dec 09 17:06:43 vega systemd[362]: Closed GnuPG network certificate management daemon.
Dec 09 17:06:43 vega systemd[362]: Closed GnuPG cryptographic agent and passphrase cache (access for web browsers).
Dec 09 17:06:43 vega systemd[362]: Closed GnuPG cryptographic agent and passphrase cache (restricted).
Dec 09 17:06:43 vega systemd[362]: Closed GnuPG cryptographic agent (ssh-agent emulation).
Dec 09 17:06:43 vega systemd[362]: Closed GnuPG cryptographic agent and passphrase cache.
Dec 09 17:06:43 vega systemd[362]: Closed debconf communication socket.
Dec 09 17:06:43 vega systemd[362]: Closed REST API socket for snapd user session agent.
Dec 09 17:06:43 vega systemd[362]: Removed slice User Application Slice.
Dec 09 17:06:43 vega systemd[362]: Reached target Shutdown.
Dec 09 17:06:43 vega systemd[362]: Finished Exit the Session.
Dec 09 17:06:43 vega systemd[362]: Reached target Exit the Session.
Dec 09 17:06:43 vega systemd[1]: [email protected]: Deactivated successfully.
Dec 09 17:06:43 vega systemd[1]: Stopped User Manager for UID 1000.
Dec 09 17:06:43 vega systemd[1]: Starting User Manager for UID 1000...
Dec 09 17:06:43 vega systemd[1315]: pam_unix(systemd-user:session): session opened for user sebastian(uid=1000) by (uid=0)
Dec 09 17:06:43 vega systemd[1315]: Queued start job for default target Main User Target.
Dec 09 17:06:43 vega systemd[1315]: Created slice User Application Slice.
Dec 09 17:06:43 vega systemd[1315]: Reached target Paths.
Dec 09 17:06:43 vega systemd[1315]: Reached target Timers.
Dec 09 17:06:43 vega systemd[1315]: Starting D-Bus User Message Bus Socket...
Dec 09 17:06:43 vega systemd[1315]: Listening on GnuPG network certificate management daemon.
Dec 09 17:06:43 vega systemd[1315]: Listening on GnuPG cryptographic agent and passphrase cache (access for web browser>
Dec 09 17:06:43 vega systemd[1315]: Listening on GnuPG cryptographic agent and passphrase cache (restricted).
Dec 09 17:06:43 vega systemd[1315]: Listening on GnuPG cryptographic agent (ssh-agent emulation).
Dec 09 17:06:43 vega systemd[1315]: Listening on GnuPG cryptographic agent and passphrase cache.
Dec 09 17:06:43 vega systemd[1315]: Listening on debconf communication socket.
Dec 09 17:06:43 vega systemd[1315]: Listening on REST API socket for snapd user session agent.
Dec 09 17:06:43 vega systemd[1315]: Listening on D-Bus User Message Bus Socket.
Dec 09 17:06:43 vega systemd[1315]: Reached target Sockets.
Dec 09 17:06:43 vega systemd[1315]: Reached target Basic System.
Dec 09 17:06:43 vega systemd[1315]: Reached target Main User Target.
Dec 09 17:06:43 vega systemd[1315]: Startup finished in 44ms.
Dec 09 17:06:43 vega systemd[1]: Started User Manager for UID 1000.
root$ ls -lah /run/user/1000
total 0
drwx------ 6 sebastian sebastian 220 Dec 9 17:06 .
drwxr-xr-x 4 root root 80 Dec 9 16:57 ..
srw-rw-rw- 1 sebastian sebastian 0 Dec 9 17:06 bus
drwx------ 3 sebastian sebastian 60 Dec 9 16:56 dbus-1
drwx------ 2 sebastian sebastian 140 Dec 9 17:06 gnupg
srw-rw-rw- 1 sebastian sebastian 0 Dec 9 17:06 pk-debconf-socket
drwx------ 2 sebastian sebastian 80 Dec 9 16:56 pulse
srw-rw-rw- 1 sebastian sebastian 0 Dec 9 17:06 snapd-session-agent.socket
drwxr-xr-x 5 sebastian sebastian 140 Dec 9 17:06 systemd
srwxrwxrwx 1 sebastian sebastian 0 Dec 9 16:56 wayland-0
-rw-rw---- 1 sebastian sebastian 0 Dec 9 16:56 wayland-0.lock
正如您所看到的loginctl
,systemctl status
(以 root 身份运行)和journalctl
输出基本相同,但需要手动重新启动用户管理器才能获取下的systemd
目录、bus
套接字和其他内容/run/user/1000
。最终,两者都需要使用 systemd 工具以及用户服务。
但是,每次手动重新启动用户管理器对我来说并不是解决方案,因为登录服务根本不会自行启动。
有谁知道导致这个问题的原因以及如何解决它?我绝不是 Linux 专家用户,所以我很高兴能得到任何可以进一步研究的建议和技巧。