diff --git a/README.md b/README.md index 7406ee4..ed9fd03 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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 ```