From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tom Roche Newsgroups: gmane.emacs.help Subject: Re: how to cleanly stop emacs daemon from commandline? Date: Sat, 01 Oct 2016 20:31:47 -0700 Message-ID: <877f9rctp8.fsf@pobox.com> References: <87h98vcvn6.fsf@pobox.com> Reply-To: help-gnu-emacs@gnu.org, Tom Roche NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1475396478 18793 195.159.176.226 (2 Oct 2016 08:21:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 2 Oct 2016 08:21:18 +0000 (UTC) User-Agent: GNU Emacs 24.4.1 (x86_64-pc-linux-gnu, GTK+ Version 3.14.5) To: help-gnu-emacs@gnu.org, Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Oct 02 10:21:13 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bqc11-0001zl-C8 for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Oct 2016 10:20:55 +0200 Original-Received: from localhost ([::1]:58508 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqc0z-0008LM-VQ for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Oct 2016 04:20:53 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42785) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqXVR-0007EO-MO for help-gnu-emacs@gnu.org; Sat, 01 Oct 2016 23:32:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bqXVM-0007Yz-3i for help-gnu-emacs@gnu.org; Sat, 01 Oct 2016 23:32:00 -0400 Original-Received: from pb-smtp2.pobox.com ([64.147.108.71]:53970 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqXVL-0007Yo-VG for help-gnu-emacs@gnu.org; Sat, 01 Oct 2016 23:31:56 -0400 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 5DB4C42F23; Sat, 1 Oct 2016 23:31:54 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:in-reply-to:references:reply-to:date:message-id :mime-version:content-type; s=sasl; bh=R2dnZZ1/I4/87NuJSGIECKnzW zE=; b=xxW1UHulUasJiM7DfWJHqI3zs+psUnnKWg2I8yPhuLFms7/tyCcMvcnSj sYN7kkG/S+L4DmujAWRxQHy9r+tFy0yirx/JP+IjyBXX7PJlrUTGN/2glYymviYE TEL/mnVncut/uWX7Jvoy2h9m1JszofmF85XchH6XpBrR25HxEo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :in-reply-to:references:reply-to:date:message-id:mime-version :content-type; q=dns; s=sasl; b=WZYGGQzwn2X4Wg22PxF2lLIBvRwOjzte d9+GwHewQIaxG5L8IJvqef4Oo4PhBfhtck3wI8WR9sl8dLyfNwv2fPygKDh4luQz lKrlxmW1LeLHmHXjJxo6MI0LfSWWp7kMjvGLX+Rsl9SAIP1hEcb7hod9iN8et2HV UPLVjPSeTx4= Original-Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 53B8242F22; Sat, 1 Oct 2016 23:31:54 -0400 (EDT) Original-Received: from tlrW510.pobox.com (unknown [173.20.44.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id A720942F21; Sat, 1 Oct 2016 23:31:53 -0400 (EDT) In-Reply-To: <87h98vcvn6.fsf@pobox.com> X-Pobox-Relay-ID: C366EEE4-8850-11E6-95D1-EAAE7A1B28F4-07218935!pb-smtp2.pobox.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 64.147.108.71 X-Mailman-Approved-At: Sun, 02 Oct 2016 04:20:12 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:111432 Archived-At: [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 [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