unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#16507: 24.3; systemd unit for a GNU Emacs daemon
@ 2014-01-20 12:34 Philipp Moeller
  2014-01-20 16:58 ` Andreas Schwab
                   ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Philipp Moeller @ 2014-01-20 12:34 UTC (permalink / raw)
  To: 16507

systemd provides an easy way to set-up a per-user Emacs daemon and there
are several unit files floating around the web. One that works is:

  /etc/systemd/system/emacs@.service
  ----------------------------------
  [Unit]
  Description=GNU Emacs: the extensible, self-documenting text editor
  
  [Service]
  Type=forking
  ExecStart=/usr/bin/emacs --daemon
  ExecStop=/usr/bin/emacsclient --eval "(progn (setq kill-emacs-hook 'nil) (kill-emacs))"
  Restart=always
  User=%i
  
  [Install]
  WantedBy=multi-user.target

It would be helpful to include this with the default GNU Emacs, so
users don't need to maintain their own files.

The above file would need some configuration through configure to set
the install path correctly and there should be an option to enable or
disable installing it via --with-systemd.





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: 24.3; systemd unit for a GNU Emacs daemon
  2014-01-20 12:34 bug#16507: 24.3; systemd unit for a GNU Emacs daemon Philipp Moeller
@ 2014-01-20 16:58 ` Andreas Schwab
  2014-01-20 17:05   ` Glenn Morris
  2014-01-20 18:53 ` Ted Zlatanov
  2014-12-03 19:39 ` bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon Rüdiger Sonderfeld
  2 siblings, 1 reply; 22+ messages in thread
From: Andreas Schwab @ 2014-01-20 16:58 UTC (permalink / raw)
  To: Philipp Moeller; +Cc: 16507

Philipp Moeller <bootsarehax@gmail.com> writes:

>   ExecStop=/usr/bin/emacsclient --eval "(progn (setq kill-emacs-hook 'nil) (kill-emacs))"

'nil is the same as nil.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: 24.3; systemd unit for a GNU Emacs daemon
  2014-01-20 16:58 ` Andreas Schwab
@ 2014-01-20 17:05   ` Glenn Morris
  0 siblings, 0 replies; 22+ messages in thread
From: Glenn Morris @ 2014-01-20 17:05 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Philipp Moeller, 16507

Andreas Schwab wrote:

>>   ExecStop=/usr/bin/emacsclient --eval "(progn (setq kill-emacs-hook 'nil) (kill-emacs))"
>
> 'nil is the same as nil.

Also: why set kill-emacs-hook to nil at all?

If it is to avoid prompting: "functions placed on this hook should not
expect to be able to interact with the user.  To ask for confirmation,
see `kill-emacs-query-functions' instead."





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: 24.3; systemd unit for a GNU Emacs daemon
  2014-01-20 12:34 bug#16507: 24.3; systemd unit for a GNU Emacs daemon Philipp Moeller
  2014-01-20 16:58 ` Andreas Schwab
@ 2014-01-20 18:53 ` Ted Zlatanov
  2014-01-20 20:25   ` Stefan Monnier
  2014-12-03 19:39 ` bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon Rüdiger Sonderfeld
  2 siblings, 1 reply; 22+ messages in thread
From: Ted Zlatanov @ 2014-01-20 18:53 UTC (permalink / raw)
  To: Philipp Moeller; +Cc: 16507

On Mon, 20 Jan 2014 13:34:51 +0100 Philipp Moeller <bootsarehax@gmail.com> wrote: 

PM> systemd provides an easy way to set-up a per-user Emacs daemon and there
PM> are several unit files floating around the web. One that works is:
...
PM> It would be helpful to include this with the default GNU Emacs, so
PM> users don't need to maintain their own files.

PM> The above file would need some configuration through configure to set
PM> the install path correctly and there should be an option to enable or
PM> disable installing it via --with-systemd.

I would like that as part of the package, even if 95% of users never
need it.  The 5% that do will appreciate the convenience.

Ted





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: 24.3; systemd unit for a GNU Emacs daemon
  2014-01-20 18:53 ` Ted Zlatanov
@ 2014-01-20 20:25   ` Stefan Monnier
  2014-01-20 21:03     ` Nathan Trapuzzano
  2014-01-20 22:36     ` Mark Oteiza
  0 siblings, 2 replies; 22+ messages in thread
From: Stefan Monnier @ 2014-01-20 20:25 UTC (permalink / raw)
  To: Philipp Moeller; +Cc: 16507

> I would like that as part of the package, even if 95% of users never
> need it.  The 5% that do will appreciate the convenience.

I don't see any problem with adding such a file.
I guess it would go in `etc'?


        Stefan





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: 24.3; systemd unit for a GNU Emacs daemon
  2014-01-20 20:25   ` Stefan Monnier
@ 2014-01-20 21:03     ` Nathan Trapuzzano
  2014-01-20 22:36     ` Mark Oteiza
  1 sibling, 0 replies; 22+ messages in thread
From: Nathan Trapuzzano @ 2014-01-20 21:03 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Philipp Moeller, 16507

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> I don't see any problem with adding such a file.  I guess it would go
> in `etc'?

I think the suggestion was that it could be a build feature like
--with-systemd-unit-file or something like that.  That would indeed be
nice.





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: 24.3; systemd unit for a GNU Emacs daemon
  2014-01-20 20:25   ` Stefan Monnier
  2014-01-20 21:03     ` Nathan Trapuzzano
@ 2014-01-20 22:36     ` Mark Oteiza
  1 sibling, 0 replies; 22+ messages in thread
From: Mark Oteiza @ 2014-01-20 22:36 UTC (permalink / raw)
  To: 16507

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> I would like that as part of the package, even if 95% of users never
>> need it.  The 5% that do will appreciate the convenience.
>
> I don't see any problem with adding such a file.
> I guess it would go in `etc'?
>
>
>         Stefan

Units of installed packages go in lib, per systemd.unit(5)

The addition of a user unit should also be considered.  Here is an example:

[Unit]
Description=GNU Emacs daemon
Documentation=man:emacs(1) info:Emacs

[Service]
Type=forking
ExecStart=/usr/bin/emacs --daemon
ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)"

[Install]
WantedBy=default.target





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon.
  2014-01-20 12:34 bug#16507: 24.3; systemd unit for a GNU Emacs daemon Philipp Moeller
  2014-01-20 16:58 ` Andreas Schwab
  2014-01-20 18:53 ` Ted Zlatanov
@ 2014-12-03 19:39 ` Rüdiger Sonderfeld
  2014-12-03 21:08   ` Romain Francoise
                     ` (4 more replies)
  2 siblings, 5 replies; 22+ messages in thread
From: Rüdiger Sonderfeld @ 2014-12-03 19:39 UTC (permalink / raw)
  To: emacs-devel; +Cc: 16507

As discussed in Bug#16507, I've added a systemd service file to deal with 
emacs --daemon.  This however requires some installation changes.  That's why 
I submit this patch for review before pushing it.

A new configuration flag `--with-systemduserunitdir' is added to set the 
installation directory for the user unit.  If it is unset an attempt is made 
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üdiger Sonderfeld  <ruediger@c-plusplus.de>
+
+	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  <larsi@gnus.org>
 
 	* .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=@etcdocdir@
 # Where to install Emacs game score files.
 gamedir=@gamedir@
 
+# Where to install systemd unit files.
+systemdunitdir=@systemdunitdir@
+
 # ==================== Utility Programs for the Build ====================
 
 # Allow the user to specify the install program.
@@ -286,6 +289,9 @@ SUBDIR_MAKEFILES = `echo $(SUBDIR_MAKEFILES_IN:.in=) | sed 
's|$(srcdir)/||g'`
 COPYDIR = ${srcdir}/etc ${srcdir}/lisp
 COPYDESTS = "$(DESTDIR)${etcdir}" "$(DESTDIR)${lispdir}"
 
+# systemd unit
+SYSTEMD_UNITS = @SYSTEMD_UNITS@
+
 all: ${SUBDIR} info
 
 .PHONY: all ${SUBDIR} blessmail epaths-force epaths-force-w32 etc-emacsver
@@ -716,6 +722,16 @@ install-etc:
 	    || exit 1; \
 	  done ; \
 	done
+	if test "x$(SYSTEMD_UNITS)" = "xemacs.service" ; then \
+	  tmp=etc/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
 
 ### Build Emacs and install it, stripping binaries while installing them.
 install-strip:
@@ -771,6 +787,7 @@ uninstall: uninstall-$(NTDIR) uninstall-doc
 	  file="$(DESTDIR)${gamedir}/$${file}"; \
 	  [ -s "$${file}" ] || rm -f "$$file"; \
 	done
+	-rm -f "$(DESTDIR)$(systemdunitdir)/emacs.service"
 
 ### 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 
usable.])
  ],
  [with_file_notification=$with_features])
 
+AC_ARG_WITH([systemduserunitdir],
+ AS_HELP_STRING([--with-systemduserunitdir=DIR], [Directory for systemd user 
service files]),
+ [], [with_systemduserunitdir=default])
+
 ## 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)
 
+if test "x$with_systemduserunitdir" != xno; then
+  if test "x$with_systemduserunitdir" = xdefault; then
+    with_systemduserunitdir=`"$PKG_CONFIG" --variable=systemduserunitdir 
systemd`
+  fi
+  AC_SUBST([systemdunitdir], [$with_systemduserunitdir])
+fi
+
+if test -n "$with_systemduserunitdir" -a "x$with_systemduserunitdir" != xno ; 
then
+  SYSTEMD_UNITS="emacs.service"
+else
+  SYSTEMD_UNITS=""
+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=no
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üdiger Sonderfeld  <ruediger@c-plusplus.de>
+
+	Add a systemd service file for dealing with emacs --daemon.
+	* emacs.service.in: New file.
+
 2014-12-02  Eli Zaretskii  <eliz@gnu.org>
 
 	* 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=Emacs: the extensible, customizable text editor - and more.
+Documentation=info:Emacs man:emacs(1) https://gnu.org/software/emacs/
+
+[Service]
+Type=forking
+ExecStart=@emacs_prog@ --daemon
+ExecStop=@emacsclient_prog@ --eval "(kill-emacs)"
+Restart=on-failure
+
+[Install]
+WantedBy=default.target
-- 
2.1.3






^ permalink raw reply related	[flat|nested] 22+ messages in thread

* bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon.
  2014-12-03 19:39 ` bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon Rüdiger Sonderfeld
@ 2014-12-03 21:08   ` Romain Francoise
  2014-12-03 21:16   ` joakim
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 22+ messages in thread
From: Romain Francoise @ 2014-12-03 21:08 UTC (permalink / raw)
  To: Rüdiger Sonderfeld; +Cc: 16507, emacs-devel

Hi,

On Wed, Dec 03, 2014 at 08:39:44PM +0100, Rüdiger Sonderfeld wrote:
> As discussed in Bug#16507, I've added a systemd service file to deal
> with emacs --daemon. This however requires some installation changes.
> That's why I submit this patch for review before pushing it.

Is this something that distributions would be expected to enable?
Because I use both systemd and Emacs, yet I absolutely don't want to
have an Emacs daemon started by default in my user instance.

Also, by default user instances are killed when the last session is
closed, which would therefore kill the emacs process and kinda defeat
the point of having a persistent daemon.





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon.
  2014-12-03 19:39 ` bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon Rüdiger Sonderfeld
  2014-12-03 21:08   ` Romain Francoise
@ 2014-12-03 21:16   ` joakim
       [not found]   ` <87iohstp9m.fsf@kima.orebokech.com>
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 22+ messages in thread
From: joakim @ 2014-12-03 21:16 UTC (permalink / raw)
  To: Rüdiger Sonderfeld; +Cc: 16507, emacs-devel

Rüdiger Sonderfeld <ruediger@c-plusplus.net> writes:

> As discussed in Bug#16507, I've added a systemd service file to deal with 
> emacs --daemon.  This however requires some installation changes.  That's why 
> I submit this patch for review before pushing it.
>
> A new configuration flag `--with-systemduserunitdir' is added to set the 
> installation directory for the user unit.  If it is unset an attempt is made 
> 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üdiger Sonderfeld  <ruediger@c-plusplus.de>
> +
> +	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  <larsi@gnus.org>
>  
>  	* .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=@etcdocdir@
>  # Where to install Emacs game score files.
>  gamedir=@gamedir@
>  
> +# Where to install systemd unit files.
> +systemdunitdir=@systemdunitdir@
> +
>  # ==================== Utility Programs for the Build ====================
>  
>  # Allow the user to specify the install program.
> @@ -286,6 +289,9 @@ SUBDIR_MAKEFILES = `echo $(SUBDIR_MAKEFILES_IN:.in=) | sed 
> 's|$(srcdir)/||g'`
>  COPYDIR = ${srcdir}/etc ${srcdir}/lisp
>  COPYDESTS = "$(DESTDIR)${etcdir}" "$(DESTDIR)${lispdir}"
>  
> +# systemd unit
> +SYSTEMD_UNITS = @SYSTEMD_UNITS@
> +
>  all: ${SUBDIR} info
>  
>  .PHONY: all ${SUBDIR} blessmail epaths-force epaths-force-w32 etc-emacsver
> @@ -716,6 +722,16 @@ install-etc:
>  	    || exit 1; \
>  	  done ; \
>  	done
> +	if test "x$(SYSTEMD_UNITS)" = "xemacs.service" ; then \
> +	  tmp=etc/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
>  
>  ### Build Emacs and install it, stripping binaries while installing them.
>  install-strip:
> @@ -771,6 +787,7 @@ uninstall: uninstall-$(NTDIR) uninstall-doc
>  	  file="$(DESTDIR)${gamedir}/$${file}"; \
>  	  [ -s "$${file}" ] || rm -f "$$file"; \
>  	done
> +	-rm -f "$(DESTDIR)$(systemdunitdir)/emacs.service"
>  
>  ### 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 
> usable.])
>   ],
>   [with_file_notification=$with_features])
>  
> +AC_ARG_WITH([systemduserunitdir],
> + AS_HELP_STRING([--with-systemduserunitdir=DIR], [Directory for systemd user 
> service files]),
> + [], [with_systemduserunitdir=default])
> +
>  ## 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)
>  
> +if test "x$with_systemduserunitdir" != xno; then
> +  if test "x$with_systemduserunitdir" = xdefault; then
> +    with_systemduserunitdir=`"$PKG_CONFIG" --variable=systemduserunitdir 
> systemd`
> +  fi
> +  AC_SUBST([systemdunitdir], [$with_systemduserunitdir])
> +fi
> +
> +if test -n "$with_systemduserunitdir" -a "x$with_systemduserunitdir" != xno ; 
> then
> +  SYSTEMD_UNITS="emacs.service"
> +else
> +  SYSTEMD_UNITS=""
> +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=no
> 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üdiger Sonderfeld  <ruediger@c-plusplus.de>
> +
> +	Add a systemd service file for dealing with emacs --daemon.
> +	* emacs.service.in: New file.
> +
>  2014-12-02  Eli Zaretskii  <eliz@gnu.org>
>  
>  	* 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=Emacs: the extensible, customizable text editor - and more.
> +Documentation=info:Emacs man:emacs(1) https://gnu.org/software/emacs/+
> +[Service]
> +Type=forking
> +ExecStart=@emacs_prog@ --daemon
> +ExecStop=@emacsclient_prog@ --eval "(kill-emacs)"
> +Restart=on-failure
> +
> +[Install]
> +WantedBy=default.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=Emacs: the extensible, self-documenting text editor

[Service]
Type=forking
ExecStart=/usr/bin/ssh-agent /usr/local/bin/emacs --daemon
ExecStop=/usr/local/bin/emacs --eval "(progn (setq kill-emacs-hook 'nil) (kill-emacs))"
Restart=always
User=%i
WorkingDirectory=%h

[Install]
WantedBy=multi-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)))))


-- 
Joakim Verona





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon.
       [not found]   ` <87iohstp9m.fsf@kima.orebokech.com>
@ 2014-12-03 21:44     ` Rüdiger Sonderfeld
  2014-12-03 22:08     ` Ulrich Mueller
       [not found]     ` <21631.35293.852427.367195@a1i15.kph.uni-mainz.de>
  2 siblings, 0 replies; 22+ messages in thread
From: Rüdiger Sonderfeld @ 2014-12-03 21:44 UTC (permalink / raw)
  To: emacs-devel; +Cc: 16507, Romain Francoise, Rüdiger Sonderfeld

On Wednesday 03 December 2014 22:08:37 Romain Francoise wrote:
> Is this something that distributions would be expected to enable?
> Because I use both systemd and Emacs, yet I absolutely don't want to
> have an Emacs daemon started by default in my user instance.

It's something the user would be expected to enable.  This should only provide 
the service file and the user can then enable it, using

    systemctl enable --user emacs.service

(or disable it by using disable).

> Also, by default user instances are killed when the last session is
> closed, which would therefore kill the emacs process and kinda defeat
> the point of having a persistent daemon.

Users should be able to prevent this, by using `loginctl enable-linger'.

Regards,
Rüdiger






^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon.
       [not found]   ` <87iohstp9m.fsf@kima.orebokech.com>
  2014-12-03 21:44     ` Rüdiger Sonderfeld
@ 2014-12-03 22:08     ` Ulrich Mueller
       [not found]     ` <21631.35293.852427.367195@a1i15.kph.uni-mainz.de>
  2 siblings, 0 replies; 22+ messages in thread
From: Ulrich Mueller @ 2014-12-03 22:08 UTC (permalink / raw)
  To: Romain Francoise; +Cc: 16507, Rüdiger Sonderfeld, emacs-devel

>>>>> On Wed, 03 Dec 2014, Romain Francoise wrote:

> Is this something that distributions would be expected to enable?

As it is proposed, it won't work for Gentoo. We support installation
of several Emacs versions in parallel, so a systemd unit file
installed under a fixed path name would lead to file collisions
between different versions.

Which means that we shall disable installation of the file in Gentoo.
(Besides, systemd isn't our default init system ...)





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon.
       [not found]     ` <21631.35293.852427.367195@a1i15.kph.uni-mainz.de>
@ 2014-12-04  0:18       ` Rüdiger Sonderfeld
       [not found]       ` <5628178.gi3dgk9OHo@descartes>
  1 sibling, 0 replies; 22+ messages in thread
From: Rüdiger Sonderfeld @ 2014-12-04  0:18 UTC (permalink / raw)
  To: emacs-devel; +Cc: Ulrich Mueller, Romain Francoise, 16507

On Wednesday 03 December 2014 23:08:29 Ulrich Mueller wrote:
> >>>>> On Wed, 03 Dec 2014, Romain Francoise wrote:
> > Is this something that distributions would be expected to enable?
> 
> As it is proposed, it won't work for Gentoo. We support installation
> of several Emacs versions in parallel, so a systemd unit file
> installed under a fixed path name would lead to file collisions
> between different versions.
> 
> Which means that we shall disable installation of the file in Gentoo.
> (Besides, systemd isn't our default init system ...)

Multiple versions are indeed an issue.  I don't know if the systemd folks have 
a suggestion for that case.  But as far as I understand the recommendation is 
indeed to install unit files to the directory given by pkg-config.

The installation directory can of course be changed and you could simply point 
it elsewhere and then have the user copy the unit file she wants.

Regards,
Rüdiger






^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon.
       [not found]       ` <5628178.gi3dgk9OHo@descartes>
@ 2014-12-04  2:57         ` Drew Adams
  2014-12-04  6:26         ` Ulrich Mueller
  1 sibling, 0 replies; 22+ messages in thread
From: Drew Adams @ 2014-12-04  2:57 UTC (permalink / raw)
  To: Rüdiger Sonderfeld, emacs-devel
  Cc: Ulrich Mueller, Romain Francoise, 16507

Please drop one or the other from the recipients list:
emacs-devel or debbugs.





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon.
  2014-12-03 19:39 ` bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon Rüdiger Sonderfeld
                     ` (2 preceding siblings ...)
       [not found]   ` <87iohstp9m.fsf@kima.orebokech.com>
@ 2014-12-04  3:00   ` Glenn Morris
       [not found]   ` <pmvblsrueb.fsf@fencepost.gnu.org>
  4 siblings, 0 replies; 22+ messages in thread
From: Glenn Morris @ 2014-12-04  3:00 UTC (permalink / raw)
  To: Rüdiger Sonderfeld; +Cc: 16507, emacs-devel


Thanks, looks nice.
(Don't see why it needed to be posted to two mailing lists though.)

Should the name of the service file not respect program-transform though?
Ie, if I am installing the Emacs binary as "emacs24", should the service
file not be installed as "emacs24.service"?





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon.
       [not found]       ` <5628178.gi3dgk9OHo@descartes>
  2014-12-04  2:57         ` Drew Adams
@ 2014-12-04  6:26         ` Ulrich Mueller
  1 sibling, 0 replies; 22+ messages in thread
From: Ulrich Mueller @ 2014-12-04  6:26 UTC (permalink / raw)
  To: Rüdiger Sonderfeld; +Cc: 16507, Romain Francoise, emacs-devel

>>>>> On Thu, 04 Dec 2014, Rüdiger Sonderfeld wrote:

> On Wednesday 03 December 2014 23:08:29 Ulrich Mueller wrote:
>> Which means that we shall disable installation of the file in
>> Gentoo. (Besides, systemd isn't our default init system ...)

> Multiple versions are indeed an issue. I don't know if the systemd
> folks have a suggestion for that case. But as far as I understand
> the recommendation is indeed to install unit files to the directory
> given by pkg-config.

> The installation directory can of course be changed and you could
> simply point it elsewhere and then have the user copy the unit file
> she wants.

IIUC, a copy of the file is installed with the data-directory (etc/)
anyway? So the file will be available to the user, even if not
installed in the pkgconfig location.

Alternatively, if there is users' demand for it, we (Gentoo) could
add the unit to another package (like app-emacs/emacs-common-gentoo
which contains the desktop files, or app-emacs/emacs-daemon). We try
to keep the number of files installed such at a minimum, though, and
follow upstream's install locations whereever possible.





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon.
       [not found]   ` <pmvblsrueb.fsf@fencepost.gnu.org>
@ 2014-12-05 17:26     ` Rüdiger Sonderfeld
  2014-12-08 17:03       ` Glenn Morris
  0 siblings, 1 reply; 22+ messages in thread
From: Rüdiger Sonderfeld @ 2014-12-05 17:26 UTC (permalink / raw)
  To: 16507

On Wednesday 03 December 2014 22:00:44 Glenn Morris wrote:
> Thanks, looks nice.
> (Don't see why it needed to be posted to two mailing lists though.)

Sorry about that.

> Should the name of the service file not respect program-transform though?
> Ie, if I am installing the Emacs binary as "emacs24", should the service
> file not be installed as "emacs24.service"?

That makes sense and would solve the problem of having several Emacs versions 
installed.

I'm a bit afraid that using the directory given by systemd might be confusing 
because it won't respect the prefix set by the user.  E.g., Emacs being 
installed to /usr/local but the service file going to /usr/lib/systemd/user.  
However, I think this is just the way systemd expects things to be and it 
would be up to the systemd developers to change this.

Regards,
Rüdiger






^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon.
  2014-12-05 17:26     ` Rüdiger Sonderfeld
@ 2014-12-08 17:03       ` Glenn Morris
  2014-12-08 18:51         ` Stefan Monnier
  0 siblings, 1 reply; 22+ messages in thread
From: Glenn Morris @ 2014-12-08 17:03 UTC (permalink / raw)
  To: Rüdiger Sonderfeld; +Cc: 16507

Rüdiger Sonderfeld wrote:

> I'm a bit afraid that using the directory given by systemd might be
> confusing because it won't respect the prefix set by the user. E.g.,
> Emacs being installed to /usr/local but the service file going to
> /usr/lib/systemd/user.

I agree that that is an issue. Personally I think you should respect
the user's prefix. For example, I often install software as a non-root
user into my local software space, and it's always annoying when
things try to install files into /usr (which fails due to lack of
permission).

It's going to take a bit of know-how to actually enable the service,
and I think people doing that will be able to cope with copying
the file to the appropriate location if they need to.





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon.
  2014-12-08 17:03       ` Glenn Morris
@ 2014-12-08 18:51         ` Stefan Monnier
  2014-12-08 20:41           ` Eli Zaretskii
  0 siblings, 1 reply; 22+ messages in thread
From: Stefan Monnier @ 2014-12-08 18:51 UTC (permalink / raw)
  To: Glenn Morris; +Cc: Rüdiger Sonderfeld, 16507

>> Emacs being installed to /usr/local but the service file going to
>> /usr/lib/systemd/user.
> I agree that that is an issue. Personally I think you should respect
> the user's prefix.

Indeed, if the prefix is /usr/local we should not install anything
outside /usr/local.


        Stefan





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon.
  2014-12-08 18:51         ` Stefan Monnier
@ 2014-12-08 20:41           ` Eli Zaretskii
  2014-12-09  2:47             ` Stefan Monnier
  0 siblings, 1 reply; 22+ messages in thread
From: Eli Zaretskii @ 2014-12-08 20:41 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: ruediger, 16507

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Mon, 08 Dec 2014 13:51:21 -0500
> Cc: Rüdiger Sonderfeld <ruediger@c-plusplus.de>,
> 	16507@debbugs.gnu.org
> 
> >> Emacs being installed to /usr/local but the service file going to
> >> /usr/lib/systemd/user.
> > I agree that that is an issue. Personally I think you should respect
> > the user's prefix.
> 
> Indeed, if the prefix is /usr/local we should not install anything
> outside /usr/local.

AFAIK, there are packages out there which install stuff in /etc, so
I'm not sure this rule is valid.





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon.
  2014-12-08 20:41           ` Eli Zaretskii
@ 2014-12-09  2:47             ` Stefan Monnier
  2016-11-13 23:52               ` bug#16507: 24.3; systemd unit for a GNU Emacs daemon Glenn Morris
  0 siblings, 1 reply; 22+ messages in thread
From: Stefan Monnier @ 2014-12-09  2:47 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: ruediger, 16507

>> >> Emacs being installed to /usr/local but the service file going to
>> >> /usr/lib/systemd/user.
>> > I agree that that is an issue. Personally I think you should respect
>> > the user's prefix.
>> Indeed, if the prefix is /usr/local we should not install anything
>> outside /usr/local.
> AFAIK, there are packages out there which install stuff in /etc, so
> I'm not sure this rule is valid.

I'm talking about a general rule, which I think Emacs should follow.
Some other packages may have good reasons to break this rule, but
I can't think of any reason why Emacs should.


        Stefan





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#16507: 24.3; systemd unit for a GNU Emacs daemon
  2014-12-09  2:47             ` Stefan Monnier
@ 2016-11-13 23:52               ` Glenn Morris
  0 siblings, 0 replies; 22+ messages in thread
From: Glenn Morris @ 2016-11-13 23:52 UTC (permalink / raw)
  To: 16507-done

Version: 26.1

An emacs.service file is now included (since 181bd84).
Sorry for the delay.





^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2016-11-13 23:52 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-20 12:34 bug#16507: 24.3; systemd unit for a GNU Emacs daemon Philipp Moeller
2014-01-20 16:58 ` Andreas Schwab
2014-01-20 17:05   ` Glenn Morris
2014-01-20 18:53 ` Ted Zlatanov
2014-01-20 20:25   ` Stefan Monnier
2014-01-20 21:03     ` Nathan Trapuzzano
2014-01-20 22:36     ` Mark Oteiza
2014-12-03 19:39 ` bug#16507: [RFC] Add a systemd service file for dealing with emacs --daemon Rüdiger Sonderfeld
2014-12-03 21:08   ` Romain Francoise
2014-12-03 21:16   ` joakim
     [not found]   ` <87iohstp9m.fsf@kima.orebokech.com>
2014-12-03 21:44     ` Rüdiger Sonderfeld
2014-12-03 22:08     ` Ulrich Mueller
     [not found]     ` <21631.35293.852427.367195@a1i15.kph.uni-mainz.de>
2014-12-04  0:18       ` Rüdiger Sonderfeld
     [not found]       ` <5628178.gi3dgk9OHo@descartes>
2014-12-04  2:57         ` Drew Adams
2014-12-04  6:26         ` Ulrich Mueller
2014-12-04  3:00   ` Glenn Morris
     [not found]   ` <pmvblsrueb.fsf@fencepost.gnu.org>
2014-12-05 17:26     ` Rüdiger Sonderfeld
2014-12-08 17:03       ` Glenn Morris
2014-12-08 18:51         ` Stefan Monnier
2014-12-08 20:41           ` Eli Zaretskii
2014-12-09  2:47             ` Stefan Monnier
2016-11-13 23:52               ` bug#16507: 24.3; systemd unit for a GNU Emacs daemon Glenn Morris

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).