LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 07-01-2015, 10:56 AM   #1
matb
LQ Newbie
 
Registered: Jul 2015
Posts: 5

Rep: Reputation: Disabled
Ftp mount after OpenVPN connection


Hey I want to fix that my ftp mounts only after my OpenVPN connection is established (I'm on raspbian)
I found this script for ubuntu: http://linuxnotes.us/archives/66

It's not working at the moment, maybe someone can help me?

Installation file
Code:
#!/bin/bash

DEFAULTS="/etc/default/openvpn"
SCRIPTS="openvpn-wait4active  openvpn-unmount"
FSTAB=/etc/fstab

echo "What are the VPN interfaces (ie:  tap0,  tun0)"
echo -n "Enter all the VPN interfaces separated by spaces: "
read ints
echo "interfaces=\"$ints\"" >> $DEFAULTS


cp $SCRIPTS /etc/init.d
sed -i "s/^mount/#mount/g" /etc/rc.local
sed -i "s./bin/mount.#/bin/mount.g" /etc/rc.local

update-rc.d -f openvpn remove
update-rc.d -f openvpn-wait4active remove
update-rc.d -f openvpn-unmount remove

update-rc.d openvpn start 40 S . stop 39 S .
update-rc.d openvpn-wait4active start 44 S . stop 43 S .


ln -s /etc/init.d/openvpn-unmount /etc/rc0.d/S19openvpn-unmount 
ln -s /etc/init.d/openvpn-unmount /etc/rc6.d/S19openvpn-unmount 
#update-rc.d openvpn-unmount  start 19 0 .
#update-rc.d openvpn-unmount  start 19 6 .


sed -i "s/dmask/dir_mode/g" $FSTAB
sed -i "s/fmask/file_mode/g" $FSTAB


exit 0
openvpn wait4active (I added ftp with in the grep command)
Code:
#!/bin/sh  

### BEGIN INIT INFO
# Provides:          Wait for vpn interfaces to come up
# Required-Start:    $network $local_fs openvpn
# Required-Stop:     $network $local_fs openvon
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Wait until Openvpn VPN service  is fully active
### END INIT INFO

PATH=/sbin:/bin
. /lib/init/vars.sh

. /lib/lsb/init-functions
. /lib/init/mount-functions.sh

if [ -r /etc/default/locale ]; then
	. /etc/default/locale
	export LANG
fi

MAX_TRIES=30

if test -e /etc/default/openvpn ; then
  . /etc/default/openvpn
else
  mount -a -t proc >/dev/null 2>&1  # Ignore error message due to /proc already being mounted
  ES_TO_REPORT=$?
  if [ 0 = "$ES_TO_REPORT" ]
  then
    log_action_end_msg 0
  else
    log_action_end_msg 1 "code $ES_TO_REPORT"
  fi
  exit 0
  interfaces="tap0 tun0"
fi

case "$1" in
start)
	for i in $interfaces; do
		cnt=0
		log_daemon_msg "Waiting for interface: $i                          "
		rc=1
		while [ $rc -ne 0 -a $cnt -lt $MAX_TRIES  ]; do
			cnt=$((cnt + 1))
			sleep 1
			ifconfig | grep -q $i
			rc=$?
		done
		log_action_end_msg $rc
	done
	sleep 15
	# Do the mountall again to mount any filesystems which were
	# unmountable due to the network not being up.
	a=`/bin/grep -v '^#' /etc/fstab | /bin/grep -E "ftp|nfs|nfs4|smbfs|cifs|ncp|ncpfs|coda|ocfs2|gfs" | /usr/bin/awk '{print $1}'`
	for i in $a; do
		log_daemon_msg "Mounting: $i                                 "
		mount $i
		ES_TO_REPORT=$?
		if [ 0 = "$ES_TO_REPORT" ]
		then
			log_action_end_msg 0
		else
			log_action_end_msg 1 "code $ES_TO_REPORT"
		fi
	done
esac
openvpn-unmount
Code:
#!/bin/sh 

#
# openvpn-unmount
#
# This script is designed to unmount the currently mounted
# networked filesystems BEFORE the network is brought down.
#

# Find all networked filesystems.  Currently looks for
# nfs and cifs mounted filesystems 

a=`/bin/df -PT | /bin/grep -E "nfs|nfs4|smbfs|cifs|ncp|ncpfs|coda|ocfs2|gfs" | /usr/bin/awk '{print $7}'`

/bin/umount $a

exit 0
installation log:
Code:
root@raspberrypi:/openvpn_fix# ./setup-openvpn-mounts.sh
What are the VPN interfaces (ie:  tap0,  tun0)
Enter all the VPN interfaces separated by spaces: tun0
update-rc.d: using dependency based boot sequencing
insserv: warning: script 'S19openvpn-unmount' missing LSB tags and overrides
insserv: warning: script 'openvpn-unmount' missing LSB tags and overrides
update-rc.d: using dependency based boot sequencing
insserv: warning: script 'S01openvpn-unmount' missing LSB tags and overrides
insserv: warning: script 'openvpn-unmount' missing LSB tags and overrides
update-rc.d: using dependency based boot sequencing
insserv: warning: script 'S01openvpn-unmount' missing LSB tags and overrides
insserv: warning: script 'openvpn-unmount' missing LSB tags and overrides
update-rc.d: using dependency based boot sequencing
update-rc.d: warning:  start runlevel arguments (S) do not match openvpn Default-Start values (2 3 4 5)
update-rc.d: warning:  stop runlevel arguments (S) do not match openvpn Default-Stop values (0 1 6)
insserv: warning: script 'openvpn-unmount' missing LSB tags and overrides
update-rc.d: using dependency based boot sequencing
update-rc.d: warning:  start runlevel arguments (S) do not match openvpn-wait4active Default-Start values (2 3 4 5)
update-rc.d: warning:  stop runlevel arguments (S) do not match openvpn-wait4active Default-Stop values (0 1 6)
insserv: warning: script 'openvpn-unmount' missing LSB tags and overrides
Thank you for your effort.

Last edited by matb; 07-01-2015 at 10:58 AM.
 
Old 07-03-2015, 07:59 AM   #2
matb
LQ Newbie
 
Registered: Jul 2015
Posts: 5

Original Poster
Rep: Reputation: Disabled
no one?
 
Old 07-03-2015, 08:40 AM   #3
paul2015
Member
 
Registered: Apr 2015
Distribution: CentOS Fedora
Posts: 149

Rep: Reputation: 4
you whant when openvpn connection is established to automount nfs or ftp? and unmount on when openvpn disconnects?

Last edited by paul2015; 07-03-2015 at 08:42 AM.
 
Old 07-03-2015, 08:52 AM   #4
matb
LQ Newbie
 
Registered: Jul 2015
Posts: 5

Original Poster
Rep: Reputation: Disabled
Yes, I want to mount my ftp server, the mounting on boot is a problem right now. The script that I found also unmount before shutting down, but I don't know it's necessary.
 
Old 07-03-2015, 08:55 AM   #5
paul2015
Member
 
Registered: Apr 2015
Distribution: CentOS Fedora
Posts: 149

Rep: Reputation: 4
i am sorry write whole prosedure what you whant to mount from where and why. why mount ftp through vpn?
 
Old 07-06-2015, 09:42 AM   #6
matb
LQ Newbie
 
Registered: Jul 2015
Posts: 5

Original Poster
Rep: Reputation: Disabled
On Linux, if an ftp filesystem is auto-mounted over the VPN, a race condition can occur where the system will try to mount all the auto-mount filesystems BEFORE OpenVPN is started. This cause a hang and the ftp filesystem will be not mounted at startup. Whole my system communicates over OpenVPN, so I want to mount my ftp over OpenVPN.
 
  


Reply



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
Connection OpenVPN with IPSec eugen55ro Linux - Security 4 01-23-2012 09:05 AM
[SOLVED] OpenVPN slows down connection Cenobite Linux - Networking 2 08-21-2010 09:57 AM
openvpn connection A - B via C MarioT Linux - Networking 1 01-22-2009 09:01 AM
what is the CA files in the openvpn connection ? . adam_blackice Linux - Networking 1 08-07-2007 11:13 AM
OpenVPN Connection Issue ArcLinux Linux - Networking 1 06-08-2007 04:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 09:19 PM.

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
Open Source Consulting | Domain Registration