The life of a jail
What happens to a JailOps jail from create to delete, why a running jail does not come back after a reboot unless you said so with --autostart, how the boot order is decided and shown, and why the host keeps what you declared and nothing else.
The states
What jailops list shows.
A jail is stopped, starting, running, stopping or in error. A stopped jail whose encrypted volumes wait for their passphrase is locked. You move a jail between the first ones with jailops start, stop and restart, and jailops create --start makes one and starts it in one step.
$ jailops list -c name,state,autostartThe list is the jails of the project you work in. jailops info JAIL says more about one of them.
Declared, not remembered
Why a running jail does not come back by itself.
It is natural to expect that a jail that was running when the host went down is running when the host is back. JailOps does not do that, on purpose.
- Running is an event, not a declaration. A jail was running because someone started it, maybe an hour ago to try something. A reboot that brings back whatever happened to be running would also bring back the experiment, the half-finished migration and the jail somebody stopped to keep it quiet.
- What you declared is what you can read. The jail's specification says whether it starts at boot. Anyone who reviews a host reads
boot.autostartand knows what will be there after a reboot, without asking what was running at the time. - It is the same after a crash and after a planned reboot. The result does not depend on how the host went down.
So you say it once, when you create the jail, and it stays true. A jail that jailops app install makes already has it: installing a service is the declaration that it should run, so an app comes back after every boot.
Autostart
Say it when you create the jail.
Most jails you want back after every boot. Put it in the command that creates them:
$ jailops create web --image freebsd-15-1 --network lan --storage default --start --autostart--start starts it now and --autostart starts it every time the host boots. A jail without --autostart stays stopped after a reboot, also when it was running before. For a jail that exists:
$ jailops config set web boot.autostart trueThe host side is jailopsd_enable="YES" in rc.conf: the daemon starts at boot and its first pass starts the jails that declared boot.autostart.
The boot order
Dependencies first, then priority, then the name.
Most hosts need no order. When a jail needs another to be running first, say so: boot.depends names the jails that must start before it, and a dependency that is not running is started first, even if it has no autostart of its own. Among the jails that are ready, a lower boot.priority starts first, then the name. A cycle or a dependency that does not exist leaves the jails involved out, and says so; nothing is guessed around.
You do not have to work the order out in your head. jailops boot prints it the way the daemon will compute it, for the whole host, and lists the jails that will not start with the reason:
$ jailops bootRead it before a planned reboot, and again after you change a dependency.
Encrypted jails after a boot
They wait for you, on purpose.
After every boot of the host the keys of encrypted volumes are not loaded. The jail is locked, and the boot skips it and remembers that it was due. jailops volume unlock NAME asks for the passphrase of the volume and, for a jail that had autostart, starts it right after. A jail that depends on a locked jail does not start at boot either; start it after the unlock. The reason shows in jailops boot.
This is the one place where the host waits for a person instead of acting alone, and it is the same rule as everywhere else: nothing starts that you did not declare, and nothing is decrypted that you did not unlock.
Changing a jail without losing it
Snapshots, rollback, upgrade.
The rest of the lifecycle follows the same habit: you ask, the host does exactly that, and what it did is recorded.
jailops jail snapshot create JAILtakes a consistent ZFS snapshot across all datasets of a jail; it costs almost nothing until data changes.jailops jail rollback JAILreturns the root, the data or both to a snapshot, and shows how much it discards before it asks you to type the name.jailops jail upgrade JAILmoves a jail to a newer generation of its image, keeps the application data and merges/etc;--dry-runshows the move first. How the generations come about is in jail updates without cron.
More articles
Jail updates without cron
Replace the nightly script that upgrades every jail: automatic jail upgrades per image, with a health check, a rollback and a record of every run, what they leave alone, and how a new FreeBSD release comes in.
Read the article: Jail updates without cronJail search and shell
Ctrl+K, a few letters, Shift+Enter: find a jail by name, label or app and open its shell. Labels that filter the jail list, bash in new jails, and the jailops command next to every step.
Read the article: Jail search and shellGetting started with the JailOps CLI
Root on the host, the command line and nothing else: install JailOps, build an image, create a network and a jail, reach it by name, snapshot it, open a port and install an app.
Read the article: Getting started with the JailOps CLIJailOps on a netcup server, with IPv6 that stays up
A /64, a router pair and a FreeBSD default that drops their probes. How every jail gets its own IPv6 address on netcup, and the one sysctl that ends the random unreachable alerts.
Read the article: JailOps on a netcup server, with IPv6 that stays upOne small cloud server, many services, solid IPv6
Run your database, web tier and workers on one low-cost server, each jail with its own IPv6 address, and fix the alerts a shared /64 causes with one sysctl.
Read the article: One small cloud server, many services, solid IPv6Write your own app: memcached, from package to catalog
Turn a small FreeBSD package into a JailOps app: the definition line by line, the offline check, a local install, the five traps, and the pull request that puts it in the catalog.
Read the article: Write your own app: memcached, from package to catalogFrom catalog to running service in one command
Install nginx from the app catalog with one command, see each of its steps, and find the data, the configuration, the logs and the snapshot afterwards.
Read the article: From catalog to running service in one commandA firewall you can read
Policies, address sets and jails by name (jail:web), each with a comment, so the firewall can be reviewed by someone who did not write it.
Read the article: A firewall you can readPostgreSQL and git, closed except for who needs them
Close a database and a git server, then let in exactly the web jail and the office, with a comment on every entry.
Read the article: PostgreSQL and git, closed except for who needs themProjects are boundaries
A project is a boundary. Another project is an external host, so only addresses cross it, written out on both sides. Why that is simpler to review, and what a project does not isolate.
Read the article: Projects are boundariesTab completion for jailops
Press Tab and get the names of your jails, networks and firewall policies, even on another host. How to install and turn on completion in bash, zsh and fish.
Read the article: Tab completion for jailopsTest the firewall before you trust it
Ask the firewall whether a connection would pass, and why, before you try it. Read the answer, put it in a script, and know what it cannot tell you.
Read the article: Test the firewall before you trust itSee a connection before it happens
Pick a From and a To, a protocol and a port, press Run, and see the connection flow through the firewall: what passes, what stops it, and which rule decides.
Read the article: See a connection before it happensLimit what a jail can use
Give a jail a ceiling for memory, processes, CPU, disk, firewall states and bandwidth, one command each, and know what happens when it reaches it.
Read the article: Limit what a jail can useStop every jail cleanly when the host shuts down
A host that reboots should stop its databases before it stops the disks. How JailOps stops the jails in order, and how to start them in order again.
Read the article: Stop every jail cleanly when the host shuts downOne line in pf.conf
The host's firewall stays yours. JailOps asks for one line, and everything for the jails lives below it.
Read the article: One line in pf.confWhat the host tells you by itself
A pool that reports an error, an uplink that goes down, a jail that reaches a limit: they show up in the event stream by themselves.
Read the article: What the host tells you by itselfNetworks the host controls
No bridge, no DHCP. The host hands out the addresses, gives each jail a link of its own and is the router, so jails cannot see or impersonate each other.
Read the article: Networks the host controlsVolumes: data that outlives a jail
Keep the data in a volume and the jail disposable. One volume can be attached to several jails, has its own snapshots and its own backup.
Read the article: Volumes: data that outlives a jailBack up volumes once
One copy of a volume, however many jails use it. Leave volumes out when you want to, bring them back with the jail.
Read the article: Back up volumes onceA private Docker registry
A registry of your own with users in a file: one jail, docker-registry and docker-auth, htpasswd for the passwords, the images on a volume.
Read the article: A private Docker registryNames for jails
A jail is reached by its name inside its project: db.shop.internal, or just db. Create a jail and its name is there; delete it and the name is gone.
Read the article: Names for jails
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.