Skip to content

Instantly share code, notes, and snippets.

@volh
Created August 8, 2011 16:57
Show Gist options
  • Save volh/1132180 to your computer and use it in GitHub Desktop.
Save volh/1132180 to your computer and use it in GitHub Desktop.
#! /bin/sh
. /etc/rc.conf
. /etc/rc.d/functions
#change this. too bad emacs daemon can't really work in mutli-user mode. for now.
USERNAME=volh
DESC="Run the emacs daemon."
NAME=emacs
#change this
DAEMON=/usr/bin/$NAME
DAEMON_ARGS="--daemon"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/rc.d/$NAME
#change this
EMACSCLIENT=/usr/bin/emacsclient
#EVALEXIT="(progn (setq kill-emacs-hook 'nil) (kill-emacs))"
# This one will save buffers in any case, without prompt(as save-buffers-kill-emacs will unconditionally do).
EVALEXIT="(progn (save-some-buffers t t)(kill-emacs))"
# This will save the desktop, but not the buffers themselves
#EVALEXIT="(progn (desktop-save-in-desktop-dir)(kill-emacs))"
case "$1" in
start)
stat_busy "Starting Emacs"
su $USERNAME -c "$DAEMON $DAEMON_ARGS" > /dev/null && (add_daemon emacs; stat_done) || stat_fail
;;
stop)
stat_busy "Stopping Emacs"
su $USERNAME -c "$EMACSCLIENT --eval \"$EVALEXIT\"" && ( rm_daemon emacs; stat_done ) || stat_fail
;;
restart|force-reload)
$0 stop
sleep 1
$0 start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment