X-Original-To: alpine-devel@lists.alpinelinux.org Delivered-To: alpine-devel@lists.alpinelinux.org Received: from zimbra.netvantix.net (zimbra.netvantix.net [67.213.231.181]) by lists.alpinelinux.org (Postfix) with ESMTP id A9B1F1EBFF7 for ; Thu, 9 Dec 2010 18:36:54 +0000 (UTC) Received: from localhost (localhost.localdomain [127.0.0.1]) by zimbra.netvantix.net (Postfix) with ESMTP id 030DB258231 for ; Thu, 9 Dec 2010 11:36:54 -0700 (MST) X-Virus-Scanned: amavisd-new at zimbra.netvantix.net Received: from zimbra.netvantix.net ([127.0.0.1]) by localhost (zimbra.netvantix.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Re8O+2JdKh2z for ; Thu, 9 Dec 2010 11:36:49 -0700 (MST) Received: from zimbra.netvantix.net (zimbra.netvantix.net [67.213.231.181]) by zimbra.netvantix.net (Postfix) with ESMTP id 34F5C25822F for ; Thu, 9 Dec 2010 11:36:49 -0700 (MST) Date: Thu, 9 Dec 2010 11:36:49 -0700 (MST) From: Steve Fink To: Alpine-Devel Message-ID: <13375983.3972.1291919809136.JavaMail.root@zimbra.netvantix.net> In-Reply-To: <29574620.3969.1291919686920.JavaMail.root@zimbra.netvantix.net> Subject: [alpine-devel] OpenVPN Multiple Tunnels X-Mailinglist: alpine-devel Precedence: list List-Id: Alpine Development List-Unsubscribe: List-Post: List-Help: List-Subscribe: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_3971_30917909.1291919809135" X-Originating-IP: [174.52.152.3] X-Mailer: Zimbra 6.0.3_GA_1915.RHEL4 (ZimbraWebClient - SAF3 (Mac)/6.0.3_GA_1915.RHEL4) ------=_Part_3971_30917909.1291919809135 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Hello everyone, I am new to alpinelinux but I've been using OpenVPN for years. The init script that is included in alpinelinux is a Gentoo init script. There is a bug in Gentoo that requires the OpenVPN config file to be named openvpn.conf and essentially prevents multiple tunnels ie Server and Client. There are several work arounds by doing some symbolic links and such but the problem is with the init script. Below is an init script that will fix this. I can get the script to stay in /etc/init.d after a reboot by including it in the lbu include but it will not auto start despite the fact that I have openvpn in the default runlevel and the permissions are 755. Can anyone point me in the right direction as to make sure the lbu included version starts automatically? I would prefer not to have to place it in an rc.local file. Thanks, Steve #!/bin/sh -e # # Original version by Robert Leslie # , edited by iwj and cs # Modified for openvpn by Alberto Gonzalez Iniesta # Modified for restarting / starting / stopping single tunnels by Richard Mueller # Modified for AlpineLinux by Steve Fink RCDLINKS="0,K20 1,K20 2,S20 3,S20 4,S20 5,S20 6,K20" DAEMON=/usr/sbin/openvpn DESC="OpenVPN Daemon" CONFIG_DIR=/etc/openvpn test -x $DAEMON || exit 0 test -d $CONFIG_DIR || exit 0 # Source defaults file; edit that file to configure this script. # AlpineLinux currently does not use /etc/default so we explicitly # set auto start to all files with .conf AUTOSTART="all" STATUSREFRESH=10 if test -e /etc/default/openvpn ; then . /etc/default/openvpn fi start_vpn () { if grep -q '^[ ]*daemon' $CONFIG_DIR/$NAME.conf ; then # daemon already given in config file DAEMONARG= else # need to daemonize DAEMONARG="--daemon ovpn-$NAME" fi if grep -q '^[ ]*status ' $CONFIG_DIR/$NAME.conf ; then # status file already given in config file STATUSARG="" elif test $STATUSREFRESH -eq 0 ; then # default status file disabled in /etc/default/openvpn STATUSARG="" else # prepare default status file STATUSARG="--status /var/run/openvpn.$NAME.status $STATUSREFRESH" fi echo -n " $NAME" STATUS="OK" $DAEMON --writepid /var/run/openvpn.$NAME.pid \ $DAEMONARG $STATUSARG --cd $CONFIG_DIR \ --config $CONFIG_DIR/$NAME.conf < /dev/null || STATUS="FAILED" echo -n "($STATUS)" } stop_vpn () { kill `cat $PIDFILE` || true rm $PIDFILE rm -f /var/run/openvpn.$NAME.status 2> /dev/null } case "$1" in start) echo -n "Starting $DESC:" # autostart VPNs if test -z "$2" ; then # check if automatic startup is disabled by AUTOSTART=none if test "x$AUTOSTART" = "xnone" -o -z "$AUTOSTART" ; then echo " Autostart disabled." exit 0 fi if test -z "$AUTOSTART" -o "x$AUTOSTART" = "xall" ; then # all VPNs shall be started automatically for CONFIG in `cd $CONFIG_DIR; ls *.conf 2> /dev/null`; do NAME=${CONFIG%%.conf} start_vpn done else # start only specified VPNs for NAME in $AUTOSTART ; do if test -e $CONFIG_DIR/$NAME.conf ; then start_vpn else echo -n " (failure: No such VPN: $NAME)" fi done fi #start VPNs from command line else while shift ; do [ -z "$1" ] && break if test -e $CONFIG_DIR/$1.conf ; then NAME=$1 start_vpn else echo -n " (failure: No such VPN: $1)" fi done fi echo "." ;; stop) echo -n "Stopping $DESC:" if test -z "$2" ; then for PIDFILE in `ls /var/run/openvpn.*.pid 2> /dev/null`; do NAME=`echo $PIDFILE | cut -c18-` NAME=${NAME%%.pid} stop_vpn echo -n " $NAME" done else while shift ; do [ -z "$1" ] && break if test -e /var/run/openvpn.$1.pid ; then PIDFILE=`ls /var/run/openvpn.$1.pid 2> /dev/null` NAME=`echo $PIDFILE | cut -c18-` NAME=${NAME%%.pid} stop_vpn echo -n " $NAME" else echo -n " (failure: No such VPN is running: $1)" fi done fi echo "." ;; # We only 'reload' for running VPNs. New ones will only start with 'start' or 'restart'. reload|force-reload) echo -n "Reloading $DESC:" for PIDFILE in `ls /var/run/openvpn.*.pid 2> /dev/null`; do NAME=`echo $PIDFILE | cut -c18-` NAME=${NAME%%.pid} # If openvpn if running under a different user than root we'll need to restart if egrep '^( |\t)*user' $CONFIG_DIR/$NAME.conf > /dev/null 2>&1 ; then stop_vpn sleep 1 start_vpn echo -n "(restarted)" else kill -HUP `cat $PIDFILE` || true echo -n " $NAME" fi done echo "." ;; restart) shift $0 stop ${@} sleep 1 $0 start ${@} ;; cond-restart) echo -n "Restarting $DESC:" for PIDFILE in `ls /var/run/openvpn.*.pid 2> /dev/null`; do NAME=`echo $PIDFILE | cut -c18-` NAME=${NAME%%.pid} stop_vpn sleep 1 start_vpn done echo "." ;; *) echo "Usage: $0 {start|stop|reload|restart|force-reload|cond-restart}" >&2 exit 1 ;; esac exit 0 ------=_Part_3971_30917909.1291919809135 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable <= div style=3D'font-family: Times New Roman; font-size: 12pt; color: #000000'= >Hello everyone,

I am new to alpinelinux but I've been u= sing OpenVPN for years.
The init script that is included in alpinelinux= is a Gentoo init script.
There is a bug in Gentoo that requires = the OpenVPN config file to be named openvpn.conf and essentially prevents m= ultiple tunnels ie Server and Client. There are several work arounds by doi= ng some symbolic links and such but the problem is with the init script.

Below is an init script that will fix this. I can ge= t the script to stay in /etc/init.d after a reboot by including it in the l= bu include but it will not auto start despite the fact that I have openvpn = in the default runlevel and the permissions are 755.

Can anyone point me in the right direction as to make sure the lbu inclu= ded version starts automatically?

I would prefer n= ot to have to place it in an rc.local file.

Thanks= ,

Steve


#!/bin/sh -e
#
# Original version by Robert Leslie
# <rob@mars.org>, edited by iwj and cs
# Modified = for openvpn by Alberto Gonzalez Iniesta <agi@inittab.org>
#= Modified for restarting / starting / stopping single tunnels by Richard Mu= eller <mueller@teamix.net>
# Modified for AlpineLinux by St= eve Fink <sfink@netvantix.com>
RCDLINKS=3D"0,K20 1,K20 2,S2= 0 3,S20 4,S20 5,S20 6,K20"

DAEMON=3D/usr/sbin/open= vpn
DESC=3D"OpenVPN Daemon"
CONFIG_DIR=3D/etc/openvpn
test -x $DAEMON || exit 0
test -d $CONFIG_DIR || exit 0<= /div>

# Source defaults file; edit that file to configur= e this script.
# AlpineLinux currently does not use /etc/default = so we explicitly
# set auto start to all files with .conf
AUTOSTART=3D"all"
STATUSREFRESH=3D10
if test -e /etc= /default/openvpn ; then
  . /etc/default/openvpn
<= div>fi

start_vpn () {
    = ;if grep -q '^[=09= ]*daemon' $CONFIG_DIR/$NAME.conf ; then
   &nbs= p;  # daemon already given in config file
    = ;  DAEMONARG=3D
    else
 &nbs= p;    # need to daemonize
      DAE= MONARG=3D"--daemon ovpn-$NAME"
    fi
    if grep -q '^[=09 ]*status ' $CONFIG_DIR/$NAME.conf ; = then
      # status file already given in con= fig file
      STATUSARG=3D""
 = ;   elif test $STATUSREFRESH -eq 0 ; then
   =    # default status file disabled in /etc/default/openvpn
      STATUSARG=3D""
    el= se
      # prepare default status file
<= div>      STATUSARG=3D"--status /var/run/openvpn.$NAME.= status $STATUSREFRESH"
    fi

=
    echo -n " $NAME"
    STATU= S=3D"OK"

    $DAEMON --writepid /va= r/run/openvpn.$NAME.pid \
          = ;  $DAEMONARG $STATUSARG --cd $CONFIG_DIR \
   &nb= sp;        --config $CONFIG_DIR/$NAME.conf < /dev/nu= ll || STATUS=3D"FAILED"
    echo -n "($STATUS)"
}
stop_vpn () {
  kill `cat $PIDFILE`= || true
  rm $PIDFILE
  rm -f /var= /run/openvpn.$NAME.status 2> /dev/null
}

<= div>case "$1" in
start)
  echo -n "Starting $= DESC:"

  # autostart VPNs
&nbs= p; if test -z "$2" ; then
    # check if auto= matic startup is disabled by AUTOSTART=3Dnone
    = if test "x$AUTOSTART" =3D "xnone" -o -z "$AUTOSTART" ; then
 = ;     echo " Autostart disabled."
   &nb= sp;  exit 0
    fi
   &nb= sp;if test -z "$AUTOSTART" -o "x$AUTOSTART" =3D "xall" ; then
&nb= sp;     # all VPNs shall be started automatically
=       for CONFIG in `cd $CONFIG_DIR; ls *.conf 2> /d= ev/null`; do
        NAME=3D${CONFIG%%.c= onf}
        start_vpn
 &= nbsp;    done
    else
 &= nbsp;    # start only specified VPNs
    = ;  for NAME in $AUTOSTART ; do
       &n= bsp;if test -e $CONFIG_DIR/$NAME.conf ; then
     =      start_vpn
        el= se
          echo -n " (failure: No= such VPN: $NAME)"
        fi
=       done
    fi
&n= bsp; #start VPNs from command line
  else
    while shift ; do
      [= -z "$1" ] && break
      if test -e = $CONFIG_DIR/$1.conf ; then
        NAME= =3D$1
        start_vpn
 =      else
        echo -n= " (failure: No such VPN: $1)"
      fi
=
    done
  fi
  = ;echo "."

  ;;
stop)
  echo -n "Stopping $DESC:"

  = ;if test -z "$2" ; then
    for PIDFILE in `ls /va= r/run/openvpn.*.pid 2> /dev/null`; do
     &nbs= p;NAME=3D`echo $PIDFILE | cut -c18-`
      NA= ME=3D${NAME%%.pid}
      stop_vpn
&= nbsp;     echo -n " $NAME"
    done=
  else
    while shift ; do
      [ -z "$1" ] && break
&= nbsp;     if test -e /var/run/openvpn.$1.pid ; then
        PIDFILE=3D`ls /var/run/openvpn.$1.pid 2&= gt; /dev/null`
        NAME=3D`echo $PID= FILE | cut -c18-`
        NAME=3D${NAME%= %.pid}
        stop_vpn
 =        echo -n " $NAME"
     &= nbsp;else
        echo -n " (failure: No= such VPN is running: $1)"
      fi
    done
  fi
  ech= o "."
  ;;
# We only 'reload' for running VPN= s. New ones will only start with 'start' or 'restart'.
reload|for= ce-reload)
  echo -n "Reloading $DESC:"
 = ; for PIDFILE in `ls /var/run/openvpn.*.pid 2> /dev/null`; do
=
    NAME=3D`echo $PIDFILE | cut -c18-`
 =    NAME=3D${NAME%%.pid}
# If openvpn if running under a= different user than root we'll need to restart
   &nbs= p;if egrep '^( |\t)*user' $CONFIG_DIR/$NAME.conf > /dev/null 2>&1= ; then
      stop_vpn
  =    sleep 1
      start_vpn
      echo -n "(restarted)"
   &= nbsp;else
      kill -HUP `cat $PIDFILE` || t= rue
    echo -n " $NAME"
   &n= bsp;fi
  done
  echo "."
=   ;;

restart)
  shif= t
  $0 stop ${@}
  sleep 1
  $0 start ${@}
  ;;
cond-restart= )
  echo -n "Restarting $DESC:"
  f= or PIDFILE in `ls /var/run/openvpn.*.pid 2> /dev/null`; do
&nb= sp;   NAME=3D`echo $PIDFILE | cut -c18-`
   &= nbsp;NAME=3D${NAME%%.pid}
    stop_vpn
&= nbsp;   sleep 1
    start_vpn
=   done
  echo "."
  ;;
*)
  echo "Usage: $0 {start|stop|reload|restart= |force-reload|cond-restart}" >&2
  exit 1
<= div>  ;;
esac

exit 0

------=_Part_3971_30917909.1291919809135-- --- Unsubscribe: alpine-devel+unsubscribe@lists.alpinelinux.org Help: alpine-devel+help@lists.alpinelinux.org ---