Tag Archives: openvpn

Systemd: opevpn init script

create file /lib/systemd/system/ovpn.service

1
2
3
[Unit]
Description=OpenVPN to home
After=network.target

[Service]
Type=forking
PIDFile=/var/run/ovpn.pid
ExecStart=/usr/sbin/openvpn --daemon --cd /home/alter/ovpn/ --config ovpn.conf
Restart=always
RestartSec=60
ExecStop=killall -9 openvpn

[Install]
WantedBy=default.target

where

1
--cd /home/alter/ovpn/

is a path to folder with ovpn.conf

1
--config ovpn.conf

is a config file of openvpn client.

Fedora: runscript (example: openvpn client)

/etc/init.d/opevpn-home-client

#!/bin/bash
#
# Run-level Startup script for the OpenVPN client
#
# chkconfig: 345 91 19
# description: Startup/Shutdown OpenVPN client 
OVPN_HOME="/home/alter/ovpn/"
case "$1" in
    start)
        echo -n "Starting OpenVPN home client: "
        cd $OVPN_HOME && /usr/sbin/openvpn ovpn.conf
        echo "OK"
        ;;
    stop)
        echo -n "Shutdown OpenVPN home client: "
        killall openvpn
        echo "OK"
        ;;
    reload|restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 start|stop|restart"
        exit 1
esac
exit 0
chmod +x /etc/init.d/opevpn-home-client
chkconfig --add openvpn-home-client