summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Morris <rgm@gnu.org>2016-11-13 15:46:31 -0800
committerGlenn Morris <rgm@gnu.org>2016-11-13 15:46:31 -0800
commit181bd848eb9662759f076b31a32f6588e9eb58b4 (patch)
tree0ca9d3a192264fe960028b77b8af9a3d886a5b6e
parent9b3a853ab2430503bb1e5bae57fc35e2cd555e1a (diff)
downloademacs-181bd848eb9662759f076b31a32f6588e9eb58b4.tar.gz
Include a systemd user unit file. (Bug#16507)
* etc/emacs.service: New file. * doc/emacs/misc.texi (Emacs Server): Mention systemcl --user. * Makefile.in (libdir): New, set by configure. (systemdunitdir): New variable. (install-etc, uninstall): Handle the emacs.service file.
-rw-r--r--Makefile.in27
-rw-r--r--doc/emacs/misc.texi37
-rw-r--r--etc/NEWS6
-rw-r--r--etc/emacs.service17
4 files changed, 68 insertions, 19 deletions
diff --git a/Makefile.in b/Makefile.in
index 3c1f29b7e76..109583705fb 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -153,6 +153,9 @@ sharedstatedir=@sharedstatedir@
# a subdirectory of this.
libexecdir=@libexecdir@
+# Currently only used for the systemd service file.
+libdir=@libdir@
+
# Where to install Emacs's man pages.
# Note they contain cross-references that expect them to be in section 1.
mandir=@mandir@
@@ -196,6 +199,17 @@ desktopdir=$(datarootdir)/applications
# Where the etc/emacs.appdata.xml file is to be installed.
appdatadir=$(datarootdir)/appdata
+# Where the etc/emacs.service file is to be installed.
+# The system value (typically /usr/lib/systemd/user) can be
+# obtained with: pkg-config --variable=systemduserunitdir systemd
+# but that does not respect configure's prefix.
+# It is not clear where we should install this file when
+# prefix != /usr (or /usr/local?) (eg for non-root installs).
+# Other options include ~/.config/systemd/user/,
+# $XDG_RUNTIME_DIR/systemd/user/
+# It seems the user may end up having to make a manual link...
+systemdunitdir=$(libdir)/systemd/user
+
# Where the etc/images/icons/hicolor directory is to be installed.
icondir=$(datarootdir)/icons
@@ -714,6 +728,18 @@ install-etc:
${srcdir}/etc/emacs.appdata.xml > $${tmp}; \
${INSTALL_DATA} $${tmp} "$(DESTDIR)${appdatadir}/${EMACS_NAME}.appdata.xml"; \
rm -f $${tmp}
+ umask 022; $(MKDIR_P) "$(DESTDIR)$(systemdunitdir)"
+ tmp=etc/emacs.tmpservice; rm -f $${tmp}; \
+ emacs_name=`echo emacs | sed '$(TRANSFORM)'`; \
+ exe_name=$${emacs_name}${EXEEXT}; \
+ client_name=`echo emacsclient | sed '$(TRANSFORM)'`${EXEEXT}; \
+ sed -e '/^##/d' \
+ -e "/^Documentation/ s/emacs(1)/$${emacs_name}(1)/" \
+ -e "/^ExecStart/ s|emacs|$(DESTDIR)${bindir}/$${exe_name}|" \
+ -e "/^ExecStop/ s|emacsclient|$(DESTDIR)${bindir}/$${client_name}|" \
+ ${srcdir}/etc/emacs.service > $${tmp}; \
+ $(INSTALL_DATA) $${tmp} "$(DESTDIR)$(systemdunitdir)/${EMACS_NAME}.service"; \
+ rm -f $${tmp}
thisdir=`/bin/pwd`; \
cd ${iconsrcdir} || exit 1; umask 022 ; \
for dir in */*/apps */*/mimetypes; do \
@@ -779,6 +805,7 @@ uninstall: uninstall-$(NTDIR) uninstall-doc
fi)
-rm -f "$(DESTDIR)${desktopdir}/${EMACS_NAME}.desktop"
-rm -f "$(DESTDIR)${appdatadir}/${EMACS_NAME}.appdata.xml"
+ -rm -f "$(DESTDIR)$(systemdunitdir)/${EMACS_NAME}.service"
for file in snake-scores tetris-scores; do \
file="$(DESTDIR)${gamedir}/$${file}"; \
[ -s "$${file}" ] || rm -f "$$file"; \
diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi
index f38a797b36c..cb0a1160516 100644
--- a/doc/emacs/misc.texi
+++ b/doc/emacs/misc.texi
@@ -1570,7 +1570,7 @@ process.
You can solve this problem by setting up Emacs as an @dfn{edit
server}, so that it ``listens'' for external edit requests and acts
-accordingly. There are two ways to start an Emacs server:
+accordingly. There are various ways to start an Emacs server:
@itemize
@findex server-start
@@ -1589,32 +1589,29 @@ calls @code{server-start} after initialization, and returns control to
the calling terminal instead of opening an initial frame; it then
waits in the background, listening for edit requests.
+@cindex systemd unit file
+@item
+If your operating system uses @command{systemd} to manage startup,
+you can automatically start Emacs in daemon mode when you login
+using the supplied @dfn{systemd unit file}. To activate this:
+@example
+systemctl --user enable emacs
+@end example
+(If your Emacs was installed into a non-standard location, you may
+need to copy the @file{emacs.service} file to a standard directory
+such as @file{~/.config/systemd/user/}.)
+
@cindex socket activation, systemd, Emacs
@item
An external process can invoke the Emacs server when a connection
event occurs upon a specified socket and pass the socket to the new
-Emacs server process. An instance of this is @command{systemd}'s
-socket functionality: the @command{systemd} service creates a socket and
+Emacs server process. An instance of this is the socket functionality
+of @command{systemd}: the @command{systemd} service creates a socket and
listens for connections on it; when @command{emacsclient} connects to
it for the first time, @command{systemd} can launch the Emacs server
and hand over the socket to it for servicing @command{emacsclient}
connections. A setup to use this functionality could be:
-@file{~/.config/systemd/user/emacs.service}:
-@example
-[Unit]
-Description=Emacs
-
-[Service]
-Type=forking
-ExecStart=/path/to/emacs --daemon
-ExecStop=/path/to/emacsclient --eval "(kill-emacs)"
-Restart=always
-
-[Install]
-WantedBy=default.target
-@end example
-
@file{~/.config/systemd/user/emacs.socket}:
@example
[Socket]
@@ -1624,12 +1621,14 @@ ListenStream=/path/to/.emacs.socket
WantedBy=sockets.target
@end example
+(The @file{emacs.service} file described above must also be installed.)
+
The @code{ListenStream} path will be the path that Emacs listens for
connections from @command{emacsclient}; this is a file of your choice.
@end itemize
@cindex @env{TEXEDIT} environment variable
- Either way, once an Emacs server is started, you can use a shell
+ Once an Emacs server is started, you can use a shell
command called @command{emacsclient} to connect to the Emacs process
and tell it to visit a file. You can then set the @env{EDITOR}
environment variable to @samp{emacsclient}, so that external programs
diff --git a/etc/NEWS b/etc/NEWS
index fe76af591b3..03c49907bf4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -44,6 +44,12 @@ hand the socket over to Emacs. Emacs uses this socket to service
emacsclient commands. This new functionality can be disabled with the
configure option '--disable-libsystemd'.
++++
+** A systemd user unit file is provided. Use it in the standard way:
+systemctl --user enable emacs
+(If your Emacs is installed in a non-standard location, you may
+need to copy the emacs.service file to eg ~/.config/systemd/user/)
+
** New configure option '--disable-build-details' attempts to build an
Emacs that is more likely to be reproducible; that is, if you build
and install Emacs twice, the second Emacs is a copy of the first.
diff --git a/etc/emacs.service b/etc/emacs.service
new file mode 100644
index 00000000000..92cdeb5cf49
--- /dev/null
+++ b/etc/emacs.service
@@ -0,0 +1,17 @@
+## If your Emacs is installed in a non-standard location, you may need
+## to copy this file to a standard directory, eg ~/.config/systemd/user/ .
+## If you install this file by hand, change the "Exec" lines below
+## to use absolute file names for the executables.
+[Unit]
+Description=Emacs text editor
+Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/
+
+[Service]
+Type=forking
+ExecStart=emacs --daemon
+ExecStop=emacsclient --eval "(kill-emacs)"
+Environment=SSH_AUTH_SOCK=%t/keyring/ssh
+Restart=on-failure
+
+[Install]
+WantedBy=default.target