From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: joakim@verona.se Newsgroups: gmane.emacs.bugs Subject: bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon. Date: Wed, 03 Dec 2014 22:16:45 +0100 Message-ID: References: <5741989.eboZExnV48@descartes> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1417641507 13397 80.91.229.3 (3 Dec 2014 21:18:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 3 Dec 2014 21:18:27 +0000 (UTC) Cc: 16507@debbugs.gnu.org, emacs-devel@gnu.org To: =?UTF-8?Q?R=C3=BCdiger?= Sonderfeld Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Dec 03 22:18:20 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XwHJP-0002B7-Nj for geb-bug-gnu-emacs@m.gmane.org; Wed, 03 Dec 2014 22:18:15 +0100 Original-Received: from localhost ([::1]:43410 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XwHJP-0008Ua-Au for geb-bug-gnu-emacs@m.gmane.org; Wed, 03 Dec 2014 16:18:15 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XwHJI-0008UO-0N for bug-gnu-emacs@gnu.org; Wed, 03 Dec 2014 16:18:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XwHJC-000599-Vl for bug-gnu-emacs@gnu.org; Wed, 03 Dec 2014 16:18:07 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:55814) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XwHJC-000591-Rl for bug-gnu-emacs@gnu.org; Wed, 03 Dec 2014 16:18:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XwHJC-0007jE-Aq for bug-gnu-emacs@gnu.org; Wed, 03 Dec 2014 16:18:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: joakim@verona.se Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 03 Dec 2014 21:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16507 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 16507-submit@debbugs.gnu.org id=B16507.141764144029648 (code B ref 16507); Wed, 03 Dec 2014 21:18:02 +0000 Original-Received: (at 16507) by debbugs.gnu.org; 3 Dec 2014 21:17:20 +0000 Original-Received: from localhost ([127.0.0.1]:53027 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XwHIS-0007i3-Il for submit@debbugs.gnu.org; Wed, 03 Dec 2014 16:17:20 -0500 Original-Received: from mx1.bahnhof.se ([213.80.101.11]:59922) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XwHIN-0007hn-TN for 16507@debbugs.gnu.org; Wed, 03 Dec 2014 16:17:15 -0500 Original-Received: from localhost (mf.bahnhof.se [213.80.101.20]) by mx1-reinject (Postfix) with ESMTP id 6A5C240AB6; Wed, 3 Dec 2014 22:17:10 +0100 (CET) X-Virus-Scanned: by amavisd-new using ClamAV at bahnhof.se (MF4) Original-Received: from mf4.bahnhof.se ([127.0.0.1]) by localhost (mf4.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wkPXKsibk6gj; Wed, 3 Dec 2014 22:17:00 +0100 (CET) Original-Received: from mta.verona.se (h-235-102.a149.priv.bahnhof.se [85.24.235.102]) by mf4.bahnhof.se (Postfix) with ESMTP id C60953D77FA; Wed, 3 Dec 2014 22:16:59 +0100 (CET) Original-Received: from localhost (unknown [127.0.0.1]) by mta.verona.se (Postfix) with ESMTP id 7F3BB52720D; Wed, 3 Dec 2014 21:16:59 +0000 (UTC) X-Virus-Scanned: amavisd-new at verona.se Original-Received: from mta.verona.se ([127.0.0.1]) by localhost (exodia.verona.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Mkl5ruL1J6Ei; Wed, 3 Dec 2014 22:16:45 +0100 (CET) Original-Received: from exodia.verona.se (www.verona.se [192.168.200.15]) by mta.verona.se (Postfix) with ESMTP id E7DC6527205; Wed, 3 Dec 2014 22:16:45 +0100 (CET) In-Reply-To: <5741989.eboZExnV48@descartes> ("=?UTF-8?Q?R=C3=BCdiger?= Sonderfeld"'s message of "Wed, 03 Dec 2014 20:39:44 +0100") User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.4.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:96830 Archived-At: R=FCdiger Sonderfeld writes: > As discussed in Bug#16507, I've added a systemd service file to deal with= =20 > emacs --daemon. This however requires some installation changes. That's= why=20 > I submit this patch for review before pushing it. > > A new configuration flag `--with-systemduserunitdir' is added to set the= =20 > installation directory for the user unit. If it is unset an attempt is m= ade=20 > to locate the default directory by using pkg-config. > > (I guess this should also get an entry in etc/NEWS.) > > * configure.ac (with_systemduserunitdir): New option. > * Makefile.in (systemdunitdir,SYSTEMD_UNITS): New variables. > (install-etc): Install systemd unit file. > (uninstall): Uninstall systemd unit file. > * etc/emacs.service.in: New file. > --- > ChangeLog | 8 ++++++++ > Makefile.in | 17 +++++++++++++++++ > configure.ac | 19 +++++++++++++++++++ > etc/ChangeLog | 5 +++++ > etc/emacs.service.in | 14 ++++++++++++++ > 5 files changed, 63 insertions(+) > create mode 100644 etc/emacs.service.in > > diff --git a/ChangeLog b/ChangeLog > index cd7698c..05ad878 100644 > --- a/ChangeLog > +++ b/ChangeLog > @@ -1,3 +1,11 @@ > +2014-12-03 R=FCdiger Sonderfeld > + > + Add a systemd service file for dealing with emacs --daemon. > + * configure.ac (with_systemduserunitdir): New option. > + * Makefile.in (systemdunitdir,SYSTEMD_UNITS): New variables. > + (install-etc): Install systemd unit file. > + (uninstall): Uninstall systemd unit file. > + > 2014-12-01 Lars Magne Ingebrigtsen >=20=20 > * .gitignore: Ignore loaddefs directly under lisp, and in > diff --git a/Makefile.in b/Makefile.in > index ccb70a4..b1e6be5 100644 > --- a/Makefile.in > +++ b/Makefile.in > @@ -241,6 +241,9 @@ etcdocdir=3D@etcdocdir@ > # Where to install Emacs game score files. > gamedir=3D@gamedir@ >=20=20 > +# Where to install systemd unit files. > +systemdunitdir=3D@systemdunitdir@ > + > # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Utility P= rograms for the Build =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D >=20=20 > # Allow the user to specify the install program. > @@ -286,6 +289,9 @@ SUBDIR_MAKEFILES =3D `echo $(SUBDIR_MAKEFILES_IN:.in= =3D) | sed=20 > 's|$(srcdir)/||g'` > COPYDIR =3D ${srcdir}/etc ${srcdir}/lisp > COPYDESTS =3D "$(DESTDIR)${etcdir}" "$(DESTDIR)${lispdir}" >=20=20 > +# systemd unit > +SYSTEMD_UNITS =3D @SYSTEMD_UNITS@ > + > all: ${SUBDIR} info >=20=20 > .PHONY: all ${SUBDIR} blessmail epaths-force epaths-force-w32 etc-emacsv= er > @@ -716,6 +722,16 @@ install-etc: > || exit 1; \ > done ; \ > done > + if test "x$(SYSTEMD_UNITS)" =3D "xemacs.service" ; then \ > + tmp=3Detc/emacs.service; rm -f $${tmp}; \ > + sed \ > + -e "s;@emacs_prog@;${bindir}/${EMACSFULL};" \ > + -e "s;@emacsclient_prog@;${bindir}/emacsclient${EXEEXT};" \ > + "$(srcdir)/etc/emacs.service.in" > $${tmp}; \ > + umask 022; $(MKDIR_P) "$(DESTDIR)$(systemdunitdir)"; \ > + $(INSTALL_DATA) $${tmp} "$(DESTDIR)$(systemdunitdir)/emacs.service"; \ > + rm -f $${tmp}; \ > + fi >=20=20 > ### Build Emacs and install it, stripping binaries while installing them. > install-strip: > @@ -771,6 +787,7 @@ uninstall: uninstall-$(NTDIR) uninstall-doc > file=3D"$(DESTDIR)${gamedir}/$${file}"; \ > [ -s "$${file}" ] || rm -f "$$file"; \ > done > + -rm -f "$(DESTDIR)$(systemdunitdir)/emacs.service" >=20=20 > ### Windows-specific uninstall target for removing programs produced > ### in nt/, and its Posix do-nothing shadow. > diff --git a/configure.ac b/configure.ac > index 010abc8..e737f1b 100644 > --- a/configure.ac > +++ b/configure.ac > @@ -374,6 +374,10 @@ otherwise for the first of `gfile' or `inotify' that= is=20 > usable.]) > ], > [with_file_notification=3D$with_features]) >=20=20 > +AC_ARG_WITH([systemduserunitdir], > + AS_HELP_STRING([--with-systemduserunitdir=3DDIR], [Directory for system= d user=20 > service files]), > + [], [with_systemduserunitdir=3Ddefault]) > + > ## For the times when you want to build Emacs but don't have > ## a suitable makeinfo, and can live without the manuals. > dnl http://lists.gnu.org/archive/html/emacs-devel/2008-04/msg01844.html@= @ -2678,6 +2682,21 @@ AC_SUBST(NOTIFY_OBJ) > AC_SUBST(GFILENOTIFY_CFLAGS) > AC_SUBST(GFILENOTIFY_LIBS) >=20=20 > +if test "x$with_systemduserunitdir" !=3D xno; then > + if test "x$with_systemduserunitdir" =3D xdefault; then > + with_systemduserunitdir=3D`"$PKG_CONFIG" --variable=3Dsystemduseruni= tdir=20 > systemd` > + fi > + AC_SUBST([systemdunitdir], [$with_systemduserunitdir]) > +fi > + > +if test -n "$with_systemduserunitdir" -a "x$with_systemduserunitdir" != =3D xno ;=20 > then > + SYSTEMD_UNITS=3D"emacs.service" > +else > + SYSTEMD_UNITS=3D"" > +fi > + > +AC_SUBST(SYSTEMD_UNITS) > + > dnl Do not put whitespace before the #include statements below. > dnl Older compilers (eg sunos4 cc) choke on it. > HAVE_XAW3D=3Dno > diff --git a/etc/ChangeLog b/etc/ChangeLog > index 4f672df..02c0895 100644 > --- a/etc/ChangeLog > +++ b/etc/ChangeLog > @@ -1,3 +1,8 @@ > +2014-12-03 R=FCdiger Sonderfeld > + > + Add a systemd service file for dealing with emacs --daemon. > + * emacs.service.in: New file. > + > 2014-12-02 Eli Zaretskii >=20=20 > * NEWS: Mention 'bidi-find-overridden-directionality'. > diff --git a/etc/emacs.service.in b/etc/emacs.service.in > new file mode 100644 > index 0000000..0e59bc2 > --- /dev/null > +++ b/etc/emacs.service.in > @@ -0,0 +1,14 @@ > +# -*- conf-mode -*- > +# Copyright (C) 2014 Free Software Foundation, Inc. > +[Unit] > +Description=3DEmacs: the extensible, customizable text editor - and more. > +Documentation=3Dinfo:Emacs man:emacs(1) https://gnu.org/software/emacs/+ > +[Service] > +Type=3Dforking > +ExecStart=3D@emacs_prog@ --daemon > +ExecStop=3D@emacsclient_prog@ --eval "(kill-emacs)" > +Restart=3Don-failure > + > +[Install] > +WantedBy=3Ddefault.target I have a unit file that enables ssh-agent, which is otherwise a problem. I'm not sure if its generally usable. [Unit] Description=3DEmacs: the extensible, self-documenting text editor [Service] Type=3Dforking ExecStart=3D/usr/bin/ssh-agent /usr/local/bin/emacs --daemon ExecStop=3D/usr/local/bin/emacs --eval "(progn (setq kill-emacs-hook 'nil) = (kill-emacs))" Restart=3Dalways User=3D%i WorkingDirectory=3D%h [Install] WantedBy=3Dmulti-user.target The corresponding elisp looks like (warning, lame hard-coding): (defun ssh-agent-init () (interactive) (save-excursion (if (get-buffer "ssh-agent-process") (kill-buffer "ssh-agent-process" )) (with-current-buffer (get-buffer-create "ssh-agent-process") (call-process "ssh-agent" nil t t "-c" "-a" "/home/joakim/.ssh-agent= -sock") (goto-char (point-min)) (message "buf: %s cont: %s"(current-buffer) (buffer-string)) (search-forward-regexp ".* .* \\(.*\\);") (message "1: %s" (match-string 0)(match-string 1)) (setenv "SSH_AUTH_SOCK" (match-string 1)) (setq ssh-auth-sock (getenv "SSH_AUTH_SOCK" )) (message "%s" (getenv "SSH_AUTH_SOCK" ))) ) ) (setenv "SSH_AUTH_SOCK" "/home/joakim/.ssh-agent-sock") ;;from the internetz ;; - it hangs, but works anyway ;; - it should also run ssh-agent-init intelligently (defun ssh-add-process-filter (process string) (save-match-data (if (string-match ":\\s *\\'" string) (process-send-string process (concat (read-passwd string) "\n")) (message "%s" string)))) (defun ssh-add () "Run ssh-add to add a key to the running SSH agent. Let Emacs prompt for the passphrase." (interactive) (let ((process-connection-type t) process) (unwind-protect (progn (setq process (start-process "ssh-add" nil "ssh-add" )) (set-process-filter process 'ssh-add-process-filter) (while (accept-process-output process))) (if (eq (process-status process) 'run) (kill-process process))))) --=20 Joakim Verona