From: Sebastian Rose <sebastian_rose@gmx.de>
To: Stefan Vollmar <vollmar@nf.mpg.de>
Cc: "Gregory J. Grubbs" <gregory@dynapse.com>,
emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: Re: org batch job using emacsclient?
Date: Tue, 17 Nov 2009 03:25:34 +0100 [thread overview]
Message-ID: <87bpj13n1d.fsf@gmx.de> (raw)
In-Reply-To: <9F07BE57-B87D-4433-8489-4CDD268EC638@nf.mpg.de> (Stefan Vollmar's message of "Tue, 17 Nov 2009 01:12:09 +0100")
Stefan Vollmar <vollmar@nf.mpg.de> writes:
> Gentlemen,
>
> thanks for the many helpful replies!
>
> To start with, it now works for me and I can measure a consistent speedup of 7x
> (!) for using emacsclient - in an interactive web service (conversion of
> org-files to HTML) the difference between 0.35 s and 2.40 s (average) is
> significant.
That was to be expected :)
> (1) Having started the emacs server with
>
> emacs --daemon=org
>
> this shell script works for me:
>
> #!/bin/sh
> emacsclient -s org
> --eval "(progn
> (add-to-list 'load-path \"/opt/org-6.33c/lisp/\")
> (require 'org)(require 'org-exp)
> (setq org-export-headline-levels 2)
> (find-file \"$1\")
> (org-export-as-html 2 nil nil nil nil \".\")
> (kill-buffer))"
>
> I have added a (kill-buffer) statement for cleaning up (I observed an increasing
> number of emacsclient processes before), is this a good solution?
Does it help? Then I think it's ok.
The `usual' way to close a server buffer is `C-x #' which is bound to
the function `server-edit'. That's what I use in org-protocol.el. The
name is somewhat confusing, though.
Another trick is, to simply not wait for a reply from the server at
all:
emacsclient --no-wait ...
> (2) A problem remains with (1): it seems that I need to "name" the daemon.
> Otherwise there could be a conflict with Emacs daemons started by other users.
> How can I make sure the daemon is running if the script requires it? I read
> about a "-a" option for emacsclient - how would this work in my case?
I would start Emacs in rc.emacs-server like this (but maybe use no
server at all, see below):
/path/to/emacs -Q -l /etc/emacs-server/init.el --daemon=SERVER-NAME
/path/to/emacsclient --no-wait --socket-name=SERVER-NAME xy.org
You could also use an absolute path for the socket.
and put all required setup into /etc/emacs-server/init.el. `-Q'
ensures emacs will start correctly, even if a user without a
home-directory (e.g. apache user) starts it and thus no ~/.emacs can
be found (start-stop-daemon switches to the UID you tell it). Also, if
started as root, emacs will _not_ load root's .emacs.
Start Emacs in an /etc/init.d/rc.emacs-server script to make sure it
starts when you restart the server. Use `start-stop-daemon' to do so
[1] and provide the commands `start', `stop', `restart' and `status'
maybe. A cron-job could check for a running emacs-server via
/etc/init.d/rc.emacs-server status
every 5 minutes or so. If that fails, re-start Emacs.
Your script could check for the running Emacs, too, and restart it as
necessary.
Are you familiar with init.d stuff? There is an example file somewhere
on Debian...
http://github.com/SebastianRose/denycc/blob/master/scripts/rc.denycc
is made from such an example file for Debian 4.0
Access privileges might be important. Unfortunately I have no good
concept at hand - I don't thing emacs-server offers one at all,
actually. Something to read...
At least I would add something like this to your emacsclient
shell-script (insert you Apaches EUID for the 99):
if [ 99 -ne $EUID ];then
echo "Got to be a native American to execute this command!"
exit 124
fi
Best wishes
Sebastian
== Footnotes: ====
[1] From `man start-stop-daemon' (German version - English version below):
BESCHREIBUNG
start-stop-daemon wird zur Steuerung der Erzeugung und Beendigung
von Prozessen auf Syste‐ mebene verwendet. Durch die Verwendung
einer der Abgleich-Optionen kann start-stop-daemon so
konfiguriert werden, dass er existierende Instanzen von einem
laufenden Prozess finden kann.
Hinweis: Falls --pidfile nicht angegeben ist, verhält sich
start-stop-daemon ähnlich zu killall(1). start-stop-daemon wird
die Prozesstabelle nach Prozessen durchsuchen, die auf den
Prozessnamen, uid und/oder gid (falls angegeben) passen. Jeder
passende Prozess wird --start daran hindern, den Daemon zu
starten. Allen passenden Prozessen wird das KILL-Sig‐ nal
geschickt, falls --stop angegeben ist. Für Daemons die langlebige
Kinder haben, die ein --stop überleben sollen, müssen Sie eine
PID-Datei angeben.
* man -L en_US start-stop-daemon:
DESCRIPTION
start-stop-daemon is used to control the creation and termination
of system-level pro‐ cesses. Using one of the matching options,
start-stop-daemon can be configured to find existing instances of
a running process.
Note: unless --pidfile is specified, start-stop-daemon behaves
similar to killall(1). start-stop-daemon will scan the process
table looking for any processes which match the process name,
uid, and/or gid (if specified). Any matching process will prevent
--start from starting the daemon. All matching processes will be
sent the KILL signal if --stop is specified. For daemons which
have long-lived children which need to live through a --stop, you
must specify a pidfile.
next prev parent reply other threads:[~2009-11-17 2:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-16 8:51 org batch job using emacsclient? Stefan Vollmar
2009-11-16 11:07 ` Noorul Islam K M
2009-11-16 11:13 ` Adam Spiers
2009-11-16 14:07 ` Magnus Henoch
2009-11-16 15:41 ` Gregory J. Grubbs
2009-11-17 0:12 ` Stefan Vollmar
2009-11-17 2:25 ` Sebastian Rose [this message]
2009-11-17 9:06 ` Stefan Vollmar
2009-11-17 12:16 ` Sebastian Rose
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
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bpj13n1d.fsf@gmx.de \
--to=sebastian_rose@gmx.de \
--cc=emacs-orgmode@gnu.org \
--cc=gregory@dynapse.com \
--cc=vollmar@nf.mpg.de \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
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).