diff options
author | Ulrich Müller <ulm@gentoo.org> | 2008-11-02 10:06:54 +0000 |
---|---|---|
committer | Ulrich Müller <ulm@gentoo.org> | 2008-11-02 10:06:54 +0000 |
commit | 4dcbeaee929e2980e4ea92f2df678aad70ab78c2 (patch) | |
tree | 164dc573c50043e9d1f7a6727486fdf63a9d4aba | |
download | emacs-tools-emacs-daemon-0.3.tar.gz emacs-tools-emacs-daemon-0.3.tar.bz2 emacs-tools-emacs-daemon-0.3.zip |
Initial import of emacs-daemon.emacs-daemon-0.3
svn path=/emacs-daemon/; revision=1147
-rw-r--r-- | 10emacs-daemon-gentoo.el | 12 | ||||
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | Makefile | 21 | ||||
-rw-r--r-- | emacs-daemon.rc | 57 |
4 files changed, 98 insertions, 0 deletions
diff --git a/10emacs-daemon-gentoo.el b/10emacs-daemon-gentoo.el new file mode 100644 index 0000000..ae29057 --- /dev/null +++ b/10emacs-daemon-gentoo.el @@ -0,0 +1,12 @@ + +;;; emacs-daemon site-lisp configuration + +(and + (fboundp 'daemonp) + (daemonp) + (let ((file (concat "/var/run/emacs-daemon/" + (user-login-name) "/emacs.pid"))) + (if (file-writable-p file) + ;; write process id to file + (with-temp-file file + (insert (number-to-string (emacs-pid)) "\n"))))) diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..c10e3f0 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,8 @@ +2008-11-02 Ulrich Mueller <ulm@gentoo.org> + + * Version 0.3 released. + + * emacs-daemon.rc, 10emacs-daemon-gentoo.el, Makefile: New files. + +Copyright 2008 Gentoo Foundation +Distributed under the terms of the GNU General Public License v2 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f50285d --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +# Copyright 2008 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +PN = emacs-daemon +PV = $(shell sed '/^[ \t]*\* .*[Vv]ersion/!d;s/[^0-9.]*\([0-9.]*\).*/\1/;q' \ + ChangeLog) +P = $(PN)-$(PV) + +DISTFILES = ChangeLog emacs-daemon.rc 10emacs-daemon-gentoo.el + + +.PHONY: all dist clean + +all: + +dist: $(DISTFILES) + tar -cjf $(P).tar.bz2 --transform='s%^%$(P)/%' $^ + tar -tjvf $(P).tar.bz2 + +clean: + -rm -f *~ *.tmp *.gz *.bz2 diff --git a/emacs-daemon.rc b/emacs-daemon.rc new file mode 100644 index 0000000..3231a4c --- /dev/null +++ b/emacs-daemon.rc @@ -0,0 +1,57 @@ +#!/sbin/runscript +# Copyright 2008 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id$ + +EMACS="/usr/bin/emacs" +USER="${RC_SVCNAME#*.}" +PIDFILE_DIR="/var/run/emacs-daemon/${USER}" +PIDFILE="${PIDFILE_DIR}/emacs.pid" + +checkconfig() { + if [ "${USER}" = "${RC_SVCNAME}" ]; then + eerror "You have to create an init script for each user:" + eerror "ln -s emacs-daemon /etc/init.d/emacs-daemon.<user>" + return 1 + fi + + if ! id -u "${USER}" >/dev/null; then + eerror "${USER}: No such user" + 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 + eerror "${EMACS} does not support running as a daemon" + 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 +} + +start() { + local home + checkconfig || return 1 + + ebegin "Starting Emacs daemon for ${USER}" + eval home="~${USER}" + start-stop-daemon --start --user "${USER}" --chdir "${home}" \ + --quiet --pidfile "${PIDFILE}" --exec "${EMACS}" -- --daemon + eend $? +} + +stop() { + ebegin "Stopping Emacs daemon for ${USER}" + start-stop-daemon --stop --user "${USER}" \ + --pidfile "${PIDFILE}" --exec "${EMACS}" + eend $? +} |