﻿`runwisp import supervisord` converts a supervisord config into `runwisp.toml`.
Each `[program]` becomes a RunWisp [service](/configuration/services/).

## Convert the config

```bash
runwisp import supervisord /etc/supervisor/supervisord.conf -o runwisp.toml
runwisp validate
```

Pass the file path rather than piping it in. With a path, `[include]` files are
found and merged; piped input has no location to resolve them from.

Given:

```ini
[program:web]
command=/usr/bin/gunicorn app:app
directory=/srv/app
user=www-data
startsecs=10
startretries=5
stopsignal=INT
environment=DJANGO_SETTINGS="prod",LOG_LEVEL=info
stdout_logfile=/var/log/web.log

[program:worker]
command=/srv/app/worker --idx %(process_num)s
numprocs=4
```

you get:

```toml title="runwisp.toml"
[services.web]
run = "/usr/bin/gunicorn app:app"
working_dir = "/srv/app"
user = "www-data"
healthy_after = "10s"
restart_attempts = 5
stop_signal = "SIGINT"

[services.web.env]
DJANGO_SETTINGS = "prod"
LOG_LEVEL = "info"

[services.worker]
run = "/srv/app/worker --idx %(process_num)s"
instances = 4
```

A summary on stderr has one row per program, marked `✓` (mapped), `~`
(changed, with the reason), `!` (needs a fix), or `-` (already in your config).
Here, `web` is `~` because its log file setting was dropped, and `worker` is `!`
because `%(process_num)s` isn't filled in.

If you already have a `runwisp.toml`, use `--write` instead of `-o`; see
[Staging and promoting](/coming-from/cron/#staging-and-promoting). All flags are
in the [CLI reference](/reference/cli/#runwisp-import).

## Stop the programs in supervisord

The import doesn't stop supervisord or edit its config. If both run the same
program, you get two copies fighting over ports or queues. Stop them first:

```bash
sudo supervisorctl stop web worker     # the programs you imported
```

Then remove them from supervisord's config, so a reload or reboot doesn't
start them again:

```bash
sudo cp /etc/supervisor/supervisord.conf ~/supervisord.conf.backup
sudo $EDITOR /etc/supervisor/supervisord.conf   # or the conf.d/ file
sudo supervisorctl reread && sudo supervisorctl update
```

When nothing is left, `sudo systemctl disable --now supervisor` stops
supervisord itself. You can move a few programs at a time, but never leave
one enabled in both.

## How the pieces map

| supervisord                     | runwisp.toml                                                      | Notes                                        |
| ------------------------------- | ----------------------------------------------------------------- | -------------------------------------------- |
| `[program:web]`                 | `[services.web]`                                                  |                                              |
| `command`                       | [`run`](/configuration/services/#run)                             | `%(program_name)s` is filled in.             |
| `directory`                     | [`working_dir`](/configuration/services/#working_dir)             |                                              |
| `user`                          | [`user`](/configuration/services/#user)                           | The daemon must run as root to switch users. |
| `umask`                         | [`umask`](/configuration/services/#umask)                         |                                              |
| `numprocs`                      | [`instances`](/configuration/services/#instances)                 | Each gets `RUNWISP_INSTANCE_INDEX` (from 0). |
| `startsecs`                     | [`healthy_after`](/configuration/services/#healthy_after)         |                                              |
| `startretries`                  | [`restart_attempts`](/configuration/services/#restart_attempts)   |                                              |
| `stopsignal`                    | [`stop_signal`](/configuration/services/#stop_signal)             | `INT` becomes `SIGINT`.                      |
| `stopwaitsecs`                  | [`graceful_stop`](/configuration/services/#graceful_stop)         |                                              |
| `priority`                      | [`priority`](/configuration/services/#priority)                   |                                              |
| `autostart`                     | [`autostart`](/configuration/services/#autostart)                 |                                              |
| `environment`                   | [`env`](/configuration/services/#env)                             |                                              |
| `autorestart`                   | [`restart`](/configuration/services/#restart)                     | `false` becomes a task. See below.           |
| `exitcodes`                     | _(dropped)_                                                       | See below.                                   |
| `stdout_logfile` and similar    | _(dropped)_                                                       | RunWisp captures output for every run.       |
| `[group:site] programs=web,…`   | [`group = "site"`](/configuration/services/#group) on each member |                                              |
| `[include] files=conf.d/*.conf` | _(followed and merged)_                                           | Relative to the config file.                 |

## What needs a human

Anything that can't be mapped gets a `# TODO` in the TOML and a note on the
program's row. Unknown keys are dropped and listed by name.

- **`autorestart`.** `autorestart=true` becomes a service with RunWisp's
  default [`restart`](/configuration/services/#restart), which restarts after
  any exit. `unexpected` (supervisord's default) becomes
  `restart = "on_failure"`; RunWisp counts any non-zero exit as a failure, where
  supervisord goes by `exitcodes`. `false`, `no`, `off`, and `0` mean the
  program runs once, so it becomes a task with
  [`run_on_start = true`](/configuration/tasks/#run_on_start). Like under
  supervisord, it runs again whenever the daemon starts.
- **`exitcodes`.** RunWisp treats exit `0` as success and anything else as
  `failed`. If your program exits non-zero on purpose, end its [`run`](/configuration/tasks/#run) with
  `|| true`. [`failures`](/configuration/tasks/#failures) controls which
  outcomes count for alerts.
- **`%(...)s` expansions.** Only `%(program_name)s` is filled in. For
  `%(process_num)s`, use `$RUNWISP_INSTANCE_INDEX` in the command. Others, like
  `%(ENV_x)s`, need a manual edit.
- **Log files.** Dropped. To control log size and retention, see
  [Logs](/concepts/logs/).
- **supervisord's own sections** (`[supervisord]`, `[supervisorctl]`,
  `[unix_http_server]`, `[inet_http_server]`, `[rpcinterface]`) are skipped with
  a note. RunWisp's own settings are in [`[daemon]`](/configuration/daemon/).
- **`[eventlistener]` and `[fcgi-program]`** are not supported. They get a `!`
  row so you know to replace them another way.

## Learn more

- [`[services.*]`](/configuration/services/)
- [Tasks vs services](/concepts/tasks-vs-services/)
- [From cron](/coming-from/cron/), for scheduled jobs
