You know, because I can.
(I promised @nicferrier a writeup on this project, so here goes.)
Installing Emacs 24
The Emacs that comes with the Raspian distribution is version 23.4. Unfortunately, elnode requires Emacs 24, so I had to compile my own. I dreaded doing this, but it actually turned out pretty straightforward.
You need to
apt-get install some build dependencies like
libncurses-dev (and probably
build-essentials if you don’t
already have them), then you’re ready to go:
This would be a good opportunity to make a sandwich, or learn some sanskrit, as building everything will take quite a while.
By default the elnode webserver runs on Emacs startup, so the idea is to fire up emacs and just leave it. One way of doing that would be to ssh into the Pi and run emacs inside a tmux session (I tend to use tmux for all remote access anyway). This makes the emacs process persistent, and when I next log in I can just resume the session.
However, with this approach I’d still need to login in and start manually every time the server restarts, so the setup is kind of fragile. Especially since I have builders running round the house cutting the main power every now and then.
So instead I use a simple init script to run emacs in daemon mode
(using the aptly named
--daemon switch). This way I can still
connect to the running emacs process using
emacsclient, but I don’t
have to bother with starting it manually anymore.
The only caveat is that since I want
start-stop-daemon to fork off a
new process to run emacs as the
pi user (running a web-connected
root seems like a really bad idea), I can’t rely on it to
generate a correct PID file for me. Instead, we’ll have to do that
from inside emacs (see next section).
When I start the deamon I get some weird error messages from elnode, but as far as I can tell it actually runs fine.
This is my little Hello World-script. There’s nothing remarkable about
it, really. The first section generates a PID file to be used by the
init script to check if the process is running. I stop the default
server, as it binds to “localhost”, and I want to bind to the actual
server name (
raspberrypi.local in my case) in order to serve remote
requests. You can see it in action here.
Did I say there was nothing remarkable about this script? Yeah, apart from the fact that it’s running a webserver inside a 25 year old text editor on a computer that’s about as large as a deck of cards.