LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-05-2015, 01:42 PM   #1
emacsomancer
LQ Newbie
 
Registered: May 2015
Location: 127.0.0.1
Distribution: Void, Guix, Arch
Posts: 15

Rep: Reputation: Disabled
Question Creating a systemd unit for performing a particular action when the network goes down


Via systemd units, I have my VPN app (PIA VPN) set up to be terminated when my laptop suspends, and set-up to re-initialise when the network comes back up (the network automatically goes down when the system suspends and automatically comes back up when it wakes).

Thus I have a systemd unit like this for killing VPN on suspend:

Code:
[Unit]
Description=User suspend actions
Before=suspend.target

[Service]
User=%I
Environment=DISPLAY=:0
Type=oneshot
ExecStart=-/usr/bin/pkill -f pia
ExecStartPost=/usr/bin/sleep 5

[Install]
WantedBy=sleep.target
And a systemd unit like this for initialising the VPN on network resume:

Code:
[Unit]
Description=Restart PIA VPN
Requires=network.target
After=network.target

[Service]
Environment=DISPLAY=:0
User=%I
Type=forking
ExecStart=/usr/bin/sh /home/emacsomancer/pia.sh
Restart=always
RestartSec=5

[Install]
WantedBy=network.target

But what I additionally want (or perhaps in place of the first systemd unit above) is to kill the VPN when the network goes down. I can't figure out how to do this though.
 
  


Reply

Tags
network, systemd, vpn


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: systemd unit file basics LXer Syndicated Linux News 0 10-28-2015 04:11 PM
[SOLVED] systemd unit does not load at startup. manual start shows no such file/dir failure zjmarlow Linux - Newbie 9 07-19-2015 06:19 AM
Creating a systemd unit for gcr raisdead Linux - Newbie 1 11-12-2014 05:32 PM
LXer: Hybrid RAID 1 (Mirror) of RAM drive & SATA HDD Using LVM with LUKS [and systemd unit file] on LXer Syndicated Linux News 0 07-29-2014 10:40 AM
Performing an action every reboot Zaulden Linux - Laptop and Netbook 9 08-03-2005 05:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration