How to start and operate hibernate-on-approach.py on pomelo for a journey.
psycopg2 — not installed by default. Install once:
sudo apt install python3-psycopg2 (or: pip3 install --break-system-packages psycopg2-binary)
stunnel postgres tunnel — must be running before the script starts. The [postgres] block in /etc/stunnel/stunnel.conf maps 127.0.0.1:5432 → gravlax:15432. Verify with: pgrep -a stunnel (should show pid and conf path). stunnel is normally started at boot; if not, sudo service stunnel4 start.
sudo systemctl hibernate must work passwordlessly for the user. If not yet set up, add a sudoers entry:
echo 'john ALL=(ALL) NOPASSWD: /bin/systemctl hibernate' | sudo tee /etc/sudoers.d/hibernate-on-approach then sudo visudo -c to validate.
Start in a tmux pane (so it survives terminal close) before departure:
python3 ~/bin/hibernate-on-approach.py
The script reconnects with backoff after hibernate/resume, so it handles the post-hibernate wifi-tunnel-down period automatically. No action needed after the device wakes up.
tail -f ~/hibernate-on-approach.log — logs a status line every 5s (nearest section, distance, armed state) plus trigger and reconnect events.
Ctrl+C for a clean exit (caught as KeyboardInterrupt).
The script uses psycopg2 (not asyncpg) so it can call time.sleep in the poll loop without blocking an event loop. psycopg2 is a C extension; psycopg2-binary avoids needing libpq-dev at install time.