Commit 181bd848 authored by Glenn Morris's avatar Glenn Morris

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.
parent 9b3a853a
......@@ -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"; \
......
......@@ -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
......
......@@ -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.
......
## 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment