@@ -640,13 +640,13 @@ function protonvpn_looper_cmd() {
640
640
log_warning " Not verifying connection, as healthchecks are disabled"
641
641
fi
642
642
else
643
- log_error " Failed to connect to ${PROTONVPN_SERVER} "
643
+ log_error " Failed to connect to ${PROTONVPN_SERVER:- NA } "
644
644
if [[ -z $( ip link show protonwire0 type wireguard 2> /dev/null) ]]; then
645
645
log_debug " Wireguard interface for protonwire is not present."
646
646
return 1
647
647
fi
648
648
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 } "
650
650
fi
651
651
__protonvpn_disconnect
652
652
return 1
@@ -696,17 +696,29 @@ function protonvpn_looper_cmd() {
696
696
fi
697
697
698
698
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
700
705
break
701
706
fi
702
707
703
708
sleep " ${sleep_int:- 120} " &
704
709
wait $!
705
710
706
711
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} )"
708
714
(( ++ __PROTONWIRE_HC_ERRORS))
709
715
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
+
710
722
if __protonvpn_connect; then
711
723
sleep 2 & # avoid transient errors
712
724
wait $!
@@ -1732,32 +1744,30 @@ function __protonvpn_connect() {
1732
1744
else
1733
1745
log_debug " WIREGUARD_PRIVATE_KEY is not set"
1734
1746
declare -a lookup_paths=(
1735
- " /etc/protonwire/private-key"
1736
1747
" /etc/protonwire/protonwire-private-key"
1737
1748
" /etc/protonwire/protonvpn-private-key"
1738
1749
" /etc/protonwire/wireguard-private-key"
1750
+ " /etc/protonwire/private-key"
1739
1751
1740
- " /run/secrets/private-key"
1741
1752
" /run/secrets/protonwire-private-key"
1742
1753
" /run/secrets/protonvpn-private-key"
1743
1754
" /run/secrets/wireguard-private-key"
1755
+ " /run/secrets/private-key"
1744
1756
1745
- " /run/secrets/protonwire/private-key"
1746
1757
" /run/secrets/protonwire/protonwire-private-key"
1747
1758
" /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"
1759
1761
)
1760
1762
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
+
1761
1771
for lookup_path in " ${lookup_paths[@]} " ; do
1762
1772
if [[ -f ${lookup_path} ]]; then
1763
1773
if __is_usable_keyfile " ${lookup_path} " ; then
@@ -2140,6 +2150,7 @@ function __protonvpn_disconnect() {
2140
2150
2141
2151
if __has_notify_socket; then
2142
2152
log_debug " Notify to systemd that vpn is disconnecting"
2153
+ __systemd_notify " Disconnecting from ${PROTONVPN_SERVER:- NA} "
2143
2154
__systemd_notify " STOPPING=1"
2144
2155
else
2145
2156
log_debug " No systemd notify socket found, skiping stopping notification"
@@ -2197,8 +2208,17 @@ function __protonvpn_disconnect() {
2197
2208
fi
2198
2209
2199
2210
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
2200
2215
return 0
2201
2216
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
2202
2222
return 1
2203
2223
}
2204
2224
0 commit comments