[GH-ISSUE #1268] Linux suspend-resume broken. CLI API request #490

Open
opened 2026-10-13 20:22:38 +00:00 by bsakaguchi · 3 comments
Owner

Originally created by @EmpathyZeroed on GitHub (Nov 23, 2024).
Original GitHub issue: https://github.com/amnezia-vpn/amnezia-client/issues/1268

Describe the bug
On Linux (and Windows if I remember correctly too) after resume from suspend/hibernation, network connection breaks and high CPU spikes occur until the VPN is manually disabled in Amnezia GUI.

Expected behavior
Automatic re-connection like in Mac OS. Other approach is at least to schedule before&after suspend commands (e.g. amneziavpn --disconnect and amneziavpn --connect "server 1" --mode xtls) to manually disable/re-enable VPN but this requires CLI interface which doesn't exist. At least one solution should be provided, otherwise its perpetual jerking of the GUI button after each screen lock.

Desktop (please complete the following information):

  • OS: Arch Linux

CLI mode / API / RPC / service is crucial not only for this particular case but mandatory for such matured and developed app.

Originally created by @EmpathyZeroed on GitHub (Nov 23, 2024). Original GitHub issue: https://github.com/amnezia-vpn/amnezia-client/issues/1268 **Describe the bug** On Linux (and Windows if I remember correctly too) after resume from suspend/hibernation, network connection breaks and high CPU spikes occur until the VPN is manually disabled in Amnezia GUI. **Expected behavior** Automatic re-connection like in Mac OS. Other approach is at least to schedule before&after suspend commands (e.g. `amneziavpn --disconnect` and `amneziavpn --connect "server 1" --mode xtls`) to manually disable/re-enable VPN but this requires CLI interface which doesn't exist. At least one solution should be provided, otherwise its perpetual jerking of the GUI button after each screen lock. **Desktop (please complete the following information):** - OS: Arch Linux **CLI mode / API / RPC / service is crucial not only for this particular case but mandatory for such matured and developed app.**
Author
Owner

@qumuq-til commented on GitHub (Mar 5, 2025):

A convoluted workaround, but it does work.

Step 1: Create a new monitor script in your home directory and make it executable.

mkdir ~/scripts
nano ~/scripts/amnezia-vpn-monitor.sh
chmod +x ~/scripts/amnezia-vpn-monitor.sh

Paste the following contents into amnezia-vpn-monitor.sh:

#!/bin/sh

# Simple monitor script that watches for a trigger file
while true; do
    if [ -f /tmp/restart-vpn ]; then
        # Remove the trigger file
        rm /tmp/restart-vpn
        # Restart the app
	sleep 5
        /usr/local/bin/AmneziaVPN &
    fi
    sleep 1
done

Step 2: create a systemd user service to run the monitor script.

mkdir -p ~/.config/systemd/user/
nano ~/.config/systemd/user/amnezia-vpn-monitor.service

Paste the following contents into amnezia-vpn-monitor.service

[Unit]
Description=Monitor for VPN restart trigger
After=graphical-session.target

[Service]
ExecStart=%h/scripts/amnezia-vpn-monitor.sh
Restart=on-failure

[Install]
WantedBy=graphical-session.target

Register your service with the OS:

systemctl --user daemon-reload
systemctl --user enable amnezia-vpn-monitor.service
systemctl --user start amnezia-vpn-monitor.service

Step 3: create a new script triggered on resume/wake and make it executable.

sudo nano /usr/lib/systemd/system-sleep/restart-amnezia-vpn.sh
sudo chmod +x /usr/lib/systemd/system-sleep/restart-amnezia-vpn.sh

Paste the following contents into restart-amnezia-vpn.sh:

#!/bin/sh

# pre = going to sleep, post = waking up

case "$1" in
    post)
	killall AmneziaVPN-service
	killall AmneziaVPN
	sleep 10
        touch /tmp/restart-vpn
        chown 1000 /tmp/restart-vpn
	;;
esac

exit 0

Assumptions and explanations:

  • your user ID is assumed to be 1000, adjust accordingly if necessary, id -u will show your current ID
  • killall AmneziaVPN-service could be replaced with systemctl restart AmneziaVPN.service
  • AmneziaVPN client cannot be started correctly in any other way than by running a script from the current graphical session, at least I haven't found a way to do it (would simplify things a lot if everything could be put into /usr/lib/systemd/system-sleep/restart-amnezia-vpn.sh)
  • chown 1000 is necessary for a normal user to be able to delete that file within a script. It may not work otherwise because of the sticky bit on /tmp which may be present, so chmod ugo+w won't suffice there.
  • sleep timers may need adjustment if you find that the client starts up before your network connection is fully up. Adjust by trial and error. If you're making changes to ~/scripts/amnezia-vpn-monitor.sh, it's imperative to do systemctl --user restart vpn-monitor.service to refresh it.
  • after making many successive changes it may be necessary to do a full restart because some components of AmneziaVPN may linger, if you see that something doesn't work correctly when it seemingly should.
<!-- gh-comment-id:2700796935 --> @qumuq-til commented on GitHub (Mar 5, 2025): A convoluted workaround, but it does work. **Step 1: Create a new monitor script in your home directory and make it executable.** ``` mkdir ~/scripts nano ~/scripts/amnezia-vpn-monitor.sh chmod +x ~/scripts/amnezia-vpn-monitor.sh ``` Paste the following contents into _**amnezia-vpn-monitor.sh**_: ``` #!/bin/sh # Simple monitor script that watches for a trigger file while true; do if [ -f /tmp/restart-vpn ]; then # Remove the trigger file rm /tmp/restart-vpn # Restart the app sleep 5 /usr/local/bin/AmneziaVPN & fi sleep 1 done ``` **Step 2: create a systemd user service to run the monitor script.** ``` mkdir -p ~/.config/systemd/user/ nano ~/.config/systemd/user/amnezia-vpn-monitor.service ``` Paste the following contents into _**amnezia-vpn-monitor.service**_ ``` [Unit] Description=Monitor for VPN restart trigger After=graphical-session.target [Service] ExecStart=%h/scripts/amnezia-vpn-monitor.sh Restart=on-failure [Install] WantedBy=graphical-session.target ``` Register your service with the OS: ``` systemctl --user daemon-reload systemctl --user enable amnezia-vpn-monitor.service systemctl --user start amnezia-vpn-monitor.service ``` **Step 3: create a new script triggered on resume/wake and make it executable.** ``` sudo nano /usr/lib/systemd/system-sleep/restart-amnezia-vpn.sh sudo chmod +x /usr/lib/systemd/system-sleep/restart-amnezia-vpn.sh ``` Paste the following contents into _**restart-amnezia-vpn.sh**_: ``` #!/bin/sh # pre = going to sleep, post = waking up case "$1" in post) killall AmneziaVPN-service killall AmneziaVPN sleep 10 touch /tmp/restart-vpn chown 1000 /tmp/restart-vpn ;; esac exit 0 ``` Assumptions and explanations: - your user ID is assumed to be 1000, adjust accordingly if necessary, `id -u` will show your current ID - `killall AmneziaVPN-service` could be replaced with `systemctl restart AmneziaVPN.service` - AmneziaVPN client cannot be started correctly in any other way than by running a script from the current graphical session, at least I haven't found a way to do it (would simplify things a lot if everything could be put into /usr/lib/systemd/system-sleep/restart-amnezia-vpn.sh) - chown 1000 is necessary for a normal user to be able to delete that file within a script. It may not work otherwise because of the sticky bit on /tmp which may be present, so chmod ugo+w won't suffice there. - sleep timers may need adjustment if you find that the client starts up before your network connection is fully up. Adjust by trial and error. If you're making changes to ~/scripts/amnezia-vpn-monitor.sh, it's imperative to do `systemctl --user restart vpn-monitor.service` to refresh it. - after making many successive changes it may be necessary to do a full restart because some components of AmneziaVPN may linger, if you see that something doesn't work correctly when it seemingly should.
Author
Owner

@EmpathyZeroed commented on GitHub (Mar 8, 2025):

@qumuq-til I've come up with better workaround and just switched to ivpn

<!-- gh-comment-id:2708268026 --> @EmpathyZeroed commented on GitHub (Mar 8, 2025): @qumuq-til I've come up with better workaround and just switched to ivpn
Author
Owner

@EvgeniyMakhmudov commented on GitHub (Dec 11, 2025):

I observed the same behavior on Linux Mint 20.1 and now on 22.2. If Amnezia with XRay is connected, and I perform a pm_suspend and then wake the system up, the Amnezia client starts using 100% CPU (all cores) and its memory usage increases (more than 1 GB). After disconnecting, everything returns to normal — CPU usage drops and memory consumption decreases.

<!-- gh-comment-id:3640750783 --> @EvgeniyMakhmudov commented on GitHub (Dec 11, 2025): I observed the same behavior on Linux Mint 20.1 and now on 22.2. If Amnezia with XRay is connected, and I perform a pm_suspend and then wake the system up, the Amnezia client starts using 100% CPU (all cores) and its memory usage increases (more than 1 GB). After disconnecting, everything returns to normal — CPU usage drops and memory consumption decreases.
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
amnezia-vpn/amnezia-client#490
No description provided.