From cc26f773de3fdc040ccd027d40e4e074ab4e2e38 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Wed, 13 May 2026 10:40:03 -0500 Subject: feat(cmail): clean autostart stub and add DNS-wait drop-in I extended cmail-setup-finish.sh with two boot-cleanliness fixes for the systemd --user Bridge service. The autostart cleanup removes ~/.config/autostart/Proton Mail Bridge.desktop, which double-launches Bridge and throws an "orphan instance" dialog every login. The wait-for-dns drop-in installs an ExecStartPre loop that waits up to 30 seconds for DNS before Bridge's first API call. User-instance systemd doesn't carry network-online.target, so After=network.target doesn't imply the resolver is up. The leading '-' makes the pre-step non-fatal so an offline boot still starts the unit. --- scripts/cmail-setup-finish.sh | 54 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/cmail-setup-finish.sh b/scripts/cmail-setup-finish.sh index de99101..3e119f6 100755 --- a/scripts/cmail-setup-finish.sh +++ b/scripts/cmail-setup-finish.sh @@ -15,8 +15,13 @@ # 2. Copies Bridge's self-signed cert → ~/.config/protonbridge.pem # 3. Symlinks ~/projects/claude-templates/.ai/scripts/cmail-action.py # → ~/.local/bin/cmail-action -# 4. Enables + starts the protonmail-bridge user service -# 5. Verifies Bridge is listening on 127.0.0.1:1143 / :1025 +# 4. Removes the leftover ~/.config/autostart/Proton Mail Bridge.desktop +# stub (it double-launches Bridge alongside the systemd user service +# and throws an "orphan instance" dialog every login) +# 5. Installs a wait-for-dns drop-in so Bridge doesn't spam +# name-resolution errors during the early-boot DNS race +# 6. Enables + starts the protonmail-bridge user service +# 7. Verifies Bridge is listening on 127.0.0.1:1143 / :1025 set -euo pipefail @@ -61,12 +66,51 @@ mkdir -p "$HOME/.local/bin" ln -sf "$cmail_action_src" "$HOME/.local/bin/cmail-action" ok "linked $HOME/.local/bin/cmail-action → $cmail_action_src" -# 5. Enable + start systemd user service +# 5. Remove leftover XDG autostart stub +# The systemd --user service is the canonical launcher. The autostart .desktop +# starts a second Bridge instance that can't get the lock and pops up an +# "orphan instance" dialog every login. +info "removing orphan autostart launcher (if present)" +autostart_stub="$HOME/.config/autostart/Proton Mail Bridge.desktop" +if [ -f "$autostart_stub" ]; then + rm "$autostart_stub" + ok "removed $autostart_stub" +else + ok "no autostart stub present" +fi + +# 6. Install wait-for-dns drop-in +# User-instance systemd doesn't carry network-online.target / nss-lookup.target, +# so the packaged unit's After=network.target doesn't imply DNS readiness. +# Bridge starts before the resolver is up and its first API calls all fail +# until DNS comes online a few seconds later. The drop-in waits (bounded 30s) +# for resolution before ExecStart. The leading '-' on ExecStartPre makes it +# non-fatal, so an offline boot still starts the unit. +info "installing wait-for-dns drop-in" +dropin_dir="$HOME/.config/systemd/user/protonmail-bridge.service.d" +dropin_file="$dropin_dir/wait-for-dns.conf" +mkdir -p "$dropin_dir" +cat > "$dropin_file" <<'EOF' +[Service] +ExecStartPre=-/bin/sh -c 'for i in $(seq 1 30); do getent hosts mail-api.proton.me >/dev/null 2>&1 && exit 0; sleep 1; done' +EOF +ok "wrote $dropin_file" +systemctl --user daemon-reload +ok "reloaded systemd user units" + +# 7. Enable + start systemd user service info "enabling protonmail-bridge user service" +was_active=0 +systemctl --user is-active --quiet protonmail-bridge.service && was_active=1 systemctl --user enable --now protonmail-bridge -ok "service active" +if [ "$was_active" = "1" ]; then + systemctl --user restart protonmail-bridge + ok "service active (restarted to pick up drop-in)" +else + ok "service active" +fi -# 6. Verify +# 8. Verify info "verifying Bridge is listening" if ss -ltn 2>/dev/null | grep -qE '127\.0\.0\.1:(1143|1025)'; then ok "127.0.0.1:1143 + :1025 LISTEN" -- cgit v1.2.3