NETGEAR is aware of a growing number of phone and online scams. To learn how to stay safe click here.

Forum Discussion

Retired_Member's avatar
Retired_Member
Mar 17, 2017
Solved

OPENVPN autologin on boot (script dosn't start)

Hi,

I have a problem with autologin OPENVPN on RN102 boot. I will describe what I have already done, and plese check what is wrong or what I omitted.

1. I have prepared VPS and open VPN server on provider device. Everything is configured and works with Windows komputer

2. OPENVPN is installed on RN102, config file and pass.txt is in /etc/openvpn (when I use command:

openvpn --config /etc/openvpn/readynas.ovpn

I get connetions and it works OK.

3. To set autostart I changed settings in /etc/default/openvpn to: AUTOSTART="all"

But whe I boot my RN102, client is not connected, again when I use command: openvpn --config /etc/openvpn/readynas.ovpn

I get connections.

 

Why openvpn is not connecting on boot?

 

I even prepared script to be start on boot, automatically:

 

 

openvpn_start.sh

#!/bin/sh
touch /root/PK_KOMP__$(date +%y-%m-%d-godz.%H:%M:%S)
openvpn --config /etc/openvpn/readynas.ovpn

To check is working or not, i prepared test line (and I see that line 2 is done, so script works, but still openvpn not connects)

 

script is copied to:

/etc/init.d/

 

setting are:

update-rc.d openvpn_start.sh defaults

 

But still nothing on boot.

 

On other debian I tried with rc.local and it works correctly:

rc.local.png

  • The script for /etc/init.d/ should be in specific format. Move your openvpn_start.sh into /root/ folder.

    Create new script  /etc/init.d/openvpn_start  (without extention). Change script root permissions to executable

     

     openvpn_start script

    #!/bin/sh
    ### BEGIN INIT INFO
    # Provides: check_pseudo_UPS
    # Required-Start: $local_fs $network $named $time $syslog
    # Required-Stop: $local_fs $network $named $time $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Description: check_pseudo_UPS the default ReadyNAS UPS control
    ### END INIT INFO
    
    SCRIPT=~/openvpn_start.sh
    RUNAS=root
    
    PIDFILE=/var/run/openvpn_start.pid
    LOGFILE=/var/log/openvpn_start.log
    
    start() {
    if [ -f /var/run/$PIDNAME ] && kill -0 $(cat /var/run/$PIDNAME); then
    echo 'Service already running' >&2
    return 1
    fi
    echo 'Starting service.' >&2
    local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
    su -c "$CMD" $RUNAS > "$PIDFILE"
    echo 'Service started' >&2
    }
    
    stop() {
    if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
    echo 'Service not running' >&2
    return 1
    fi
    echo 'Stopping service.' >&2
    kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
    echo 'Service stopped' >&2
    }
    
    uninstall() {
    echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
    local SURE
    read SURE
    if [ "$SURE" = "yes" ]; then
    stop
    rm -f "$PIDFILE"
    echo "Notice: log file is not be removed: '$LOGFILE'" >&2
    update-rc.d -f <NAME> remove
    rm -fv "$0"
    fi
    }
    
    case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    uninstall)
    uninstall
    ;;
    restart)
    stop
    start
    ;;
    *)
    echo "Usage: $0 {start|stop|restart|uninstall}"
    esac

     

    --add script from /etc/init.d to autostart
    # update-rc.d openvpn_start defaults
    --or
    # insserv openvpn_start

     

    --start service
    # /etc/init.d/openvpn_start start
    # /etc/init.d/openvpn_start restart

     

    --stop service
    # /etc/init.d/openvpn_start stop

     

    --check service status
    #systemctl status openvpn_start

     

9 Replies

Replies have been turned off for this discussion
  • The script for /etc/init.d/ should be in specific format. Move your openvpn_start.sh into /root/ folder.

    Create new script  /etc/init.d/openvpn_start  (without extention). Change script root permissions to executable

     

     openvpn_start script

    #!/bin/sh
    ### BEGIN INIT INFO
    # Provides: check_pseudo_UPS
    # Required-Start: $local_fs $network $named $time $syslog
    # Required-Stop: $local_fs $network $named $time $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Description: check_pseudo_UPS the default ReadyNAS UPS control
    ### END INIT INFO
    
    SCRIPT=~/openvpn_start.sh
    RUNAS=root
    
    PIDFILE=/var/run/openvpn_start.pid
    LOGFILE=/var/log/openvpn_start.log
    
    start() {
    if [ -f /var/run/$PIDNAME ] && kill -0 $(cat /var/run/$PIDNAME); then
    echo 'Service already running' >&2
    return 1
    fi
    echo 'Starting service.' >&2
    local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
    su -c "$CMD" $RUNAS > "$PIDFILE"
    echo 'Service started' >&2
    }
    
    stop() {
    if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
    echo 'Service not running' >&2
    return 1
    fi
    echo 'Stopping service.' >&2
    kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
    echo 'Service stopped' >&2
    }
    
    uninstall() {
    echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
    local SURE
    read SURE
    if [ "$SURE" = "yes" ]; then
    stop
    rm -f "$PIDFILE"
    echo "Notice: log file is not be removed: '$LOGFILE'" >&2
    update-rc.d -f <NAME> remove
    rm -fv "$0"
    fi
    }
    
    case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    uninstall)
    uninstall
    ;;
    restart)
    stop
    start
    ;;
    *)
    echo "Usage: $0 {start|stop|restart|uninstall}"
    esac

     

    --add script from /etc/init.d to autostart
    # update-rc.d openvpn_start defaults
    --or
    # insserv openvpn_start

     

    --start service
    # /etc/init.d/openvpn_start start
    # /etc/init.d/openvpn_start restart

     

    --stop service
    # /etc/init.d/openvpn_start stop

     

    --check service status
    #systemctl status openvpn_start

     

    • Retired_Member's avatar
      Retired_Member

      After reboot, stsill no connection... logs of starting below:

      root@nas-36-0D-9D:~# systemctl status openvpn_start
      ● openvpn_start.service - LSB: check_pseudo_UPS the default ReadyNAS UPS control
         Loaded: loaded (/etc/init.d/openvpn_start; generated; vendor preset: enabled)
         Active: active (exited) since Fri 2017-03-17 14:16:05 CET; 6min ago
           Docs: man:systemd-sysv-generator(8)
         CGroup: /system.slice/openvpn_start.service
      
      Mar 17 14:16:04 nas-36-0D-9D systemd[1]: Starting LSB: check_pseudo_UPS the default ReadyNAS UPS control...
      Mar 17 14:16:04 nas-36-0D-9D openvpn_start[2144]: Starting service.
      Mar 17 14:16:05 nas-36-0D-9D su[2147]: Successful su for root by root
      Mar 17 14:16:05 nas-36-0D-9D su[2147]: + ??? root:root
      Mar 17 14:16:05 nas-36-0D-9D su[2147]: pam_unix(su:session): session opened for user root by (uid=0)
      Mar 17 14:16:05 nas-36-0D-9D su[2147]: pam_unix(su:session): session closed for user root
      Mar 17 14:16:05 nas-36-0D-9D openvpn_start[2144]: Service started
      Mar 17 14:16:05 nas-36-0D-9D systemd[1]: Started LSB: check_pseudo_UPS the default ReadyNAS UPS control.
      Warning: openvpn_start.service changed on disk. Run 'systemctl daemon-reload' to reload units.
      root@nas-36-0D-9D:~#
      root@nas-36-0D-9D:~# systemctl daemon-reload
      root@nas-36-0D-9D:~# systemctl status openvpn_start
      ● openvpn_start.service - LSB: check_pseudo_UPS the default ReadyNAS UPS control
         Loaded: loaded (/etc/init.d/openvpn_start; generated; vendor preset: enabled)
         Active: active (exited) since Fri 2017-03-17 14:16:05 CET; 6min ago
           Docs: man:systemd-sysv-generator(8)
         CGroup: /system.slice/openvpn_start.service
      
      Mar 17 14:16:04 nas-36-0D-9D systemd[1]: Starting LSB: check_pseudo_UPS the default ReadyNAS UPS control...
      Mar 17 14:16:04 nas-36-0D-9D openvpn_start[2144]: Starting service.
      Mar 17 14:16:05 nas-36-0D-9D su[2147]: Successful su for root by root
      Mar 17 14:16:05 nas-36-0D-9D su[2147]: + ??? root:root
      Mar 17 14:16:05 nas-36-0D-9D su[2147]: pam_unix(su:session): session opened for user root by (uid=0)
      Mar 17 14:16:05 nas-36-0D-9D su[2147]: pam_unix(su:session): session closed for user root
      Mar 17 14:16:05 nas-36-0D-9D openvpn_start[2144]: Service started
      Mar 17 14:16:05 nas-36-0D-9D systemd[1]: Started LSB: check_pseudo_UPS the default ReadyNAS UPS control.
      root@nas-36-0D-9D:~#

       

      After next reboot still, service is on, but not connectin:

      on.PNG

      Additionally openvpnservice is ON

      on2.PNG

      so is should autoconnect as I have marked in config:

      resolv-retry infinite
      • sotrack's avatar
        sotrack
        Luminary

        My script check_pseudo_UPS was updated to openvpn_start.

        Replace in script comments check_pseudo_UPS to openvpn_start self. This is important.

        Don't reboot NAS. Just check with command

        # /etc/init.d/openvpn_start restart

NETGEAR Academy

Boost your skills with the Netgear Academy - Get trained, certified and stay ahead with the latest Netgear technology! 

Join Us!

ProSupport for Business

Comprehensive support plans for maximum network uptime and business peace of mind.

 

Learn More