Hi,
Setup and use case:
I have a Raspberry Pi 2 Model B on Rasbian Jessie running an OpenVPN 2.3.4 client as root. I am currently doing the following manually, but I want to automate it:
1. I launch the OpenVPN client and successfully establish a connection to the OpenVPN server.
2. I run "sudo sh /home/osmc/openvpn/up.sh" at client's command line, which runs the following script and successfully mounts the server's samba share. Here are the contents of the up.sh script:
#!/bin/bash
mount -t cifs -o username=removed,password=removed,uid=1000,gid=1000 //10.99.99.120/samba/ /mnt
3. After I am done with moving files to/from the samba share, I run a different script "sudo sh /home/osmc/openvpn/down.sh" and sucessfuly unmount the server's samba share. Here are the contents of the down.sh script:
#!/bin/bash
umount /mnt
4. Finally I manually disconnect the OpenVPN client and quit.
Goal:
I want to automate this process by running the up.sh script after the openvpn connection is established and the down.sh script before the the disconnection is initiated. As you can see in the client config below, I have the security/up/down lines in there and I tried running those, but unsuccessfully - in the openvpn log I see that the the up.sh is started but never mounts the share hence openvpn crashes fatally. It seems that by design the up script runs too early so samba share is not visible/mountable yet, and the down script runs too late so the disconnection has already happened and the samba share was not visible anymore/not properly unmounted. I must repeat that openvpn is run by root and both scripts are 755.
Question:
Can someone please suggest a solution to this? Thanks and fingers crossed.
client.ovpn
client
dev tun
management localhost 1337
askpass /home/osmc/openvpn/privatekeypassword.pass
proto udp
remote removed.com 1194
resolv-retry infinite
nobind
persist-key
persist-tun
mute-replay-warnings
ns-cert-type server
key-direction 1
cipher AES-128-CBC
comp-lzo
verb 1
mute 20
script-security 2
up /home/osmc/openvpn/up.sh
down /home/osmc/openvpn/down.sh
<ca>
-----BEGIN CERTIFICATE-----
removed
-----END CERTIFICATE-----
</ca>
<cert>
-----BEGIN CERTIFICATE-----
removed
-----END RSA PRIVATE KEY-----
</key>
<tls-auth>
#
# 2048 bit OpenVPN static key
#
-----BEGIN OpenVPN Static key V1-----
removed
-----END OpenVPN Static key V1-----
</tls-auth>