Skip to content

Commit d700309

Browse files
committed
feat: systemd-notify improve notification msg on disconnect and errors
1 parent 236f871 commit d700309

File tree

3 files changed

+54
-28
lines changed

3 files changed

+54
-28
lines changed

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
> [!WARNING]
2828
>
29-
> [gVisor](https://gvisor.dev) and cgroup v1 runtime is **NOT** supported!
29+
> [gVisor](https://gvisor.dev) and cgroup v1 are **NOT** supported!
3030
3131
Images are published at [ghcr.io/tprasadtp/protonwire][ghcr].
3232

@@ -65,7 +65,7 @@ Images are published at [ghcr.io/tprasadtp/protonwire][ghcr].
6565
AllowedIPs = 0.0.0.0/0
6666
Endpoint = 91.229.23.180:51820
6767
```
68-
- Only thing needed from the above config is `PrivateKey`.
68+
- You will `PrivateKey` and optionally `Endpoint`(without port part) from the above config.
6969
- See https://protonvpn.com/support/wireguard-configurations/ for more info.
7070

7171
## Environment Variables & Config
@@ -78,6 +78,12 @@ in following locations.
7878
- `/run/secrets/protonwire-private-key`
7979
- `/run/secrets/protonwire/private-key`
8080
- `${CREDENTIALS_DIRECTORY}/private-key` (Only if `$CREDENTIALS_DIRECTORY` is set)
81+
- `${CREDENTIALS_DIRECTORY}/protonwire-private-key` (Only if `$CREDENTIALS_DIRECTORY` is set)
82+
83+
> [!IMPORTANT]
84+
>
85+
> Private key file **MUST NOT** be world-readable.
86+
8187

8288
| Name | Default/Required | Description
8389
|---|---|---
@@ -86,7 +92,7 @@ in following locations.
8692
| `IPCHECK_URL` | https://protonwire-api.vercel.app/v1/client/ip | (String) URL to check client IP.
8793
| `IPCHECK_INTERVAL` | `60` | (Integer) Interval between internal health-checks in seconds. Set this to `0` to disable IP checks.
8894
| `SKIP_DNS_CONFIG` | false | (Boolean) Set this to `1` or `true` to skip configuring DNS.
89-
| `KILL_SWITCH` | false | (Boolean) Enable KillSwitch (Experimental and can cause issues)
95+
| `KILL_SWITCH` | false | (Boolean) Enable KillSwitch (Experimental)
9096

9197
## PROTONVPN_SERVER
9298

@@ -260,19 +266,20 @@ This section covers running containers via podman. But for deployments use
260266
- Create a podman secret for private key
261267
262268
```console
263-
sudo podman secret create protonwire-private-key <PRIVATE_KEY|PATH_TO_PRIVATE_KEY>
269+
podman secret create protonwire-private-key <PRIVATE_KEY|PATH_TO_PRIVATE_KEY>
264270
```
265271
266272
- Run _protonwire_ container.
267273
268274
```console
269-
sudo podman run \
275+
podman run \
270276
-it \
277+
--rm \
271278
--init \
272279
--replace \
273280
--tz=local \
274281
--tmpfs=/tmp \
275-
--name=protonwire-demo \
282+
--name=protonwire \
276283
--secret="protonwire-private-key,mode=600" \
277284
--env=PROTONVPN_SERVER="nl-free-127.protonvpn.net" \
278285
--env=DEBUG=0 \
@@ -293,12 +300,12 @@ we are using caddy to proxy website which shows IP info. Replace these with your
293300
container(s) like [pyload](https://github.com/pyload/pyload#docker-images), [firefox](https://docs.linuxserver.io/images/docker-firefox) etc.
294301
295302
```console
296-
sudo podman run \
303+
podman run \
297304
-it \
298305
--rm \
299306
--tz=local \
300307
--name=protonwire-demo-app \
301-
--network=container:protonwire-demo \
308+
--network=container:protonwire \
302309
docker.io/library/caddy:latest \
303310
caddy reverse-proxy --change-host-header --from :8000 --to https://ip.me:443
304311
```
@@ -355,7 +362,6 @@ For example, we can run caddy to proxy `https://ip.me/` via VPN. Visiting http:/
355362
-it \
356363
--rm \
357364
--net=container:protonwire \
358-
--name=protonwire-demo \
359365
caddy:latest \
360366
caddy reverse-proxy \
361367
--change-host-header \

Vagrantfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Vagrant.configure("2") do |config|
156156

157157
$libvirt_provision = <<-SCRIPT
158158
echo "---------------------------------"
159-
echo "Installing qemu daemon"
159+
echo "Installing qemu-guest-agent"
160160
echo "---------------------------------"
161161
apt-get update
162162
apt-get install -y qemu-guest-agent

protonwire

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -640,13 +640,13 @@ function protonvpn_looper_cmd() {
640640
log_warning "Not verifying connection, as healthchecks are disabled"
641641
fi
642642
else
643-
log_error "Failed to connect to ${PROTONVPN_SERVER}"
643+
log_error "Failed to connect to ${PROTONVPN_SERVER:-NA}"
644644
if [[ -z $(ip link show protonwire0 type wireguard 2>/dev/null) ]]; then
645645
log_debug "Wireguard interface for protonwire is not present."
646646
return 1
647647
fi
648648
if __has_notify_socket; then
649-
__systemd_notify "STATUS=Failed to connect to - ${PROTONVPN_SERVER}"
649+
__systemd_notify "STATUS=Failed to connect to - ${PROTONVPN_SERVER:-NA}"
650650
fi
651651
__protonvpn_disconnect
652652
return 1
@@ -696,17 +696,29 @@ function protonvpn_looper_cmd() {
696696
fi
697697

698698
if [[ $__PROTONWIRE_HC_ERRORS -ge ${max_verify_attemps} ]]; then
699-
log_error "Connection verification ($((__PROTONWIRE_HC_ERRORS))/${IPCHECK_THRESHOLD:-5}) failed"
699+
log_error "Connection verification (${__PROTONWIRE_HC_ERRORS}/${max_verify_attemps}) failed"
700+
if __has_notify_socket; then
701+
__systemd_notify "Connection verification failed (${__PROTONWIRE_HC_ERRORS}/${max_verify_attemps}) "
702+
else
703+
log_debug "No systemd notify socket found, skiping reconnect notification"
704+
fi
700705
break
701706
fi
702707

703708
sleep "${sleep_int:-120}" &
704709
wait $!
705710

706711
if ! __protonvpn_verify_connection; then
707-
log_error "Failed to verify connection ($((__PROTONWIRE_HC_ERRORS + 1))/${IPCHECK_THRESHOLD:-5})"
712+
local xt=$((__PROTONWIRE_HC_ERRORS + 1))
713+
log_error "Failed to verify connection (${xt}/${max_verify_attemps})"
708714
((++__PROTONWIRE_HC_ERRORS))
709715
log_warning "Attempting to re-connect to ${PROTONVPN_SERVER}"
716+
if __has_notify_socket; then
717+
__systemd_notify "Attempting to re-connect to ${PROTONVPN_SERVER} (${xt}/${max_verify_attemps})"
718+
else
719+
log_debug "No systemd notify socket found, skiping reconnect notification"
720+
fi
721+
710722
if __protonvpn_connect; then
711723
sleep 2 & # avoid transient errors
712724
wait $!
@@ -1732,32 +1744,30 @@ function __protonvpn_connect() {
17321744
else
17331745
log_debug "WIREGUARD_PRIVATE_KEY is not set"
17341746
declare -a lookup_paths=(
1735-
"/etc/protonwire/private-key"
17361747
"/etc/protonwire/protonwire-private-key"
17371748
"/etc/protonwire/protonvpn-private-key"
17381749
"/etc/protonwire/wireguard-private-key"
1750+
"/etc/protonwire/private-key"
17391751

1740-
"/run/secrets/private-key"
17411752
"/run/secrets/protonwire-private-key"
17421753
"/run/secrets/protonvpn-private-key"
17431754
"/run/secrets/wireguard-private-key"
1755+
"/run/secrets/private-key"
17441756

1745-
"/run/secrets/protonwire/private-key"
17461757
"/run/secrets/protonwire/protonwire-private-key"
17471758
"/run/secrets/protonwire/protonvpn-private-key"
1748-
"/run/secrets/protonwire/protonvpn-private-key"
1749-
1750-
"/run/credentials/private-key"
1751-
"/run/credentials/protonwire-private-key"
1752-
"/run/credentials/protonvpn-private-key"
1753-
"/run/credentials/protonvpn-private-key"
1754-
1755-
"/run/credentials/protonwire/private-key"
1756-
"/run/credentials/protonwire/protonwire-private-key"
1757-
"/run/credentials/protonwire/protonvpn-private-key"
1758-
"/run/credentials/protonwire/protonvpn-private-key"
1759+
"/run/secrets/protonwire/wireguard-private-key"
1760+
"/run/secrets/protonwire/private-key"
17591761
)
17601762

1763+
# If CREDENTIALS_DIRECTORY is defined, use it (for systemd-creds)
1764+
if [[ -n $CREDENTIALS_DIRECTORY ]]; then
1765+
lookup_paths+=("${CREDENTIALS_DIRECTORY%/}/protonwire-private-key")
1766+
lookup_paths+=("${CREDENTIALS_DIRECTORY%/}/protonvpn-private-key")
1767+
lookup_paths+=("${CREDENTIALS_DIRECTORY%/}/wireguard-private-key")
1768+
lookup_paths+=("${CREDENTIALS_DIRECTORY%/}/private-key")
1769+
fi
1770+
17611771
for lookup_path in "${lookup_paths[@]}"; do
17621772
if [[ -f ${lookup_path} ]]; then
17631773
if __is_usable_keyfile "${lookup_path}"; then
@@ -2140,6 +2150,7 @@ function __protonvpn_disconnect() {
21402150

21412151
if __has_notify_socket; then
21422152
log_debug "Notify to systemd that vpn is disconnecting"
2153+
__systemd_notify "Disconnecting from ${PROTONVPN_SERVER:-NA}"
21432154
__systemd_notify "STOPPING=1"
21442155
else
21452156
log_debug "No systemd notify socket found, skiping stopping notification"
@@ -2197,8 +2208,17 @@ function __protonvpn_disconnect() {
21972208
fi
21982209

21992210
if [[ $errs -eq 0 ]]; then
2211+
if __has_notify_socket; then
2212+
log_debug "Notify to systemd that vpn has disconnected"
2213+
__systemd_notify "Disconnected"
2214+
fi
22002215
return 0
22012216
fi
2217+
2218+
if __has_notify_socket; then
2219+
log_debug "Notify to systemd that vpn disconnection errored"
2220+
__systemd_notify "Failed to disconnect"
2221+
fi
22022222
return 1
22032223
}
22042224

0 commit comments

Comments
 (0)