all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Bob Proulx <bob@proulx.com>
To: Jean Louis <bugs@gnu.support>
Cc: help-gnu-emacs@gnu.org
Subject: Re: How to run --daemon in foreground?
Date: Sun, 30 Oct 2016 17:50:37 -0600	[thread overview]
Message-ID: <20161030153451214174078@bob.proulx.com> (raw)
In-Reply-To: <20161029151559.GB30693@protected.rcdrun.com>

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 skarnet.org so
> excellent s6-rc service manager, to run emacs as user, and to restart
> it whenever necessary: http://skarnet.org/software/
> 
> 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
     process.

   * 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.

Bob



  parent reply	other threads:[~2016-10-30 23:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-29 15:15 How to run --daemon in foreground? Jean Louis
2016-10-30 18:09 ` Glenn Morris
2016-10-30 18:42   ` Jean Louis
2016-10-30 23:50 ` Bob Proulx [this message]
2016-10-31  0:01   ` Stefan Monnier
2016-10-31  0:19     ` Glenn Morris
2016-10-31 12:41       ` Jean Louis
2016-10-31 14:26       ` Philipp Stephani
2016-10-31  5:47   ` Jean Louis
2016-10-31  5:53   ` Jean Louis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161030153451214174078@bob.proulx.com \
    --to=bob@proulx.com \
    --cc=bugs@gnu.support \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.