Skip to content

Commit

Permalink
Fix service restart after adding plug (#740)
Browse files Browse the repository at this point in the history
  • Loading branch information
devzbysiu authored Jan 16, 2025
1 parent a6a17e6 commit 6fb1888
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
10 changes: 8 additions & 2 deletions snap/hooks/connect-plug-firewall-control
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/bin/sh
if [ "$(cat ${SNAP_COMMON}/connections/firewall-control 2> /dev/null)" -ne "1" ]; then
snapctl restart nordvpn.nordvpnd

INTERFACE_NAME="firewall-control"

if snapctl is-connected ${INTERFACE_NAME}; then
echo "The ${INTERFACE_NAME} interface is connected. Restarting the Snap container..."
snapctl restart nordvpn.nordvpnd
else
echo "The ${INTERFACE_NAME} interface is not connected."
fi
10 changes: 10 additions & 0 deletions snap/hooks/connect-plug-hardware-observe
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

INTERFACE_NAME="hardware-observe"

if snapctl is-connected ${INTERFACE_NAME}; then
echo "The ${INTERFACE_NAME} interface is connected. Restarting the Snap container..."
snapctl restart nordvpn.nordvpnd
else
echo "The ${INTERFACE_NAME} interface is not connected."
fi
10 changes: 8 additions & 2 deletions snap/hooks/connect-plug-network-control
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/bin/sh
if [ "$(cat ${SNAP_COMMON}/connections/network-control 2> /dev/null)" -ne "1" ]; then
snapctl restart nordvpn.nordvpnd

INTERFACE_NAME="network-control"

if snapctl is-connected ${INTERFACE_NAME}; then
echo "The ${INTERFACE_NAME} interface is connected. Restarting the Snap container..."
snapctl restart nordvpn.nordvpnd
else
echo "The ${INTERFACE_NAME} interface is not connected."
fi
5 changes: 3 additions & 2 deletions snapconf/snapconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const (
// https://snapcraft.io/docs/supported-interfaces
type Interface string

// NOTE: Some of the interfaces require restart of the service. This is achieved
// by using snap hooks see snap/hooks directory.
// For more information see the docs: https://snapcraft.io/docs/interface-hooks.
const (
InterfaceNetwork Interface = "network"
InterfaceNetworkBind Interface = "network-bind"
Expand Down Expand Up @@ -60,8 +63,6 @@ type ConnChecker struct {

// NewSnapChecker snap permission checker with specific setup
func NewSnapChecker(publisherErr events.Publisher[error]) *ConnChecker {
// currently the order is important for machine ID generation:
// At the moment InterfaceHardwareObserve needs to be first because snap restarts the daemon only for some of the interfaces.
return NewConnChecker(
[]Interface{
InterfaceHardwareObserve,
Expand Down

0 comments on commit 6fb1888

Please sign in to comment.