This page is a row in the executable that served it.

There is one file on that server. It is a SQLite database, file(1) says so, and it is also the program the kernel executed to answer this request. The HTML you are reading came out of SELECT body FROM routes WHERE path = '/index.html', run by the process whose own machine code lives three tables over.

The file

$ file server
server: SQLite 3.x database, application id 1397050438, user version 1, ...

$ xxd -s 64 -l 8 server     # 1397050438 == 0x53454c46, the binfmt magic
00000040: 0000 0000 5345 4c46                      ....SELF

$ ./server --journal wal 8080
self-httpd: serving 3 routes out of /srv/self/server
self-httpd: listening on http://0.0.0.0:8080 with 4 workers (journal=wal)

$ sqlite3 server 'SELECT path, mime, bytes FROM site'

The format is SELF, the Structured Executable & Linkable Format: an ELF program rewritten as rows. segments holds the load image, symbols replaces .dynsym plus .gnu.hash, and a binfmt_misc interpreter maps the rows and jumps to 0x2ea0. Nothing holds the file open once the program is running, so the program can open its own path as a database and serve out of it.

What is in it, right now

Every number below is a SELECT against this file, evaluated while it was answering your request.

13segments
179symbols
105relocations
2needed libraries
3routes
12tables
486requests recorded
133presses recorded

233472 bytes · 4096-byte pages · x86_64 · interpreter /lib64/ld-linux-x86-64.so.2 · SQLite 3.45.1

Write to it

visits and presses are ordinary tables in the same file. Pressing this button is an INSERT into the executable, committed before the response is written:

CREATE TABLE presses (id INTEGER PRIMARY KEY, at TEXT, button TEXT);
INSERT INTO presses (at, button) VALUES (datetime('now'), 'press');

Its own table of contents

sqlite_schema is this format's section header table, so the list below is readelf -S with the row counts filled in.

loading…

Deploying is scp. Editing is a transaction.

There is no asset bundle, no template directory, and no restart. The site is data in the running program, so changing it is SQL, and undoing the change is ROLLBACK:

$ sqlite3 server "UPDATE routes SET body = readfile('new.html')
                  WHERE path = '/index.html'"
$ curl -s https://selfdb.exe.xyz | head -1   # already served, no restart

$ sqlite3 server 'SELECT count(*), ua FROM visits
                  GROUP BY ua ORDER BY 1 DESC LIMIT 3'

$ sqldiff --summary yesterday.server server  # what did the deploy touch?