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: how to cleanly stop emacs daemon from commandline? Date: Sat, 01 Oct 2016 19:49:49 -0700 Message-ID: <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 1475396474 17238 195.159.176.226 (2 Oct 2016 08:21:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 2 Oct 2016 08:21:14 +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:07 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 1bqc0z-0001jO-GZ for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Oct 2016 10:20:53 +0200 Original-Received: from localhost ([::1]:58507 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqc0y-0008Jz-5Q for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Oct 2016 04:20:52 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40306) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqWqs-0002F2-L1 for help-gnu-emacs@gnu.org; Sat, 01 Oct 2016 22:50:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bqWqm-0008Do-Vn for help-gnu-emacs@gnu.org; Sat, 01 Oct 2016 22:50:05 -0400 Original-Received: from pb-smtp2.pobox.com ([64.147.108.71]:59265 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqWqm-0008DK-Rs for help-gnu-emacs@gnu.org; Sat, 01 Oct 2016 22:50:00 -0400 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id B4AF142BB6; Sat, 1 Oct 2016 22:49:56 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:reply-to:date:message-id:mime-version:content-type; s= sasl; bh=SWG0pS6POUE+29hDQb7IrhdjDL4=; b=MAHthO9wGd0RN67wm1EkGCo 1e+EIptzFqbT5JWPOS6JYIiJ94I5Jm2bml0kXVk3LCbnASKVINmH5jRX2BY5JWjA X7APwwnj9/etixJtBFx9B+CxEvkVSC+s3g3sHhiBSzAUyQICYdY5iOYjNIL+HmX7 B6UnD4B3FtehgeSpOdvc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :reply-to:date:message-id:mime-version:content-type; q=dns; s= sasl; b=wZqWxAhLNy5vsZ2cC+dJ3xYS5D+OIgDiyvx3lny537Iq4UkNMkXBeHY1 ezpECL72SuVIW197NJgaLNLqGxBs3ui3Xe0BWKXg5sSbuIrC6pdmTcRlOMN8aHS4 fgwPO113lAhln5gASk6Jk4akSqPT/FzdztAvLkLM8b4WwXDlPJw= Original-Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id AB38542BB5; Sat, 1 Oct 2016 22:49:56 -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 11B9A42BB4; Sat, 1 Oct 2016 22:49:55 -0400 (EDT) X-Pobox-Relay-ID: E6CA1498-884A-11E6-9C2B-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:111431 Archived-At: [endnotes after .sig] 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 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`, 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 [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