all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tom Roche <Tom_Roche@pobox.com>
To: help-gnu-emacs@gnu.org,
Subject: Re: how to cleanly stop emacs daemon from commandline?
Date: Sat, 01 Oct 2016 20:31:47 -0700	[thread overview]
Message-ID: <877f9rctp8.fsf@pobox.com> (raw)
In-Reply-To: <87h98vcvn6.fsf@pobox.com>


[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 <Tom_Roche@pobox.com>

[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	other threads:[~2016-10-02  3:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-02  2:49 how to cleanly stop emacs daemon from commandline? Tom Roche
2016-10-02  3:31 ` Tom Roche [this message]
2016-10-02  8:45 ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877f9rctp8.fsf@pobox.com \
    --to=tom_roche@pobox.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.