You are not logged in.

#1 2013-09-19 03:06:42

firecat53
Member
From: Sammamish, Wa
Registered: 2007-05-14
Posts: 1,440
Website

[SOLVED] Stopping openvpn@ service on suspend

I'm trying to stop any running openvpn@ service either prior to suspend or immediately after resume. I've got a service file enabled:

[Unit]
Description=Root suspend actions
Before=sleep.target

[Service]
Type=forking
ExecStart=-/home/firecat53/.local/bin/suspend.sh

[Install]
WantedBy=sleep.target

and the helper script suspend.sh:

#!/bin/sh
# Helper script to stop openvpn on suspend
/usr/bin/systemctl stop $(/usr/bin/systemctl | grep openvpn@ | awk '{print $1}')

The helper script works fine when run by itself, but it fails when run from the service file, and openvpn is still running. I've also tried it post-resume, with the same results.

# journalctl
....
Sep 18 19:56:54 scotty suspend.sh[10544]: Failed to issue method call: Invalid argument
$ systemctl status suspend.sh
suspend.service - Root suspend actions
   Loaded: loaded (/etc/systemd/system/suspend.service; enabled)
   Active: inactive (dead) since Wed 2013-09-18 19:56:54 PDT; 6min ago
  Process: 10544 ExecStart=/home/firecat53/.local/bin/suspend.sh (code=exited, status=1/FAILURE)

Am I doing something wrong here, or is there another way to accomplish this?

Thanks!
Scott

Last edited by firecat53 (2013-09-20 03:52:57)

Offline

#2 2013-09-19 08:17:50

Raynman
Member
Registered: 2011-10-22
Posts: 1,094

Re: [SOLVED] Stopping openvpn@ service on suspend

Maybe you could add

Conflicts=sleep.target

to the openvpn@ template?

Offline

#3 2013-09-20 03:52:32

firecat53
Member
From: Sammamish, Wa
Registered: 2007-05-14
Posts: 1,440
Website

Re: [SOLVED] Stopping openvpn@ service on suspend

Thanks for the tip! Solved by extending openvpn@.service in /etc/systemd/system/openvpn@.service.d/suspend_conflict.conf

[Unit]
Conflicts=suspend.target sleep.target

Now it kills the openvpn@ service on suspend and doesn't restart it automatically on resume, which is the behavior I was looking for.

Scott

Offline

Board footer

Powered by FluxBB