1

I'm running Pop!_OS, a Ubuntu based OS, and I want to run nordvpn disconnect before suspend and nordvpn connect after suspend. I'm using code from this arch linux wiki and can't get the nordvpn connect/nordvpn disconnect commands to run on system wake. I added the file 99nordvpn-reload to /lib/systemd/system-sleep/ and made it executable with sudo chmod a+x 99nordvpn-reload. The code in that file is:

#!/bin/sh
case $1/$2 in
  pre/*)
    nordvpn disconnect
    ;;
  post/*)
    nordvpn connect
    ;;
esac

waking from sleep, running journalctl -u systemd-suspend.service shows:

Jun 13 22:08:38 pop-os [4520]: /usr/lib/systemd/system-sleep/99nordvpn-reload failed with exit status 1.

I have also tried running the command as a local user with:

#!/bin/sh
case $1/$2 in
  pre/*)
    sudo -u $USER nordvpn disconnect
    ;;
  post/*)
    sudo -u $USER nordvpn connect
    ;;
esac

but $USER is replaced with the output from echo $USER. However, I get the same error message as before. I'm assuming this error has something to do with the nordvpn package being installed locally or my $USER, hence the attempt at executing the command with sudo -u $USER.

Based on this thread, I also attempted creating the globally executable file /usr/local/bin/nordvpn-reload with contents:

#!/bin/bash

nordvpn disconnect;nordvpn connect

and changing the contents of /lib/systemd/system-sleep/99nordvpn-reload to:

#!/bin/sh
case $1/$2 in
  pre/*)
    exit 0
    ;;
  post/*)
    /usr/local/bin/nordvpn-reload
    ;;
esac

but once again, I get the same error as always. Any suggestions/advice/further reading would be much appreciated.

2 Answers 2

0

I tried something similar on Ubuntu 20.04 LTS and for me it worked with the script at /lib/systemd/system-sleep/nordvpn-reload:

#!/bin/sh
case $1 in
  pre)
    nordvpn disconnect
    ;;

  post)
    nordvpn connect
    ;;
esac

0

In my case, I had to change the pre) line from @moritz-shroeder's response to make sure nordvpn is actually shut down:

#!/bin/sh
case $1 in
  pre)
    pkill -9 nordvpn
    ;;

  post)
    nordvpn connect
    ;;
esac

As you can see, I'm using pkill here, with the signal 9. This tells nordvpn to actually KILL its process. For some reason, a simple disconnect was not enough in my case.

You can learn more on pkill here

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.