Articles

Stop every jail cleanly when the host shuts down

jailops stop-all and the jailops_shutdown service stop the jails in the order of their dependencies before the host shuts down, so a database flushes. Boot order, the grace each jail gets and the settings in rc.conf.

Why order matters

A web jail needs its database, and the database needs time.

When a host shuts down, a database should flush its files before the disk goes away, and a web application should stop before the database it talks to. JailOps does both: the jails stop one after the other, the ones that depend on others first, and start again in the opposite order.

Starting in order

Autostart, priority and dependencies.

A jail starts when the host boots only if it has autostart. The order comes from boot.depends (a jail starts after the jails it names) and boot.priority (among jails that are ready, the lower number starts first).

on the host
$ jailops create db  --image freebsd-15-1 --network lan --storage default --autostart --start
$ jailops create web --image freebsd-15-1 --network lan --storage default --autostart --depends db --start
$ jailops boot

jailops boot prints the plan: the jails in the order they start, with the reason, and the jails with autostart that it will not start, with why. It changes nothing.

Stopping in order

The reverse, automatically.

The package installs the service jailops_shutdown. At shutdown it runs jailops stop-all: every running jail of every project, a jail before the jails it depends on, so the web jail stops before its database. A jail that cannot be stopped is reported and the others are stopped anyway.

by hand, for a maintenance window
$ jailops stop-all --dry-run      # the order, nothing stopped
$ jailops stop-all --grace 60s    # how long each jail gets

A jail has ten seconds to shut down by itself before it is killed. A database that needs longer sets its own time, with --stop-timeout 60 when the jail is made or jailops config set db boot.stop_timeout 60 later; it takes effect at the next start. Raise jailops_shutdown_timeout as well, so the host waits for the jails together.

Restarting the daemon never stops a jail.

The settings

Three lines in rc.conf.

  • jailops_shutdown_enable: on whenever jailopsd_enable is YES. NO leaves the jails to the system.
  • jailops_shutdown_timeout: the seconds for all the jails together, 80 by default. It has to stay below rcshutdown_timeout (90 by default), so raise both for a host with slow databases.
  • jailops_shutdown_grace: the time each jail gets to shut down, for example 30s.

More articles

Try it on one server.

Try the console from the screenshots, install on a clean FreeBSD 15.1 machine, or add JailOps to a host you already run.