help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to cleanly stop emacs daemon from commandline?


From: Tom Roche
Subject: Re: how to cleanly stop emacs daemon from commandline?
Date: Sat, 01 Oct 2016 20:31:47 -0700
User-agent: GNU Emacs 24.4.1 (x86_64-pc-linux-gnu, GTK+ Version 3.14.5)

[endnotes after .sig]

Tom Roche Sat, 01 Oct 2016 19:49:49 -0700[0]
> summary: I have tried several variations of

> $ emacsclient -e '(your-elisp-here)'

> and have found none that would cause a running `emacs --daemon` process (EDP) 
> to stop "cleanly" as defined by T.V. Raman (below):

> 1. release all locks (I have tested only desktop lock)
> 2. stop (e.g., such that `pgrep -l emacs` no longer shows its PID)

> Is there no way to do this? Conversely, is the EDP designed to run until 
> brutally whacked? (with, e.g., `kill -9 ${PID}`)

> details:

> This seems to be a longstanding request, as a nearly similar thread[1] is 
> almost 5 years old:

> From: T. V. Raman
> To: emacs-devel@ gnu.org
> Subject: HowTo: quit an emacs --daemon
> Date: Tue, 22 Nov 2011 19:43:34 -0800

> > quitting out of all emacsclient sessions still
> > keeps the daemon around -- and killing that process feels crude

> e.g., `kill -9 ${PID}` or `pkill -9 emacs`

> > -- it then leaves files like the emacs.desktop file locked. Is
> > there a clean way of asking a running emacs --daemon process to quit?

> but IIRC similar posts go back to 2009. My situation is similar, except that 
> I'm re/starting my daemon as part of porting my Emacs config to a new base 
> (details here[2]). My verification process is

> 0. Exit Emacs client if in one (`C-x C-c`)
> 1. Move to a bash shell for all subsequent steps
> 2. Check EDP (et al) and desktop lockfile(s) with the following bash oneliner:

> date ; pgrep -l emacs ; find ~/ -maxdepth 1 -type d -name '.emacs.d_*' | 
> xargs -i find {} -type f -name '*lock'

> 3. Run the emacsclient oneliner under test (see below)
> 4. Recheck with bash oneliner

Forgot to mention that, between test sessions, I whack EDPs and lockfiles with 
the following bash script:

    while read EDP_PGREP ; do
        EDP_PID="${EDP_PGREP%% *}"
        for CMD in \
            'date' \
            "kill -9 ${EDP_PID}" \
        ; do
            echo -e "${CMD}"
            eval "${CMD}"
        done
    done < <(pgrep -l emacs)
    echo # newline

    while read LOCK_FP ; do
        for CMD in \
            'date' \
            "rm ${LOCK_FP}" \
        ; do
            echo -e "${CMD}"
            eval "${CMD}"
        done
    done < <(find ~/ -maxdepth 1 -type d -name '.emacs.d_*' | xargs -i find {} 
-type f -name '*lock')
    echo

until I get output only from `date`.

> In no case have I found an emacsclient oneliner (or any other shell command) 
> that is 'clean' as defined by Dr Raman. I have tried numerous substitutions 
> for '(your-elisp-here)', including

> 1. (kill-emacs): often recommended, but I do not observe either the EDP to 
> stop or desktop lockfile to be removed after running `emacsclient -e 
> '(kill-emacs)'`

> 2. (save-buffers-kill-emacs): ditto

> 3. (save-buffers-kill-terminal): ditto

> 4. As recommended here[3], I tried adding

> (defun tv-stop-emacs ()
>   (interactive)
>   (if (daemonp)
>       (save-buffers-kill-emacs)
>       (save-buffers-kill-terminal)))

>    to my Emacs config, then `eval-region`,

Forgot to mention that I also tried running `M-x tv-stop-emacs` from the 
client: it exits the client, but fails to cleanly stop the daemon, as the above 
test procedure shows both a lockfile and an EDP.

> but running `emacsclient -e '(tv-stop-emacs)'` from the commandline failed 
> the above test procedure.

> 5. (run-with-timer 0 0 'save-buffers-kill-emacs): recommended here[4], but 
> gives error=

> > *ERROR*: Invalid repetition interval

>    By contrast, `(run-with-timer 0 1 'save-buffers-kill-emacs)` just fails to 
> work as claimed.

> I'm fairly sure I have tried other emacsclient oneliners that I have 
> forgotten (as minor variations on the above). It seems odd that lotsa folks 
> believe this can be done, but nothing I've found seems to work. Am I missing 
> something? If this usecase *is* working for OP, how to debug my situation?

> platform:

> Kinda vanilla, slightly downlevel but I wanna fix something before I upgrade 
> my kernel, and I wanted to update my Emacs config in order to pull in some 
> tools that I wanted to use in order to fix it :-(

> $ date
> Sat Oct  1 19:01:14 MST 2016
> $ uname -rsv
> Linux 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2+deb8u3 (2016-07-02)
> $ lsb_release -ds
> LMDE 2 Betsy
> $ cat /etc/debian_version
> 8.5
> $ gcc --version | head -n 1
> gcc (Debian 4.9.2-10) 4.9.2
> $ emacs --version | head -1
> GNU Emacs 24.4.1

> your assistance is appreciated, Tom Roche <address@hidden>

[0]: I'd link to it, but the archives are not currently "refreshing every 30 
minutes" as claimed @ 
https://lists.gnu.org/archive/html/help-gnu-emacs/2016-10/threads.html
[1]: https://lists.gnu.org/archive/html/emacs-devel/2011-11/msg00342.html
[2]: http://emacs.stackexchange.com/q/27376/5444
[3]: https://lists.gnu.org/archive/html/emacs-devel/2011-11/msg00348.html
[4]: https://lists.gnu.org/archive/html/help-gnu-emacs/2009-08/msg00757.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]