summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app-emacs/emacs-daemon/files/emacs-daemon.rc')
-rw-r--r--app-emacs/emacs-daemon/files/emacs-daemon.rc16
1 files changed, 13 insertions, 3 deletions
diff --git a/app-emacs/emacs-daemon/files/emacs-daemon.rc b/app-emacs/emacs-daemon/files/emacs-daemon.rc
index 59f9b9b..63d5a1b 100644
--- a/app-emacs/emacs-daemon/files/emacs-daemon.rc
+++ b/app-emacs/emacs-daemon/files/emacs-daemon.rc
@@ -4,7 +4,9 @@
# Distributed under the terms of the GNU General Public License v2
EMACS="/usr/bin/emacs"
-USER=${RC_SVCNAME#*.}
+USER="${RC_SVCNAME#*.}"
+PIDFILE_DIR="/var/run/emacs-daemon/${USER}"
+PIDFILE="${PIDFILE_DIR}/emacs.pid"
checkconfig() {
if [ "${USER}" = "${RC_SVCNAME}" ]; then
@@ -18,6 +20,8 @@ checkconfig() {
return 1
fi
+ # Executing Emacs here also ensures a warm cache, which later helps
+ # to create the pid file in a timely manner (within 0.5 seconds).
local has_daemon=$(${EMACS} -batch -q --no-site-file \
--eval "(princ (fboundp 'daemonp))")
if [ "${has_daemon}" != t ]; then
@@ -25,6 +29,12 @@ checkconfig() {
return 1
fi
+ if [ ! -d "${PIDFILE_DIR}" ]; then
+ ewarn "${PIDFILE_DIR} does not exist - creating it"
+ mkdir -p "${PIDFILE_DIR}"
+ chown "${USER}" "${PIDFILE_DIR}"
+ fi
+
return 0
}
@@ -35,13 +45,13 @@ start() {
ebegin "Starting Emacs daemon for ${USER}"
eval home="~${USER}"
start-stop-daemon --start --user "${USER}" --chdir "${home}" \
- --quiet --name emacs-daemon --exec "${EMACS}" -- --daemon
+ --quiet --pidfile "${PIDFILE}" --exec "${EMACS}" -- --daemon
eend $?
}
stop() {
ebegin "Stopping Emacs daemon for ${USER}"
start-stop-daemon --stop --user "${USER}" \
- --name emacs-daemon --exec "${EMACS}"
+ --pidfile "${PIDFILE}" --exec "${EMACS}"
eend $?
}