You are not logged in.

#1 2014-05-02 13:46:22

forshark
Member
Registered: 2013-01-03
Posts: 41

nfs mounts upon vpn connection

Hi,

I am attempting to automate nfs mounts upon succesful connection of an openvpn client to an openvpn server. I am using network manager dispatcher to accomplish this task.

here is my 30_nfs.sh:

#!/bin/bash

SERVER="VPN CONNECTION NAME GOES HERE"

MOUNT_POINTS=$(sed -e '/^.*#/d' -e '/^.*:/!d' -e 's/\t/ /g' /etc/fstab | tr -s " " | cut -f2 -d" ")

VPNSTAT=$(nmcli con status | grep demon $SERVER | tr -s ' ' | cut -f 5 -d ' ') 2>/dev/null

if [[ "$VPNSTAT" = "yes" ]]; then
    # The vpn connection is established, make sure the shares are mounted
    for mntpnt in ${MOUNT_POINTS}; do
        mountpoint -q $mntpnt || mount $mntpnt
    done
else
    # The vpn connection is down, unmount the shares
    for umntpnt in ${MOUNT_POINTS}; do
        umount -l -f $umntpnt &>/dev/null
    done
fi 

Have I scripted this correctly? Does NetworkManager dispatcher listen for vpn connection? If not how would I be able to automate nfs mounts upon the establishment of the vpn connection.

Thanks in advance

Offline

#2 2014-05-02 15:12:02

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: nfs mounts upon vpn connection

A few tips:

- you can use vpn-up and vpn-down to act upon vpn connection activation/deactivation,
- $CONNECTION_UUID contains the connection uuid,
- "mount -a -t nfs4" would mount all nfs4 filesystems specified in fstab without "noauto",
- "umount -a -l -t nfs4" would unmount all nfs4 filesystems,
- peek at https://bbs.archlinux.org/viewtopic.php … 0#p1410970

Offline

#3 2014-05-02 18:52:25

forshark
Member
Registered: 2013-01-03
Posts: 41

Re: nfs mounts upon vpn connection

Thanks for the quick response.

That is good advice I will try it as soon as I get some time tonight, and post my script.

Offline

#4 2014-05-03 15:42:15

der_joachim
Member
From: the Netherlands
Registered: 2008-12-17
Posts: 143
Website

Re: nfs mounts upon vpn connection

Here's a thought. Have you considered using autofs? I am not sure whether it works over VPN, but I use autofs for automatic mounting of NFS shares and it works very well.


Geek, runner, motorcyclist and professional know-it-all

Offline

Board footer

Powered by FluxBB