Skip to content

Hot reload

etemenanki-app reloads its configuration on its own when the config file changes on disk. You save the file, and the running process checks the new configuration and, if it can apply it, changes what runs to match. Open connections stay up unless the change concerns them. The REST API can ask for the same reload.

This page explains how a change is noticed, what happens to a file that cannot be applied, what a reload changes and what it keeps, and how to edit a live file without surprises. Read it before you change the config of a proxy that carries real traffic. katana reloads its own configuration differently; the katana guide covers that.

Question Answer
What starts a reload? Saving the config file, or the subscribe file it names. POST /v1/reload and a route switch through the REST API reload too.
A file that cannot be applied? Logged with the reason. The running configuration stays in place.
A file that is applied? Only what changed is rebuilt. Connections through unchanged parts stay up, and so do most connections through changed parts.
A TUN inbound, or a Hysteria 2 inbound’s obfs, changed? The reload is refused, because it would end that inbound’s connections. Restart to apply it.
A certificate renewed? Change the config file as well; see Changing a certificate or geodata file.
[log].level changed? Not applied. Restart to change it.
SIGHUP? Terminates the process. It is not a reload signal.

At startup, etemenanki-app starts a file watcher on the parent directory of the file you pass with -c, not on the file itself. Many editors save by writing a new file and renaming it over the old one; a watch on the file would lose track of it after the first save, while a watch on the directory sees every save. When -c is a bare file name such as config.toml, the watched directory is the working directory.

When the config has a [subscribe] section, the directory of the subscribe file it names is watched as well. The set of watched directories is updated after every reload, so a config that starts naming another subscribe file has that file followed from then on.

After a change in a watched directory, the watcher waits briefly for the burst of events to settle, so that an editor’s save, which often produces several events, leads to one reload. The reload then reads the config file, and the subscribe file it names, again by path.

If the watch on the config’s directory cannot be set up, for example because the per-user inotify limits (fs.inotify.max_user_instances, fs.inotify.max_user_watches) are reached, etemenanki-app logs one line:

ERROR etemenanki_app: config hot-reload disabled: <reason>

If you rely on reloads, check for this line after a start. Raise the limits and restart. A reload through the REST API does not depend on the watcher.

flowchart TB
  E["Change in a watched directory"] --> D["Settle briefly"]
  D --> R["Read the config file and its subscribe file"]
  R --> M["Merge the subscribe file, lower the config"]
  M --> P["Plan: compare the new configuration with what runs"]
  P --> G{"Would it end an inbound's live connections?"}
  G -- "yes" --> X["Refuse, keep the running config"]
  G -- "no" --> B["Build and bind what is new, beside what runs"]
  B --> C["Switch over, retire what is gone"]
  R & M & P & B -->|"error"| X
  1. Read. The config file, and the subscribe file its [subscribe] names.
  2. Check. The same stages as --test (see How a file is checked): parse, merge the subscribe file, lower, validate.
  3. Plan. Every inbound, outbound, balancer, the route table, the resolvers and the user lists are compared with what runs. What is unchanged is kept as it is; what changed is built again.
  4. Prepare. Everything new is built, and every new listener is bound, while the old configuration keeps serving. A failure here refuses the reload and leaves nothing half-applied.
  5. Commit. New connections switch to the new configuration. What the new file no longer has is retired.

An applied reload logs what it did, one group per kind of change:

INFO etemenanki_app::instance: config reloaded: built [route]; reused [dns, outbound home@v1, outbound travel@v1, inbound socks-in]
Group Lists
built What was built from the new file: new resources, and new versions of changed ones, such as outbound proxy@v2, balancer auto, route or dns
swapped Inbounds that kept their listener and serve new connections with new settings
drained Old outbound versions that were retired
rebound Inbounds bound on a new address or port
restarted Inbounds whose change ended their live connections (never listed by etemenanki-app, which refuses such a change)
removed Inbounds that are gone
reused What was kept exactly as it was

Groups with nothing in them are left out. The start logs the same summary as config loaded: ….

If the new file cannot be read, does not pass the checks, or cannot be built or bound, etemenanki-app logs the error and keeps the running configuration. Nothing stops, and no connection is dropped:

ERROR etemenanki_app::instance: reload: route references unknown outbound nope; keeping the running config

<error> is the same text --test prints for that file. A file with a TOML syntax error, or a misspelt key, logs a line that starts with reload: TOML parse error at line <n>, column <m>.

A change that would end live connections is refused with its own line:

ERROR etemenanki_app::instance: reload refused, keeping the running config: inbound tun-in: the tun inbound's settings changed; its runtime restarts and its flows end, which would end its live connections; restart to apply it

Two changes are refused this way: any change to a tun inbound, and a change to a Hysteria 2 inbound’s obfs or obfs_password, which connected clients cannot follow. Restart the process to apply them.

A listener that cannot be bound refuses the whole reload as well:

ERROR etemenanki_app::instance: reload: inbound http-in: binding 127.0.0.1:8080 failed: Address already in use (os error 98); keeping the running config

The running configuration keeps all of its listeners. Free the address or change the port.

When the file cannot be read at all, the line is reload: … with the operating system’s error. Permission denied (os error 13) typically means that the new file has a different owner or mode from the old one, so the service user cannot read it. Fix the owner or mode, and if no reload follows, save the file again.

After a failed edit, saving the file that is already running applies without changing anything: the summary lists every resource as reused.

A reload rebuilds only what changed. For each kind of change:

Change What happens
Nothing that matters, such as a comment Everything is reused. Nothing is rebuilt and no connection is touched.
An inbound’s settings, users, transport, certificate, REALITY keys or sniffing, with the same listen and port The listener keeps its socket, and new connections are served with the new settings. Connections already open keep the settings they were accepted with.
A user removed, or a user’s password, UUID or key changed New connections are checked against the new users. The removed user’s open connections, and the open connections that used the old credential, are closed. Other users’ connections are not touched.
An inbound’s port The inbound is bound on the new port. The connections it accepted on the old one stay open.
An inbound removed Its listener stops and its open connections are closed.
A tun inbound, or a Hysteria 2 inbound’s obfs Refused; restart to apply.
An outbound changed A new version of it is built, and new connections use the new version. Connections already open are not moved to it. A WireGuard outbound is the exception: its open connections are closed.
An outbound unchanged Kept as it runs, with the connection or tunnel it holds, such as a Hysteria 2 connection or a WireGuard tunnel, as long as [dns] is unchanged too.
An outbound removed It is no longer used for new connections. A removed WireGuard outbound also closes its open connections.
[route] New connections follow the new rules, and so does the next packet of every UDP association. Open TCP connections keep the outbound they were opened on; only a REST API switch with "close": true closes the ones it moved.
[dns] The resolvers are rebuilt with an empty cache, and every outbound except blackhole is built as a new version.
A [[balancer]], or one of its members The balancer is rebuilt: its members start healthy and are probed at once. A balancer whose members are all unchanged keeps their health.
The subscribe file Merged again: its nodes are outbounds and its route groups are the rules, with the effects above.
[api] The API is started, rebound or stopped once the reload is applied. See REST API.
[log] Not applied. The level is set once, at startup.
The RUST_LOG environment variable, the -c path Not applied. Both are fixed for the life of the process.

Relative paths in the file are resolved against the process’s working directory on every reload, just as at startup.

Certificate, key and CA files are read at startup and on each reload. To put a renewed certificate into service, change the config file after the new certificate is in place.

A convenient way is a dedicated comment line that your renewal job rewrites. For example, keep this as the first line of the config:

/etc/etemenanki/config.toml
# reload-stamp: 0

and run this after each certificate renewal:

Terminal window
sed -i "s/^# reload-stamp:.*/# reload-stamp: $(date +%s)/" /etc/etemenanki/config.toml

GNU sed -i writes a new file in the same directory and renames it over the old one, so the proxy never reads a half-written file. The inbound keeps its listener: new connections get the new certificate, and open connections carry on with the old one. Nothing is dropped.

After you update the geodata files that [route] names, restart etemenanki-app.

Two things can go wrong when you edit the file that a running proxy watches:

  • A half-written file. The watcher reads the file shortly after any event in its directory. If your tool writes the file in several steps, or you copy it over a slow link, etemenanki-app may read a truncated file. A truncated file is usually refused, but one that happens to end between two tables can still be valid, and it would then be applied without the tables after the cut.
  • A mistake you only notice after saving. A file that cannot be applied is refused safely, but a valid file that does the wrong thing, such as a route pointing at the wrong outbound, is applied at once.

Write the new version next to the live file, check it, and move it into place in one step. The commands assume the etemenanki service user and the /etc/etemenanki layout from Running in production:

  1. Copy the live config, keeping its owner and mode, and edit the copy in the same directory:

    Terminal window
    sudo cp -p /etc/etemenanki/config.toml /etc/etemenanki/config.toml.new
    sudoedit /etc/etemenanki/config.toml.new

    -p matters: a copy that the service user cannot read is refused later with Permission denied (os error 13).

  2. Check the copy with --test, as the service user and from the working directory the service uses, so that file permissions and relative paths are the same as in a reload:

    Terminal window
    sudo -u etemenanki sh -c 'cd /etc/etemenanki && exec /usr/local/bin/etemenanki-app --test -c config.toml.new'

    It prints Configuration OK. on success. --test runs every check a reload runs except binding listeners and creating TUN devices, so a port that is already taken still passes.

  3. Rename the copy over the live file:

    Terminal window
    sudo mv /etc/etemenanki/config.toml.new /etc/etemenanki/config.toml

    A rename within one directory is atomic: the proxy reads either the old file or the new one, never a mix. Do not cp over the live file, which writes it in place. The REST API writes the file the same way when it switches a route.

  4. Check the log for the config reloaded: … line:

    Terminal window
    journalctl -u etemenanki -n 20

    Look in particular for keeping the running config, which means the new file was not applied.

A subscribe file deserves the same care: download it next to the live one, then rename it into place.

Symptom Cause Fix
Saving the file changes nothing, and no reload line appears Nothing in the file changed, or the watcher is off (config hot-reload disabled) Make a real change; restart if the watcher is off
reload refused, keeping the running config: inbound …, which would end its live connections; restart to apply it A tun inbound, or a Hysteria 2 inbound’s obfs, changed Restart the process
reload: inbound … binding … failed: …; keeping the running config The new address is taken, or a port below 1024 needs a privilege the process lacks Free the address or change the port
reload: … No such file or directory (os error 2); keeping the running config A file the config refers to is missing, or a relative path resolves against a different working directory Fix the path
reload: subscribe: …; keeping the running config The subscribe file, or a pick in [subscribe.routes], is wrong See the errors on Subscribe files
The log level stays the same after a change [log].level is read only at startup Restart the process
Permission denied (os error 13) on a reload The new file’s owner or mode does not let the service user read it Fix the owner or mode
The process exited after SIGHUP, for example from an ExecReload=/bin/kill -HUP $MAINPID line in the unit etemenanki-app has no SIGHUP handler, so the signal terminates it Remove the ExecReload= line and save the file instead; see Running in production