I use emacs a lot and restart it since I change my init.el from time to time, so I started to use emacs.service about one year ago using command like
systemctl --user enable emacs.service
systemctl --user start emacs.service
/usr/lib/systemd/user/emacs.service
will be symbolinked as ~/.config/systemd/user/default.target.wants/emacs.service
the content of the emacs.service is:
$ cat /usr/lib/systemd/user/emacs.service
[Unit]
Description=Emacs text editor
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/
[Service]
Type=notify
ExecStart=/usr/bin/emacs --fg-daemon
ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)"
# The location of the SSH auth socket varies by distribution, and some
# set it from PAM, so don't override by default.
# Environment=SSH_AUTH_SOCK=%t/keyring/ssh
Restart=on-failure
[Install]
WantedBy=default.target
so every time I start my computer, emacs daemon will be started in emacs.service in background, and I only need to start emacsclient to open emacs window to edit my files.
OK, this is just background, people familiar with emacs know what I'm talking about.
But I have been suffering a problem for a long time, and for some reasons, recently I have to reboot my computer repeatedly and this problem occurs to me many times, so this is the time I need to fix it.
When I reboot or shutdown my computer, the black screen will always display the following message:
A stop job is running for User Manager for UID 1000 (x / 2mins)
and I have to wait for 2 mins to successfully reboot or shutdown my computer, of cause I can just Ctrl-Alt-Delete
to force it to restart/shutdown, but this is happening when I use Linux in VirtualBox a guest OS since Ctrl-Alt-Delete
is for host OS, ANYWAY, typing Ctrl-Alt-Delete
to force it to restart/shutdown to me.
I tried to disable emacs.service using systemctl --user disable emacs.service; systemctl --user stop emacs.service
, and reboot, the message is gone, and my computer restarts very quickly.
And I tried to analyze the journal log using `journalctl -rb -1q, there is some lines like:
Oct 28 16:29:21 chz-pc kernel: audit: type=1131 audit(1572251361.509:103): pid=1 uid=0 auid=4294967295 ses=4294967295 subj==unconfined msg='unit=user@1000 comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? >
Oct 28 16:29:21 chz-pc kernel: kauditd_printk_skb: 7 callbacks suppressed
Oct 28 16:29:21 chz-pc systemd[1]: Stopping User Runtime Directory /run/user/1000...
Oct 28 16:29:21 chz-pc audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 subj==unconfined msg='unit=user@1000 comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=failed'
Oct 28 16:29:21 chz-pc systemd[1]: Stopped User Manager for UID 1000.
Oct 28 16:29:21 chz-pc systemd[1]: user@1000.service: Failed with result 'timeout'.
Oct 28 16:29:21 chz-pc systemd[1]: user@1000.service: Killing process 876 (emacs) with signal SIGKILL.
Oct 28 16:29:21 chz-pc systemd[1]: user@1000.service: Killing process 866 (systemd) with signal SIGKILL.
Oct 28 16:29:21 chz-pc systemd[1]: user@1000.service: State 'stop-sigterm' timed out. Killing.
Oct 28 16:28:51 chz-pc emacs[876]: Buffer recentf<3> modified; kill anyway? (y or n)
Oct 28 16:28:51 chz-pc systemd[866]: emacs.service: Control process exited, code=killed, status=15/TERM
Oct 28 16:28:51 chz-pc systemd[866]: emacs.service: Stopping timed out. Terminating.
Oct 28 16:27:22 chz-pc audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 subj==unconfined msg='unit=systemd-logind comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=su>
Oct 28 16:27:22 chz-pc systemd[1]: Stopped Login Service.
Oct 28 16:27:22 chz-pc systemd[1]: systemd-logind.service: Succeeded.
So stopping emacs.service timed out, and it gets stuck there for over 1 minute,
And I tried to edit /etc/systemd/system.conf
and setting DefaultTimeoutStopSec=5s
, but it seems it doens't work at all.
So is there better solution that I don't have to see this message and normally reboot/shutdown as fast as I know without stopping the emacs.service first manually?
BTW:
OS: Manjaro+KDE, or openSUSE Tumbleweed+KDE
emacs version: 26.2/26.3/27.0
platform: VirtualBox or real hardware
my-kill-or-save-buffers
function and hook it via(add-hook 'kill-emacs-hook #'my-kill-or-save-buffers)
– jue Oct 28 '19 at 11:16Buffer recentf<3> modified; kill anyway? (y or n)
– Nsukami _ Oct 28 '19 at 13:24recentf-save-list
is already inkill-emacs-hook
– CodyChan Oct 29 '19 at 7:04kill-emacs-hook
. Or disablerecentf
for some tests. Then test emacs server killing with systemd's restart facilities. It's difficult to debug your setup from here. On my system this kinda stuff works... – jue Oct 30 '19 at 9:54