---
id: "wrap-a-cli-command"
type: "guide"
title: "Wrap a CLI command"
summary: "Run an existing CLI command as a supervised recurring job using ctx.exec, without rewriting its logic."
why: "The command already works — Servix only adds the schedule, supervision, and logging around it."
audiences: ["developers"]
prerequisites: ["service-shell"]
related: ["wrap-a-function"]
---
# Wrap a CLI command

1. Start from the command you already run by hand:

```bash
mongo-backup --source X --target Y
```

2. Wrap it with `ctx.exec` in a proactive worker:

```ts
import { defineServixService } from "@x12i/servix";

export default defineServixService({
  name: "mongo-backup",
  workers: [
    {
      id: "hourly-backup",
      type: "proactive",
      schedule: { mode: "interval", everyMs: 60 * 60 * 1000 },
      async execute(ctx) {
        await ctx.exec("mongo-backup", [
          "--source",
          String(ctx.config.source),
          "--target",
          String(ctx.config.target)
        ]);
      }
    }
  ]
});
```

3. Configure the values the command needs:

```bash
servix config set mongo-backup source=X target=Y
servix start mongo-backup
```

Servix does not care whether the real work is internal TypeScript or an external command.