Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,10 @@ Useful `screen` controls:
### Run as a systemd service

Use this option when the bot should start together with the system and restart
after crashes. This example still starts the bot inside `screen`, so you can
reconnect to the running session.
after crashes.

First complete the setup from the simple `screen` run section above. Then create
a `systemd` service file:
First complete the clone and configuration setup from the simple `screen` run
section above. Then create a `systemd` service file:

```bash
sudo nano /etc/systemd/system/codex-time-bot.service
Expand All @@ -212,8 +211,7 @@ Type=simple
User=denys
WorkingDirectory=/home/denys/codex-time-bot
Environment=PYTHONUNBUFFERED=1
ExecStart=/usr/bin/screen -DmS codex-time-bot /home/denys/codex-time-bot/.venv/bin/python main.py
ExecStop=/usr/bin/screen -S codex-time-bot -X quit
ExecStart=/home/denys/codex-time-bot/.venv/bin/python main.py
Restart=on-failure
RestartSec=5

Expand All @@ -239,23 +237,35 @@ Check service status:
sudo systemctl status codex-time-bot
```

If the bot runs as a `systemd` service, make sure it is not also running in a
parallel `screen` session to avoid running two bot instances at the same time.
List existing `screen` sessions with:

```bash
screen -ls
```

Useful service commands:

```bash
sudo systemctl stop codex-time-bot
sudo systemctl restart codex-time-bot
sudo journalctl -u codex-time-bot -f
```

To reconnect to the service-owned `screen` session:
Useful autostart commands:

```bash
screen -r codex-time-bot
sudo systemctl enable codex-time-bot
sudo systemctl disable codex-time-bot
```

Detach with `Ctrl+A`, then `D`. Stop the service through `systemd` instead of
pressing `Ctrl+C` inside the session:
- Enable autostart after reboot: `sudo systemctl enable codex-time-bot`.
- Disable autostart after reboot: `sudo systemctl disable codex-time-bot`.
- Disabling autostart does not stop the currently running service; use
`sudo systemctl stop codex-time-bot` for that.

Logs:

```bash
sudo systemctl stop codex-time-bot
sudo journalctl -u codex-time-bot -f
```
Loading