mirror of
https://github.com/masscollaborationlabs/emacs.git
synced 2025-07-03 19:03:24 +00:00
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.
This commit is contained in:
parent
9b3a853ab2
commit
181bd848eb
4 changed files with 68 additions and 19 deletions
27
Makefile.in
27
Makefile.in
|
@ -153,6 +153,9 @@ sharedstatedir=@sharedstatedir@
|
||||||
# a subdirectory of this.
|
# a subdirectory of this.
|
||||||
libexecdir=@libexecdir@
|
libexecdir=@libexecdir@
|
||||||
|
|
||||||
|
# Currently only used for the systemd service file.
|
||||||
|
libdir=@libdir@
|
||||||
|
|
||||||
# Where to install Emacs's man pages.
|
# Where to install Emacs's man pages.
|
||||||
# Note they contain cross-references that expect them to be in section 1.
|
# Note they contain cross-references that expect them to be in section 1.
|
||||||
mandir=@mandir@
|
mandir=@mandir@
|
||||||
|
@ -196,6 +199,17 @@ desktopdir=$(datarootdir)/applications
|
||||||
# Where the etc/emacs.appdata.xml file is to be installed.
|
# Where the etc/emacs.appdata.xml file is to be installed.
|
||||||
appdatadir=$(datarootdir)/appdata
|
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.
|
# Where the etc/images/icons/hicolor directory is to be installed.
|
||||||
icondir=$(datarootdir)/icons
|
icondir=$(datarootdir)/icons
|
||||||
|
|
||||||
|
@ -714,6 +728,18 @@ install-etc:
|
||||||
${srcdir}/etc/emacs.appdata.xml > $${tmp}; \
|
${srcdir}/etc/emacs.appdata.xml > $${tmp}; \
|
||||||
${INSTALL_DATA} $${tmp} "$(DESTDIR)${appdatadir}/${EMACS_NAME}.appdata.xml"; \
|
${INSTALL_DATA} $${tmp} "$(DESTDIR)${appdatadir}/${EMACS_NAME}.appdata.xml"; \
|
||||||
rm -f $${tmp}
|
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`; \
|
thisdir=`/bin/pwd`; \
|
||||||
cd ${iconsrcdir} || exit 1; umask 022 ; \
|
cd ${iconsrcdir} || exit 1; umask 022 ; \
|
||||||
for dir in */*/apps */*/mimetypes; do \
|
for dir in */*/apps */*/mimetypes; do \
|
||||||
|
@ -779,6 +805,7 @@ uninstall: uninstall-$(NTDIR) uninstall-doc
|
||||||
fi)
|
fi)
|
||||||
-rm -f "$(DESTDIR)${desktopdir}/${EMACS_NAME}.desktop"
|
-rm -f "$(DESTDIR)${desktopdir}/${EMACS_NAME}.desktop"
|
||||||
-rm -f "$(DESTDIR)${appdatadir}/${EMACS_NAME}.appdata.xml"
|
-rm -f "$(DESTDIR)${appdatadir}/${EMACS_NAME}.appdata.xml"
|
||||||
|
-rm -f "$(DESTDIR)$(systemdunitdir)/${EMACS_NAME}.service"
|
||||||
for file in snake-scores tetris-scores; do \
|
for file in snake-scores tetris-scores; do \
|
||||||
file="$(DESTDIR)${gamedir}/$${file}"; \
|
file="$(DESTDIR)${gamedir}/$${file}"; \
|
||||||
[ -s "$${file}" ] || rm -f "$$file"; \
|
[ -s "$${file}" ] || rm -f "$$file"; \
|
||||||
|
|
|
@ -1570,7 +1570,7 @@ process.
|
||||||
|
|
||||||
You can solve this problem by setting up Emacs as an @dfn{edit
|
You can solve this problem by setting up Emacs as an @dfn{edit
|
||||||
server}, so that it ``listens'' for external edit requests and acts
|
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
|
@itemize
|
||||||
@findex server-start
|
@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
|
the calling terminal instead of opening an initial frame; it then
|
||||||
waits in the background, listening for edit requests.
|
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
|
@cindex socket activation, systemd, Emacs
|
||||||
@item
|
@item
|
||||||
An external process can invoke the Emacs server when a connection
|
An external process can invoke the Emacs server when a connection
|
||||||
event occurs upon a specified socket and pass the socket to the new
|
event occurs upon a specified socket and pass the socket to the new
|
||||||
Emacs server process. An instance of this is @command{systemd}'s
|
Emacs server process. An instance of this is the socket functionality
|
||||||
socket functionality: the @command{systemd} service creates a socket and
|
of @command{systemd}: the @command{systemd} service creates a socket and
|
||||||
listens for connections on it; when @command{emacsclient} connects to
|
listens for connections on it; when @command{emacsclient} connects to
|
||||||
it for the first time, @command{systemd} can launch the Emacs server
|
it for the first time, @command{systemd} can launch the Emacs server
|
||||||
and hand over the socket to it for servicing @command{emacsclient}
|
and hand over the socket to it for servicing @command{emacsclient}
|
||||||
connections. A setup to use this functionality could be:
|
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}:
|
@file{~/.config/systemd/user/emacs.socket}:
|
||||||
@example
|
@example
|
||||||
[Socket]
|
[Socket]
|
||||||
|
@ -1624,12 +1621,14 @@ ListenStream=/path/to/.emacs.socket
|
||||||
WantedBy=sockets.target
|
WantedBy=sockets.target
|
||||||
@end example
|
@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
|
The @code{ListenStream} path will be the path that Emacs listens for
|
||||||
connections from @command{emacsclient}; this is a file of your choice.
|
connections from @command{emacsclient}; this is a file of your choice.
|
||||||
@end itemize
|
@end itemize
|
||||||
|
|
||||||
@cindex @env{TEXEDIT} environment variable
|
@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
|
command called @command{emacsclient} to connect to the Emacs process
|
||||||
and tell it to visit a file. You can then set the @env{EDITOR}
|
and tell it to visit a file. You can then set the @env{EDITOR}
|
||||||
environment variable to @samp{emacsclient}, so that external programs
|
environment variable to @samp{emacsclient}, so that external programs
|
||||||
|
|
6
etc/NEWS
6
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
|
emacsclient commands. This new functionality can be disabled with the
|
||||||
configure option '--disable-libsystemd'.
|
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
|
** New configure option '--disable-build-details' attempts to build an
|
||||||
Emacs that is more likely to be reproducible; that is, if you build
|
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.
|
and install Emacs twice, the second Emacs is a copy of the first.
|
||||||
|
|
17
etc/emacs.service
Normal file
17
etc/emacs.service
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue