writingmaclulich.com

Make JAR deploys over SSH safe with an AI operator, without replatforming

Five changes that make an SSH and JAR deploy safe without replatforming it

  1. Wrap the deploy you have instead of replacing itMine was 17 hosts over SSH. Kubernetes would have shifted the work onto the people building the product.
  2. Give the agent typed actions, never a shellMy first version took a host and any command string. Now hosts, services and version tags are validated and quoted at the boundary.
  3. Gate every host, and stop when a check can’t runThe gates repeat between all 17 hosts. A database error means the check never ran, so --force can’t override it.
  4. Deploy one host, prove it, then the nextA campaign host takes roughly 133 seconds, most of it a deliberate drain, and one live message shows all 17 hosts.
  5. Roll back the JAR, never the databaseA down migration can drop data, so the database stays forward-migrated and a human decides when the old app may not work with the new schema.
The numbers are from Audience Republic’s production deploy: 17 long-lived hosts, SSH and JARs.

The deployment was simple, but operating it was not

If you still deploy to long-lived servers over SSH and want each release safer without a new platform, this is for you. It starts with the system Audience Republic already had: 17 long-lived production hosts, with no Terraform plan or disposable infrastructure between us and them.

I made that old-school Java deployment reasonable by putting an AI operator on top of it. We connected over SSH, applied PostgreSQL migrations, pulled JARs from S3, changed symlinks, restarted systemd services and watched the result.

Rather than asking the AI to pretend this was a modern platform, I taught it how the platform actually worked, including the parts that could hurt us. The basic operation was still one command:

ssh "$host" "~/bin/deploy.sh 16.4"

On each host, that one command ran the same six steps

  1. PullThe production branch
  2. Stop consumingFrom RabbitMQ
  3. WaitTwo minutes for in-flight work
  4. DownloadThe selected JAR from S3
  5. SwitchThe service symlink
  6. RestartThe service with systemd

None of that is fashionable, but it is wonderfully legible. You can SSH to a box, inspect the symlink, ask systemd whether the service is active and curl its health endpoint without passing through seven control planes on the way to the process.

Old deployment systems are awkward to talk about because the expected ending is a replatforming. Mention SSH and someone will ask why it is not Kubernetes. Mention JARs and the proposed fix quickly becomes a new delivery platform, even when the immediate problem is the risk around each release.

That was not the useful move here because the mechanics were simple and well understood. The expensive part was the operational judgement wrapped around them, and rebuilding all of it would have been a large project, while making the next deployment safer was a problem we had today.

Wrap the deploy you have instead of replacing it

Kubernetes would have shifted the work, not removed it. I knew from experience what the alternative cost. With a small team, managing a Kubernetes cluster is not an abstraction you buy once, because it quickly becomes another production system in its own right.

Kubernetes solves real problems, but the risk here was not in the mechanics

  1. Where our risk wasOur deployment mechanics were obvious. The risk sat in their sequence and the operational memory around them.
  2. What Kubernetes would addCluster upgrades, node pools, networking, ingress, secrets, access control, logging, metrics, storage and the new failure modes introduced by all of it.
  3. Who would own itThe same people who are meant to be building the product.

An AI safety layer addressed that risk without giving the team another platform to babysit. Before you replatform, check whether your risk is in the mechanics or in the sequence and memory around them.

Give the agent typed actions, never a shell

One early version exposed a general remote-command method that accepted a host and an arbitrary command string. That is convenient until a version tag becomes part of the command and the remote shell interprets it.

# Too much authority in one interface
transport.run_command(host, command)

The replacement exposed typed actions instead, validating hosts, services and version tags at the boundary, quoting remote values and running local subprocesses without a shell.

runner.run_deploy_script(
    host=host,
    version_tag=version,
)

That boundary matters more when an AI is driving, because the model can choose a deployment action but it cannot invent a new remote shell action that the interface does not provide. So give your own agent the list of actions you are willing to run, and no shell.

Gate every host, and stop on a missing check

A production restart could interrupt a CSV import or an outbound message send by removing the JVM while work was in flight. A message that reached RabbitMQ’s dead-letter queue could be replayed manually, but often it simply disappeared with no delivery callback and no automatic retry.

So the deployment agent checks database health and counts active imports and sends before a rollout. It repeats those gates between hosts, because production state can change while a 17-host deployment is running.

The gate code preserves an important distinction between blocked and broken:

if error_results:
    can_deploy = False
elif blocked_results and not force:
    can_deploy = False

A blocked deploy can be forced, a check that never ran can’t

  1. BlockedA known condition, such as an active import. An operator can investigate it, and --force can override it.
  2. BrokenA database connection error means the safety check never ran, so --force cannot turn missing evidence into a safe deployment.
  3. Message sendersThe SMS and email senders are stricter again. They deploy alone, never bypass an active send, and must prove they have reattached to RabbitMQ before the next host starts.

A gate that can’t run is not a pass. Treat a missing check as a stop, and keep the override for conditions a person has looked at.

Deploy one host, prove it, then the next

The deployment tool had no production --single-host flag. The canary mechanism was more direct: temporarily narrow the YAML inventory to one host.

production:
  campaign:
    - worker-1  # canary

The agent deploys that host, waits for the result and verifies it before restoring a larger wave. Customer-facing hosts, HA pairs and the message senders still move one at a time.

A campaign host takes roughly 133 seconds, most of it a deliberate 120-second drain

≈133 s
for one campaign host to deploy
120 s
given to in-flight messages to drain before the JVM restarts
The remote script stops queue consumption first, then restarts the JVM.

A completed command on its own was never enough. After the restart, the next host does not become eligible until this evidence is present.

The next host waits for evidence, not for the command to finish

  1. JAR symlinkPoints at the expected commit
  2. systemdReports the service as active
  3. Health endpoint/system/status returns {"ok":true}
  4. File logThe application’s log has no new errors
  5. ConsumersOn queue workers, they are back

The rollout gets one live message

The agent also needed a readable operational surface, so it kept one rolling message in the deployment channel and edited that message as the fleet changed.

A reconstructed deployment channel showing completed, active and waiting hosts with deployment times and a 17-host progress bar
A public-safe reconstruction of the live rollout message. Each host moved from waiting, to deploying, to verified without creating a new message for every step.

Every host had a line, and completed hosts gained a Sydney timestamp. The current host had a spinner that changed every 15 seconds, which mattered when one restart sat there for more than two minutes. Canary, HA, load-balanced and message-sender hosts carried their own annotations.

The progress bar was only 20 characters wide, but it showed enough to tell what had deployed, what was moving and what had not been touched. That small interface changed the character of the system: although the deployment was still SSH and JARs underneath, it now behaved like an observable rollout rather than a sequence of private terminal commands.

If your rollouts happen in terminals nobody else sees, do the same: keep one message in the deployment channel and edit it as each host changes.

Roll back the JAR, never the database

Rolling a JAR back is straightforward once the operator chooses the exact previous version. The agent deploys it through the same one-host sequence and verifies the symlink and health checks again.

Rolling a database backwards carries a different class of risk, because a down migration can drop data, change constraints or leave stored procedures in a state the old application does not understand.

The JAR goes back, the database stays forward, and incompatible changes go to a human

  1. The JAR rolls backThrough the same gates, canaries and per-host verification, because urgency does not change what the system needs to prove.
  2. The database stays forward-migratedThe agent checks whether the older application is compatible with the newer schema. Additive changes are normally fine.
  3. A human decides the restA dropped column, a new required field or a changed stored procedure puts the decision back in front of a person.

So roll back JARs only, leave the schema where it is, and have a person confirm the exact previous version.

How far to trust it

Sylvain Kalache recently wrote about AI incident tools creating comprehension debt. When software handles every routine incident, engineers lose the repetitions that taught them how their systems behave. They return only for the rare failure the AI could not solve.

I think that risk is real, and this agent only helps if it keeps its reasoning visible. The operator still chooses the rollout shape and confirms an exact rollback target.

The agent’s reasoning stays visible, but explanation is not practice

  1. What it has to showWhy a gate blocked, which host is active, what evidence passed and where the rollout will stop.
  2. Reading is not diagnosingReading that a message sender must drain does not create the same understanding as diagnosing one that failed to resume. I have not solved that part yet.
  3. Rehearsal is the next layerA simulation mode that injects a blocked gate, an unhealthy canary or an incompatible rollback and makes the human respond without touching production.

The agent can preserve the incident memory, but we still need to exercise our own.

What to copy

Here are the checks above as one list you can hand to your own deploy agent.

Before every host
- Check database health and count active imports and sends.
- If a check errors, stop. Do not use --force, because the check never ran.
- If a known condition blocks the deploy, an operator investigates first.
- Message senders deploy alone, never bypass an active send, and must be
  reattached to RabbitMQ before the next host starts.

Deploy
- Start with one canary host.
- Let in-flight work drain before the restart (mine waits 120 seconds).

Verify before the next host
- The JAR symlink points at the expected commit.
- systemd reports the service as active.
- /system/status returns {"ok":true}.
- The application's file log shows no new errors.
- On queue workers, consumers are back.

Rollback
- Roll back JARs only, through the same one-host sequence.
- Leave the database forward-migrated.
- Ask a human before rolling back past a dropped column, a new required
  field or a changed stored procedure.

How it works

The agent did not replace the deployment. It made explicit a sequence that had previously lived across scripts, documentation, production incidents and the operator’s memory.

  1. 01Migrateschema first
  2. 02Gateproduction clear
  3. 03Canaryone host
  4. 04Verifyhealth + logs
  5. 05Expandone wave
  6. 06Report17 hosts
The mechanics stayed simple while the agent made the order explicit and refused to skip the proof between stages.

What changed was the way we operated it. We kept a deployment architecture that everybody could inspect rather than adding Terraform or moving the fleet to Kubernetes, then put a more disciplined operator over it.

That is the retro appeal for me: the machinery remains boring and direct, while the AI adds the memory, refusal and visibility that made operating it reasonable.

You do not have to replace a system before AI can improve it, but you do have to teach the AI how the existing system really works and exactly when it should stop.