Restart, redeploy, and troubleshoot your SCI Case Tracker bot. Works for the standalone Telegram bot (
bot/telegram_bot.py) and the FastAPI service (api/main.py).
# Status
systemctl --user status sci-bot
# Start / stop / restart
systemctl --user start sci-bot
systemctl --user stop sci-bot
systemctl --user restart sci-bot
# Live logs (recommended — captures stderr too)
journalctl --user -u sci-bot -f
# Disable auto-start (without stopping the running bot)
systemctl --user disable sci-bot
systemctl --user enable sci-botOnce configured, the bot starts on every login (and on every boot if you enable lingering). No manual restart needed.
Save as ~/.config/systemd/user/sci-bot.service:
[Unit]
Description=SCI Case Tracker — Telegram bot
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
WorkingDirectory=%h/sci-case-tracker
EnvironmentFile=%h/sci-case-tracker/.env
ExecStart=%h/sci-case-tracker/.venv/bin/python -m bot.telegram_bot
Restart=on-failure
RestartSec=5
StandardOutput=append:%h/sci-case-tracker/logs/bot.log
StandardError=append:%h/sci-case-tracker/logs/bot.log
Environment=SCI_CACHE_DB=%h/sci-case-tracker/src/sci_case_tracker/cache.db
Environment=SCI_BOT_DB=%h/sci-case-tracker/bot/watchlist.db
[Install]
WantedBy=default.target%h expands to your home directory at runtime.
cp ~/sci-case-tracker/.env.example ~/sci-case-tracker/.env
# Open ~/sci-case-tracker/.env and paste your TELEGRAM_BOT_TOKENmkdir -p ~/sci-case-tracker/logssystemctl --user daemon-reload
systemctl --user enable sci-bot.service
systemctl --user start sci-bot.service
systemctl --user status sci-bot.serviceYou should see:
● sci-bot.service - SCI Case Tracker — Telegram bot
Active: active (running)
Main PID: <some-pid>
By default, systemd user services only run while you're logged in. To keep the bot running across reboots even before login, enable lingering:
sudo loginctl enable-linger $USEROne-time setup. From this point on, the bot starts at boot.
If you don't have systemd or prefer manual control:
# Stop anything that might already be running
pkill -f "bot.telegram_bot"; sleep 2
# Start in background, detached from terminal
TOKEN=$(grep '^TELEGRAM_BOT_TOKEN=' ~/sci-case-tracker/.env | cut -d= -f2-)
TELEGRAM_BOT_TOKEN="$TOKEN" \
setsid bash -c "cd ~/sci-case-tracker && exec .venv/bin/python -m bot.telegram_bot" \
</dev/null \
>~/sci-case-tracker/logs/bot.log \
2>&1 \
& disown
# Verify
sleep 5
ps aux | grep "bot.telegram_bot" | grep -v grep
tail -10 ~/sci-case-tracker/logs/bot.logYou should see SCI Telegram bot online. Open mode: <True|False> in the log.
| Data | Location | Notes |
|---|---|---|
| Source code | ~/sci-case-tracker/ |
tracked in git |
| Python venv + deps | ~/sci-case-tracker/.venv/ |
recreate with pip install -r requirements.txt |
| SCI status cache (SQLite) | ~/sci-case-tracker/src/sci_case_tracker/cache.db |
warm cache survives — re-lookups are instant |
| Per-user watchlist (SQLite) | ~/sci-case-tracker/bot/watchlist.db |
/track and /list data |
| Bot token | ~/sci-case-tracker/.env |
gitignored |
| Bot logs | ~/sci-case-tracker/logs/bot.log |
trim periodically; systemd captures via journald too |
| systemd unit | ~/.config/systemd/user/sci-bot.service |
survives reinstalls of the repo |
systemctl --user stop sci-bot
cd ~/sci-case-tracker
git pull
.venv/bin/pip install -r requirements.txt --upgrade
.venv/bin/pip install -e . --upgrade
systemctl --user start sci-bot
journalctl --user -u sci-bot -n 30Cache and watchlist DBs survive updates. Schema changes (rare) ship with a migration script in the release notes.
- Is it actually running?
ps aux | grep "bot.telegram_bot" | grep -v grep systemctl --user status sci-bot
- Is something else polling the same Telegram token? Telegram only allows one poller per bot. Check for any other bot framework you might be running.
- Check the log for errors:
journalctl --user -u sci-bot -n 100 # or tail -100 ~/sci-case-tracker/logs/bot.log
- If
Open mode: Falsein the log and you're not inTELEGRAM_ALLOWED_USERS, the bot ignores you silently. Add your Telegram user ID to the env var (find your ID by messaging@userinfobot).
You started the bot from the wrong directory. The bot package needs to be discoverable from cwd. Always cd ~/sci-case-tracker first, or use the systemd unit (it sets WorkingDirectory).
Install the document-extractor dependencies:
~/sci-case-tracker/.venv/bin/pip install -r ~/sci-case-tracker/requirements.txtOCR needs the Tesseract system package:
sudo apt install -y tesseract-ocr # Debian / Ubuntu
brew install tesseract # macOSNo bot restart needed — Python imports tesseract at OCR time, not at startup.
The SCI portal goes down occasionally for maintenance. The client retries once automatically. If you see persistent 5xx errors:
curl -I https://www.sci.gov.in/If that fails too, wait 5-10 minutes and try again. SCI's side is the bottleneck.
Telegram may collapse identical files (same hash). Try with a different filename or a tiny modification.
If you find a long batch upload blocks new messages, ensure the bot was started after concurrent updates were enabled. The current code uses Application.builder().concurrent_updates(True) — if you've forked an older copy, update.
If you ever want to roll back to v0.1.0:
systemctl --user stop sci-bot
cd ~/sci-case-tracker
git checkout v0.1.0
.venv/bin/pip install -r requirements.txt --upgrade
.venv/bin/pip install -e . --upgrade
systemctl --user start sci-botTo return to latest:
systemctl --user stop sci-bot
git checkout main
git pull
.venv/bin/pip install -r requirements.txt --upgrade
.venv/bin/pip install -e . --upgrade
systemctl --user start sci-botIf you use Claude / ChatGPT / Codex to manage your server, paste this into a fresh session to get the bot running again:
Resume my SCI Case Tracker Telegram bot.
Expected state:
- Repo at ~/sci-case-tracker (https://github.com/CyberWarrior9/sci-case-tracker)
- venv at ~/sci-case-tracker/.venv with sci-case-tracker installed
- Bot token in ~/sci-case-tracker/.env (TELEGRAM_BOT_TOKEN=...)
- Optional systemd unit at ~/.config/systemd/user/sci-bot.service
Please:
1. Verify the repo is present and pull latest from origin/main
2. Confirm only one bot process is running (don't start a duplicate)
3. If the systemd unit exists, use `systemctl --user start sci-bot`;
otherwise start manually using the commands in HOW-TO-RESTART.md
4. Tail logs for 5 seconds and confirm the bot is online
5. Report PID and how to test (send any case number in Telegram)
| Goal | Command |
|---|---|
| Is it running? | systemctl --user is-active sci-bot |
| Start it | systemctl --user start sci-bot |
| Stop it | systemctl --user stop sci-bot |
| Restart it | systemctl --user restart sci-bot |
| Live tail logs | journalctl --user -u sci-bot -f |
| Last 50 log lines | journalctl --user -u sci-bot -n 50 |
| Filter errors | journalctl --user -u sci-bot | grep -iE "error|exception|fail" |
| Auto-start on boot | systemctl --user enable sci-bot |
| Survive logout | sudo loginctl enable-linger $USER (one-time) |
| Disable auto-start | systemctl --user disable sci-bot |
Open an issue on the repo if:
- The bot crashes repeatedly with the same error in logs
- A specific case number returns wrong data (paste the case number + what came back)
- A specific file format isn't being parsed (attach a sanitised sample)
- A new SCI case type isn't recognised (paste the format you're trying)
Don't open an issue for:
- Generic Python or Telegram bot setup questions (use Stack Overflow)
- "How do I deploy this to AWS / Heroku / X" (check
docs/DEPLOY.md) - Feature requests for non-SCI courts (a wider rewrite — file under Discussions instead)