Skip to content

Deploy a new version

A running nvs serve uses new code and most configuration changes without a restart. This page shows a deploy that is safe at every step. The last section shows how to work the same way while you develop, alone or with a coding agent.

Copy each release into a folder of its own. A link named current points to the release that runs:

/srv/shop/
releases/
2026-11-20/
2026-11-21/
current -> releases/2026-11-21

Start the server with the path through the link:

Terminal window
nvs serve /srv/shop/current/public/index.nvs

Copy the new release into its own folder first. When the copy is complete, switch the link. On Linux, these two commands replace the link in one step:

Terminal window
ln -sfn releases/2026-11-21 /srv/shop/current.new
mv -T /srv/shop/current.new /srv/shop/current

The server reads the link at the start of each compile and again at the end. If the link changed during the compile, the server throws that compile away and compiles again. So it never builds one program from two releases.

The server finds the change by itself within [opcache] revalidate_freq. The default is 2s. Run nvs reload to make the change take effect at once, and to see the result:

Terminal window
nvs reload
server 4120: configuration unchanged, 1 program reloaded, 0 programs with errors

The server checks its configuration files and every program it has loaded. The command returns when every compile has ended. A program that no request has loaded yet is compiled by its first request.

A reload compiles only the functions that changed. The server uses its saved code for every other function. The log has one program reloaded line for each program. Its compiled field is the number of functions compiled, and reused is the number used again.

Run nvs reload as the account that runs the server, or as an administrator. It reloads every server that uses the same data folder. The data folder is where nvs keeps its own files, such as the compile cache. If the server was started with --data, give the same --data to nvs reload. --json prints the result as one JSON document.

Exit code Meaning
0 Every server uses the files on disk.
1 A configuration file or a program has an error. Each error is printed with its file and line. A server that did not reply also gives 1.
2 No server is running for this data folder.

When a program has an error, the server does not use the new version of it. Every request to that program fails with the error until you fix the file. When a server does not reply, the command cannot tell which files it uses. Its line says could not be reached or closed the connection without a reply. So a deploy script switches back to the previous release when the exit code is 1:

#!/bin/sh
cd /srv/shop
ln -sfn releases/2026-11-21 current.new
mv -T current.new current
nvs reload
case $? in
0) echo "The new release is live." ;;
1) echo "The reload failed. Switching back."
ln -sfn releases/2026-11-20 current.new
mv -T current.new current
nvs reload
exit 1 ;;
2) echo "No server is running. The server uses the new release when it starts." ;;
esac

Run a database change with nvs run, before you switch the link. nvs run starts a new process and compiles the program from the disk, so it needs no reload:

Terminal window
nvs run /srv/shop/releases/2026-11-21/bin/migrate.nvs

Requests that started before the switch finish on the old code. So for a short time, both versions run. Write each database change so that the old code still works with it. The new code must also read what the old code wrote, such as sessions, cache entries and queued jobs.

  • A configuration file is read again on every reload, also through a link. A key that needs a restart, such as [server] listen, is written to the log and takes effect at the next start.
  • Static files still come from the release that the server started with.
  • A [[server.mount]] table reads the links of its mounts when the server starts. With a mount table, a switched link takes effect at the next start.

While you develop, and with a coding agent

Section titled “While you develop, and with a coding agent”

The server compiles a changed program when its files stay unchanged for [opcache] settle. A person or a coding agent can pause between two edits for longer than that. The server then compiles a program that is only half edited, and logs errors that you did not make.

To stop this, set a long revalidate_freq, so that the server checks its files only once an hour. Then run nvs reload after each batch of edits:

[opcache]
revalidate_freq = "1h"

nvs reload prints each error with its file and line, so you or the agent can fix it at once. A reload that you forget still takes effect within one hour. nvs agent primer tells a coding agent to run nvs reload after its edits.

In development, the server also keeps the result of checking each file for errors in memory. A reload after an edit inside one function then checks one file and compiles one function, at any program size. The setting is [opcache] incremental. Its default is true in development and false in production, where the server frees this memory after each compile:

[opcache]
incremental = true

Read every option in Reference: nvs reload.