Mon, 28 Jan 2013 17:37:18 +0100
Correct socket error reporting improvement with IPv6 portable code,
after helpful recommendation by Saúl Ibarra Corretgé on OSips devlist.
1 #!@l_prefix@/bin/openpkg rc
2 ##
3 ## rc.openvpn -- Run-Commands
4 ##
6 %config
7 openvpn_enable="$openpkg_rc_def"
8 openvpn_log_prolog="true"
9 openvpn_log_epilog="true"
10 openvpn_log_numfiles="10"
11 openvpn_log_minsize="1M"
12 openvpn_log_complevel="9"
14 %common
15 openvpn_etcdir="@l_prefix@/etc/openvpn"
16 openvpn_vardir="@l_prefix@/var/openvpn"
17 openvpn_signal () {
18 [ -f $openvpn_vardir/$1.pid ] && kill -$2 `cat $openvpn_vardir/$1.pid`
19 }
21 %status -u @l_susr@ -o
22 openvpn_usable="unknown"
23 openvpn_active="yes"
24 if rcService openvpn enable yes; then
25 for cfgfile in $openvpn_etcdir/*.conf; do
26 [ ".`grep '^disable' $cfgfile`" != . ] && continue
27 name=`echo "$cfgfile" | sed -e 's;^.*/\([^/]*\)\.conf;\1;'`
28 openvpn_signal $name 0
29 if [ $? -ne 0 ]; then
30 openvpn_active="no"
31 break
32 fi
33 done
34 fi
35 echo "openvpn_enable=\"$openvpn_enable\""
36 echo "openvpn_usable=\"$openvpn_usable\""
37 echo "openvpn_active=\"$openvpn_active\""
39 %start -p 200 -u @l_susr@
40 rcService openvpn enable yes || exit 0
41 rcService openvpn active yes && exit 0
42 if [ -f $openvpn_etcdir/openvpn.sh ]; then
43 sh $openvpn_etcdir/openvpn.sh start || exit $?
44 fi
45 for cfgfile in $openvpn_etcdir/*.conf; do
46 [ ".`grep '^disable' $cfgfile`" != . ] && continue
47 name=`echo "$cfgfile" | sed -e 's;^.*/\([^/]*\)\.conf;\1;'`
48 if [ -f $openvpn_etcdir/$name.sh -a ".$name" != .openvpn ]; then
49 sh $openvpn_etcdir/$name.sh start || exit $?
50 fi
51 @l_prefix@/sbin/openvpn \
52 --daemon "$name" \
53 --log-append $openvpn_vardir/$name.log \
54 --writepid $openvpn_vardir/$name.pid \
55 --status $openvpn_vardir/$name.status 60 \
56 --config $cfgfile \
57 --cd $openvpn_etcdir || exit $?
58 done
60 %stop -p 800 -u @l_susr@
61 rcService openvpn enable yes || exit 0
62 rcService openvpn active no && exit 0
63 for cfgfile in $openvpn_etcdir/*.conf; do
64 [ ".`grep '^disable' $cfgfile`" != . ] && continue
65 name=`echo "$cfgfile" | sed -e 's;^.*/\([^/]*\)\.conf;\1;'`
66 openvpn_signal $name TERM
67 done
68 sleep 1
69 for cfgfile in $openvpn_etcdir/*.conf; do
70 [ ".`grep '^disable' $cfgfile`" != . ] && continue
71 name=`echo "$cfgfile" | sed -e 's;^.*/\([^/]*\)\.conf;\1;'`
72 if [ -f $openvpn_etcdir/$name.sh -a ".$name" != .openvpn ]; then
73 sh $openvpn_etcdir/$name.sh stop || true
74 fi
75 done
76 if [ -f $openvpn_etcdir/openvpn.sh ]; then
77 sh $openvpn_etcdir/openvpn.sh stop || true
78 fi
79 rm -f $openvpn_vardir/*.pid 2>/dev/null || true
81 %restart -u @l_susr@
82 rcService openvpn enable yes || exit 0
83 rcService openvpn active no && exit 0
84 rc openvpn stop start
86 %reload -u @l_susr@
87 rcService openvpn enable yes || exit 0
88 rcService openvpn active no && exit 0
89 for cfgfile in $openvpn_etcdir/*.conf; do
90 [ ".`grep '^disable' $cfgfile`" != . ] && continue
91 name=`echo "$cfgfile" | sed -e 's;^.*/\([^/]*\)\.conf;\1;'`
92 openvpn_signal $name USR1
93 if [ -f $openvpn_etcdir/$name.sh ]; then
94 sh $openvpn_etcdir/$name.sh reload || true
95 fi
96 done
98 %daily -u @l_susr@
99 rcService openvpn enable yes || exit 0
100 for cfgfile in $openvpn_etcdir/*.conf; do
101 [ ".`grep '^disable' $cfgfile`" != . ] && continue
102 name=`echo "$cfgfile" | sed -e 's;^.*/\([^/]*\)\.conf;\1;'`
103 shtool rotate -f \
104 -n ${openvpn_log_numfiles} -s ${openvpn_log_minsize} -d \
105 -z ${openvpn_log_complevel} -o @l_rusr@ -g @l_rgrp@ -m 644 \
106 -P "${openvpn_log_prolog}" \
107 -E "${openvpn_log_epilog}; rc openvpn reload" \
108 $openvpn_vardir/$name.log
109 done