How to auto-start OpenVPN client in Debian 6 and Ubuntu 12.04

I had this huge problem – my Debian desktop did not reconnect to the VPN on reboot so here is a small how-to what needs to be done :).

Assumptions: You have working installation of OpenVPN client so when you are in /etc/openvpn and type: openvpn client.conf , where your client.conf contains configuration data it does connect without any problems. So now your only problem is – you have to write it every time you need OpenVPN to be connected and this is going to be solved by this howto.

1) Create file  myopenvpn in  /etc/init.d/

nano /etc/init.d/myopenvpn

2) Insert into myopenvpn and save:

# OpenVPN autostart on boot script

start on runlevel [2345]
stop on runlevel [!2345]

respawn

exec /usr/sbin/openvpn --status /var/run/openvpn.client.status 10 --cd /etc/openvpn --config /etc/openvpn/client.conf --syslog openvpn

3) Reboot the machine
4) Profit! :)