Skip to content

Instantly share code, notes, and snippets.

@volh
Created August 8, 2011 16:57
Show Gist options
  • Select an option

  • Save volh/1132180 to your computer and use it in GitHub Desktop.

Select an option

Save volh/1132180 to your computer and use it in GitHub Desktop.

Revisions

  1. volh revised this gist Aug 8, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ case "$1" in
    ;;
    stop)
    stat_busy "Stopping Emacs"
    su $USERNAME -c "nohup $EMACSCLIENT --eval \"$EVALEXIT\"" && ( rm_daemon emacs; stat_done ) || stat_fail
    su $USERNAME -c "$EMACSCLIENT --eval \"$EVALEXIT\"" && ( rm_daemon emacs; stat_done ) || stat_fail
    ;;
    restart|force-reload)
    $0 stop
  2. volh renamed this gist Aug 8, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. volh created this gist Aug 8, 2011.
    44 changes: 44 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    #! /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 "nohup $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