A Reboot Is Still a Deployment
Stack Overflow Blog

A Reboot Is Still a Deployment

Most teams I've worked with won't call a deployment finished until the new version has done some real work, such as serving a request or processing a job, and produced the result they expected. A host reboot rarely gets that treatment.

The application code hasn't changed, so the restart goes on the maintenance calendar as housekeeping, and the check afterwards is whether the service came back up. I think that bar is too low.

What would actually prove that an unchanged service recovered after its host restarted? My answer is a completed job: one piece of the work the service exists to do, finished on the returning host, against the data it's meant to use, and recorded somewhere I can read.

A service runs on more than its code

A service runs on a lot more than its code. In a recent Heap article, Guilherme Appel showed how a .NET parallel loop can become serial in a one-CPU container. Lowering the container's limit from two CPUs to one took his 200 records from 42.1 seconds to 83.6, and nobody touched the code.

A reboot can change a good deal more than a CPU limit. It can bring back a different kernel, remount the volumes and restart everything on that host the service talks to, in an order its last deployment never tested.

Canonical has changed how often Ubuntu hosts get a new kernel to boot into. On September 23, it announced a new kernel release strategy that replaces its four-week regular and two-week security update cycles with overlapping two-week cycles, so a new kernel ships every week.

A new kernel only runs after a reboot, so every one a team installs brings another restart to plan. The Register's report on the new schedule explains that each cycle spends its second week on hardware certification and regression testing. Organizations unwilling to wait, the report adds, can take release candidates after the first week and run their own acceptance tests.

That's a sensible offer for the kernel. The acceptance test I'd worry about is the one for the application running on it.

Livepatch moves some of those restarts around without removing them. Canonical describes Livepatch as patching critical and high-severity kernel vulnerabilities "while the system runs." It covers only particular combinations of release, kernel version and flavor, though, and Canonical produces patches for a given kernel for 9 to 13 months after its release, depending on the kernel. After that, its advice is to update and restart. So the restarts still come, on a different schedule.

Decide who owns the unfinished job before shutdown

Picture a team that runs a queue-backed export service on two Linux hosts. Each host runs one worker. A worker takes an export request off the shared queue, writes the finished file to a volume mounted on its host and marks the job done. In this example a job counts as complete only when both of those have happened.

In the proposed maintenance window, the host running worker A gets a kernel update and a reboot while worker B stays up on the other host. The service's code stays exactly as it was.

I didn't reboot a server to write this. To see which records an operator would actually have during that window, I built a small rehearsal on a single machine. It runs two worker processes in Python, A and B, which share a SQLite database playing the part of the queue, and the queue holds two jobs, J-001 and J-002. There are no export files in it, only queue rows, and each worker process carries a tag for its run, so A starts out tagged "before."

The harness drives the workers by command. An enable command runs a worker's claim gate, the check that decides whether it may take work at all, and a claim command names the job it should try to take.

What the rehearsal shows is the order in which the queue records change. A claimed J-001 first. Then I drained A, which in this harness means one thing: it stops claiming new jobs. When I asked A for J-002, it answered "claims disabled." J-001 was still A's, so before I stopped the process, A put the job back, and the database showed J-001 as queued with no owner.

That requeue is a decision, and I'd want it written into the plan before anyone stops a worker. My harness hands the job back explicitly. A real queue might:

  • let the worker finish first,
  • checkpoint partway, or
  • wait for a lease to expire and reassign the job.

Each of those changes when J-001 runs next, and whether it starts again from the beginning.

While A was gone, I asked B for J-002, and B claimed it and finished it. I only offered B that one job. Left to itself, a queue would probably have handed B the returned J-001 as well, which is the reason for handing a job back at all.

In this run the second worker kept the queue moving, and that's all it shows. Whether one host can carry the whole load is a capacity question, and this rehearsal doesn't touch it.

What worker A showed when it came back

A came back tagged "after," standing in for the rebooted host. Its first line said the process was up. A health check that only looked for a running process would have passed at that point.

When I sent A its enable command, the claim gate looked for a marker file on its volume and read it to confirm the volume was the one it expected. Before the relaunch I had moved the marker away, which is how the rehearsal simulates a volume that didn't come back. The gate reported "dependency unavailable," and a request for J-001 got the same "claims disabled" that J-002 had met during the drain.

I put the marker back and enabled A again. This time the gate opened, and A claimed J-001 and marked it done, with the database recording A as the worker that finished it. In the whole sequence, that row is the first record saying the returned worker did its job.

None of the harness output is a discovery. I wrote the gate, and the harness did what its code says it should. What the rehearsal makes visible is that three records can disagree after a restart: the process said it was up, the gate said its dependency was missing, and no job had finished.

The rehearsal is deliberately a narrow check, aiming for the kind of targeted accuracy on one behavior that Sancharini Panda argues a sandbox should have, and it exercised no mount, bootloader or kernel.

On a Linux host, systemd can bring the first two of those records closer together. A unit can list the paths it needs in RequiresMountsFor=, which adds Requires= and After= dependencies on the mount units needed to reach those paths. With a mount unit for the volume, the worker waits for the mount.

A service declared as Type=notify stays in the "starting" state until it sends READY=1, which means the worker decides when its startup is done. The usual default, Type=simple, treats the service as started as soon as its process is forked. For that type, the systemd manual warns, systemctl start will report success "even if the service's binary cannot be invoked successfully."

Even with both settings in place, systemd knows two things: something is mounted at the path, and the worker said it was ready. That second fact is only as good as the worker's own check. In my harness the check is the marker file, and on a real host it should confirm that the mounted volume is the one holding this worker's exports.

Neither fact shows that the worker can take a job and record it as finished. That's an application question, and I'd answer it with one representative job.

Rolling back the kernel won't roll back the queue

The obvious shortcut, if the new kernel misbehaves, is to boot the previous one and call that a rollback. I simulated the process-level version. After A finished J-001, I stopped it and relaunched it with the same code and its original tag, "before." The queue still showed J-001 done by A and J-002 done by B.

Each claim and completion in my harness ran as its own committed transaction, and relaunching a process doesn't touch committed rows. Any store with durable commits would behave the same way. SQLite's documentation on atomic commit describes a committed transaction as all or nothing, even across "an operating system crash or power failure."

On the real host, the boot environment and the work are just as separate, and that's where I'd expect a rollback plan to be misread. Booting the previous kernel brings back that kernel. It doesn't bring back packages upgraded in the same window, and it can't reach the queue, the exports already on the volume or anything the worker has sent to another system.

If the recovery plan replays jobs after a rollback, and the application has no way to recognize one it already finished, that job can run twice and leave a second copy of the same export.

Who decides when A takes work again

Somebody has to read the J-001 row and decide what happens next, and in more than one incident I've watched, the trouble started when two people each assumed the other one had.

Say Dana runs the hosts. She owns the reboot, and afterwards she reports that the host booted and whether the worker's mounts and other dependencies came back. Marcus owns the export service. He sends A one known job while it's still out of normal intake, the way my harness names the job a worker should claim. Then he reads the result and decides when A goes back to ordinary work.

Where that line falls depends on how much of the stack the team controls. If you choose the OS for a bare-metal server yourself, the reboot is yours as well. Atlantic.Net's bare-metal page, for one, says those customers are configured as the system administrator with full root access.

Whatever the hosting arrangement, checking that the export service did its job afterwards falls to whoever owns the service, so I'd agree on Dana's half and Marcus's half before the window opens.

Keep the worker out until you can see the result

The condition I'd write into the maintenance plan, before the first worker stops, is that the returning worker completes one representative job against its intended dependency and leaves a result someone other than the worker can check. For the export service, that means a file on the right volume and a queue row naming the worker that finished it.

A process that's up, a unit that's active and a mount that's present are all worth seeing on the way there, but none of them is that result. If the evidence isn't there, A stays out of normal intake, and B keeps the queue moving while Marcus finds out why.

Holding A back costs some capacity for as long as that takes. Readmitting a worker that can't do its job costs whatever it touches before anyone notices.

My rehearsal only had the second half of that evidence: one row in a SQLite file, J-001, done, finished by A after its marker file was restored. A real host needs the export file too. With both in hand, that's a reboot I'd sign off on.

Read on Stack Overflow Blog ↗ ← Back to News

Comments

No comments yet. Start the discussion.