* How to run --daemon in foreground?
@ 2016-10-29 15:15 Jean Louis
2016-10-30 18:09 ` Glenn Morris
2016-10-30 23:50 ` Bob Proulx
0 siblings, 2 replies; 10+ messages in thread
From: Jean Louis @ 2016-10-29 15:15 UTC (permalink / raw)
To: help-gnu-emacs
Hello,
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.
Shall I maybe re-define some of scripts for my usage?
Or maybe such option shall be included in the emacs.
Jean
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to run --daemon in foreground?
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
1 sibling, 1 reply; 10+ messages in thread
From: Glenn Morris @ 2016-10-30 18:09 UTC (permalink / raw)
To: Jean Louis; +Cc: help-gnu-emacs
Jean Louis wrote:
> Or maybe such option shall be included in the emacs.
See https://debbugs.gnu.org/2677 and merged 4944.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to run --daemon in foreground?
2016-10-30 18:09 ` Glenn Morris
@ 2016-10-30 18:42 ` Jean Louis
0 siblings, 0 replies; 10+ messages in thread
From: Jean Louis @ 2016-10-30 18:42 UTC (permalink / raw)
To: Glenn Morris; +Cc: help-gnu-emacs
Interesting. While I don't agree on systemd and LSB, I like daemons that may be kept in foreground.
I have some problems launching emacs on dumb terminals or from a command line, headless, without --daemon.
If someone knows how to do it, I wish to know?
To keep daemon in foreground is just few lines in emacs.c, I guess that would be nice to see include for future.
Jean
On October 30, 2016 9:09:17 PM GMT+03:00, Glenn Morris <rgm@gnu.org> wrote:
>Jean Louis wrote:
>
>> Or maybe such option shall be included in the emacs.
>
>See https://debbugs.gnu.org/2677 and merged 4944.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to run --daemon in foreground?
2016-10-29 15:15 How to run --daemon in foreground? Jean Louis
2016-10-30 18:09 ` Glenn Morris
@ 2016-10-30 23:50 ` Bob Proulx
2016-10-31 0:01 ` Stefan Monnier
` (2 more replies)
1 sibling, 3 replies; 10+ messages in thread
From: Bob Proulx @ 2016-10-30 23:50 UTC (permalink / raw)
To: Jean Louis; +Cc: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to run --daemon in foreground?
2016-10-30 23:50 ` Bob Proulx
@ 2016-10-31 0:01 ` Stefan Monnier
2016-10-31 0:19 ` Glenn Morris
2016-10-31 5:47 ` Jean Louis
2016-10-31 5:53 ` Jean Louis
2 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2016-10-31 0:01 UTC (permalink / raw)
To: help-gnu-emacs
> 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.
Actually, it should be possible to use a foreground process without
a tty by using "emacs --batch". IIUC it will require fiddling to make
it work right, but it's be good if someone could try it and report its
experience (e.g. in the form of a bug-report).
Stefan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to run --daemon in foreground?
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
0 siblings, 2 replies; 10+ messages in thread
From: Glenn Morris @ 2016-10-31 0:19 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
Stefan Monnier wrote:
> Actually, it should be possible to use a foreground process without
> a tty by using "emacs --batch". IIUC it will require fiddling to make
> it work right, but it's be good if someone could try it and report its
> experience (e.g. in the form of a bug-report).
There's a 7-year old bug report with a simple patch to add equivalent
functionality. https://debbugs.gnu.org/4944
It seems to me like a feature Emacs should have.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to run --daemon in foreground?
2016-10-30 23:50 ` Bob Proulx
2016-10-31 0:01 ` Stefan Monnier
@ 2016-10-31 5:47 ` Jean Louis
2016-10-31 5:53 ` Jean Louis
2 siblings, 0 replies; 10+ messages in thread
From: Jean Louis @ 2016-10-31 5:47 UTC (permalink / raw)
To: Bob Proulx; +Cc: help-gnu-emacs
Dear Bob,
Thank you for the suggestions.
On Sun, Oct 30, 2016 at 05:50:37PM -0600, Bob Proulx wrote:
> 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/
> 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.
Yes, I have tried with many options of screen, and now with your help,
I have found the right solution. Screen is not allowed to detach, that
way the supervision system s6-rc keeps it well in background. Emacs
daemon is sometimes crashing, and now I have solution to turn it on in
background, when the directory ~/Work is available. It means, when
encrypted partition gets mounted.
And with su - admin, I give to emacs the environment to run
with, even I would like to give it just what is necessary, I don't
know what it needs yet.
System is now working, without thinking.
#!/bin/execlineb
if { s6-test -d /home/data1/protected/Work }
su - admin -s /bin/bash -l -c "/usr/bin/screen -S emacs -D -m -- /usr/bin/emacs --user admin --chdir /home/data1/protected"
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to run --daemon in foreground?
2016-10-30 23:50 ` Bob Proulx
2016-10-31 0:01 ` Stefan Monnier
2016-10-31 5:47 ` Jean Louis
@ 2016-10-31 5:53 ` Jean Louis
2 siblings, 0 replies; 10+ messages in thread
From: Jean Louis @ 2016-10-31 5:53 UTC (permalink / raw)
To: help-gnu-emacs
I forgot to tell, that I use (server-start) in the .emacs so, this way
I can start the misbehaving emacs in foreground, by using screen,
without problems with terminal and ttys, and that it is supervised by
s6-rc tools from skarnet.org, similar to runit or daemontools by djb.
Jean
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to run --daemon in foreground?
2016-10-31 0:19 ` Glenn Morris
@ 2016-10-31 12:41 ` Jean Louis
2016-10-31 14:26 ` Philipp Stephani
1 sibling, 0 replies; 10+ messages in thread
From: Jean Louis @ 2016-10-31 12:41 UTC (permalink / raw)
To: Glenn Morris; +Cc: help-gnu-emacs, Stefan Monnier
Now I have found best solution for me to run emacs, by supervision of
s6-rc tools http://skarnet.org/software/:
#!/bin/execlineb
if { s6-test -d /home/data1/protected/Work }
su - admin -s /bin/execlineb -c "/usr/bin/screen -S emacs -D -m -- /usr/bin/emacs --user admin --chdir /home/data1/protected"
The first line is only checking if directory exists, as it is only
there with encrypted partition. Not in the standard one.
The second one is taking all my user environment and starting screen
with emacs. If emacs exists for any reason, screen does not have a
shell to remain in background, but exists as well, due to execlineb
program, and daemon is respawned.
I still look into --start-server option, to heave it headless in
background.
Jean
On Sun, Oct 30, 2016 at 08:19:26PM -0400, Glenn Morris wrote:
> Stefan Monnier wrote:
>
> > Actually, it should be possible to use a foreground process without
> > a tty by using "emacs --batch". IIUC it will require fiddling to make
> > it work right, but it's be good if someone could try it and report its
> > experience (e.g. in the form of a bug-report).
>
> There's a 7-year old bug report with a simple patch to add equivalent
> functionality. https://debbugs.gnu.org/4944
>
> It seems to me like a feature Emacs should have.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to run --daemon in foreground?
2016-10-31 0:19 ` Glenn Morris
2016-10-31 12:41 ` Jean Louis
@ 2016-10-31 14:26 ` Philipp Stephani
1 sibling, 0 replies; 10+ messages in thread
From: Philipp Stephani @ 2016-10-31 14:26 UTC (permalink / raw)
To: Glenn Morris, Stefan Monnier; +Cc: help-gnu-emacs
Glenn Morris <rgm@gnu.org> schrieb am Mo., 31. Okt. 2016 um 01:22 Uhr:
> Stefan Monnier wrote:
>
> > Actually, it should be possible to use a foreground process without
> > a tty by using "emacs --batch". IIUC it will require fiddling to make
> > it work right, but it's be good if someone could try it and report its
> > experience (e.g. in the form of a bug-report).
>
> There's a 7-year old bug report with a simple patch to add equivalent
> functionality. https://debbugs.gnu.org/4944
>
> It seems to me like a feature Emacs should have.
>
>
Agreed. However, the patch doesn't apply cleanly any more.
Please note that starting Emacs without --daemon and '-f server-start' is
not the same: it ignores the systemd socket activation; that code path is
only taken if the --daemon flag is present. Therefore, a new flag (or
--daemon=foreground etc.) is needed.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2016-10-31 14:26 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).