# Troubleshooting

## Check a Single-Instance Service

```bash
sudo systemctl status rtmn --no-pager
sudo journalctl -u rtmn -n 100 --no-pager
```

## Check an Account-Isolated Service

```bash
sudo systemctl status "rtmn-$INSTANCE.service" --no-pager
sudo journalctl -u "rtmn-$INSTANCE.service" -n 100 --no-pager
```

## Common Causes

| Symptom | Possible Cause |
| --- | --- |
| Service exits immediately | Environment file error, shell path error, token error |
| No Telegram response | Wrong chat ID, wrong token, outbound HTTPS blocked |
| Message goes to another server | The same token is active in another instance |
| Audit log write failure | Audit log directory permission error |
| `ExecStart` failure | Wrong binary path or missing execute permission |
| Exit status `78` | Configuration error with restart-loop prevention |

## Checks

### Bot Token

A wrong or revoked token fails Telegram API validation.

Check these points:

- The token is the one issued by BotFather.
- No extra spaces or newlines were included.
- The same token is not active in another instance.

### Chat ID

If the allowed chat ID is wrong, messages will not execute commands.

Check these points:

- Personal chat IDs and group chat IDs were not mixed up.
- A supergroup ID did not lose its `-100` prefix.
- `RTMN_ALLOWED_CHAT_IDS` is comma-separated only.

### Environment File Permissions

```bash
sudo stat -c '%n %U %G %a' /etc/rtmn/env
sudo stat -c '%n %U %G %a' "/etc/rtmn/env-$INSTANCE"
```

Recommended values:

```
owner: root
group: root
mode:  600
```

### Audit Log Permissions

For account-isolated installations, the service account must be able to write to the audit log directory.

```bash
sudo stat -c '%n %U %G %a' "/var/log/rtmn/$INSTANCE"
```

### systemd Unit Syntax

```bash
sudo systemd-analyze verify "/etc/systemd/system/rtmn-$INSTANCE.service"
```

### Binary Executability

```bash
sudo -u "$ACCOUNT" "/home/$ACCOUNT/.rtmn-$INSTANCE/rtmn-$INSTANCE" --help
```

## Exit Status 78

If the service exits with status `78`, treat it as a configuration error.

Recommended handling order:

1. Check journal logs.
2. Verify environment file values.
3. Verify the `EnvironmentFile` and `ExecStart` paths in the service file.
4. Verify audit log directory permissions.
5. Restart the service after fixing the issue.

```bash
sudo systemctl restart "rtmn-$INSTANCE.service"
```
