> ## Documentation Index
> Fetch the complete documentation index at: https://comis-fix-skill-import-vetting-gate.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# PM2

> Run Comis with PM2 on macOS, WSL, or Linux without systemd

PM2 is an optional process supervisor that keeps the Comis daemon running in
the background and provides restart, status, and log commands. The managed Linux
installer uses systemd by default; PM2 is useful on macOS, WSL, or Linux systems
where systemd is unavailable.

## Prerequisites

* Node.js 22.19.0 or newer
* Comis installed and initialized
* PM2 available on `PATH`:

```bash theme={}
npm install --global pm2
```

<Note>
  When working from a source checkout, run `pnpm build` before PM2 setup. Published
  Comis packages already include the built daemon.
</Note>

## Set up and start

<Steps>
  <Step title="Generate the process definition">
    ```bash theme={}
    comis pm2 setup
    ```

    This writes `~/.comis/ecosystem.config.js` with the installed daemon path,
    the active `COMIS_CONFIG_PATHS` value, a 512 MiB Node.js heap limit, and the
    restart policy.
  </Step>

  <Step title="Start the daemon">
    ```bash theme={}
    comis pm2 start
    ```
  </Step>

  <Step title="Verify status and logs">
    ```bash theme={}
    comis pm2 status
    comis pm2 logs --lines 50
    ```
  </Step>
</Steps>

## Commands

| Command                     | Purpose                                                           |
| --------------------------- | ----------------------------------------------------------------- |
| `comis pm2 setup`           | Generate `~/.comis/ecosystem.config.js`                           |
| `comis pm2 start`           | Start Comis from the generated definition                         |
| `comis pm2 stop`            | Stop the managed process                                          |
| `comis pm2 restart`         | Restart the managed process                                       |
| `comis pm2 status`          | Show PM2's process details; exits nonzero if Comis is not managed |
| `comis pm2 logs --lines 50` | Stream recent daemon output                                       |

After upgrading or rebuilding Comis, run `comis pm2 setup` again if the installed
daemon path changed, then run `comis pm2 restart`.

## Start at boot

To have PM2 restore Comis after reboot, run:

```bash theme={}
comis pm2 setup --enable-boot
```

PM2 may request `sudo` to register with launchd or systemd. If automatic
registration cannot complete, the command prints the manual PM2 step to run.

## Generated configuration

The generated file is owned by the current user and written with mode `0600`.
Its shape is:

```javascript theme={}
module.exports = {
  apps: [{
    name: "comis",
    script: "/absolute/path/to/packages/daemon/dist/daemon.js",
    node_args: ["--max-old-space-size=512"],
    env: {
      COMIS_CONFIG_PATHS: "/home/user/.comis/config.yaml",
    },
    restart_delay: 2000,
    kill_timeout: 10000,
    max_restarts: 10,
    autorestart: true,
  }],
};
```

Do not rely on a separately exported `COMIS_CONFIG_PATHS`; the generated PM2
definition carries the value into the background process.

## Logs

`comis pm2 logs` streams PM2 output. PM2 also stores its own log files under
`~/.pm2/logs/`. To control PM2 log retention, install and configure
`pm2-logrotate`; Comis's structured file logs have separate rotation settings in
[Logging](/operations/logging).

## Related pages

<CardGroup cols={2}>
  <Card title="systemd" icon="linux" href="/operations/systemd">
    The default managed-service path on Linux.
  </Card>

  <Card title="Daemon" icon="server" href="/operations/daemon">
    Daemon lifecycle and health checks.
  </Card>

  <Card title="Logging" icon="file-lines" href="/operations/logging">
    Configure structured daemon logs and rotation.
  </Card>

  <Card title="Troubleshooting" icon="wrench" href="/operations/troubleshooting">
    Diagnose startup and supervisor issues.
  </Card>
</CardGroup>
