[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to run --daemon in foreground?

From: Bob Proulx
Subject: Re: How to run --daemon in foreground?
Date: Sun, 30 Oct 2016 17:50:37 -0600
User-agent: NeoMutt/20161014 (1.7.1)

Jean Louis wrote:
> I wish to run emacs --daemon, that it stays in foreground. The daemon
> sometimes quits, and I wish to supervise it by using so
> excellent s6-rc service manager, to run emacs as user, and to restart
> it whenever necessary:
> For that purpose, I need the daemon to stay in foreground. The other
> daemons I know, always have an option to stay in foreground.

The "Using Emacs as a Server" node in the emacs manual says:

  There are two ways to start an Emacs server:

   * Run the command ‘server-start’ in an existing Emacs process: either
     type ‘M-x server-start’, or put the expression ‘(server-start)’ in
     your init file (*note Init File::).  The existing Emacs process is
     the server; when you exit Emacs, the server dies with the Emacs

   * Run Emacs as a “daemon”, using the ‘--daemon’ command-line option.
     *Note Initial Options::.  When Emacs is started this way, it calls
     ‘server-start’ after initialization, and returns control to the
     calling terminal instead of opening an initial frame; it then waits
     in the background, listening for edit requests.

Seems to me that using --daemon is the command line argument to
background the emacs process.  If that is not desired then you must
use the other way documented above using server-start.  Therefore the
trick is how to use that as you want.  AFAIK that requires a tty on
stdin to be present.  Using a terminal session manager such as screen
(or I presume tmux too) can provide this.

  screen -S emacs -d -m -- emacs -f server-start
    # -S emacs -- session name, give a meaningful name to session
    # -d -m -- Start screen in "detached" mode. This creates a new
               session but doesn't attach  to  it.  This  is  useful
               for  system startup scripts.
    # emacs -f server-start -- launch emacs and call function

After starting emacs in this detached screen session then you can
attach to the running emacs server as you describe.

About the only drawback is that if you were previously using screen a
lot anyway and used to doing "screen -dr" without a name then that
will now have two to choose from and need qualification.  But if you
are really into screen then you have several already and one more is
no significant change.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]