3 # OCF resource agent for PPP connection
5 # License: GNU General Public License version 2 (GPL2)
6 # (c) 2017 Tatsuki Sugiura <sugi@nemui.org> and OSDN Corporation <tech@osdn.jp>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of version 2 of the GNU General Public License as
10 # published by the Free Software Foundation.
12 # This program is distributed in the hope that it would be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 # Further, this software is distributed without any warranty that it is
17 # free of the rightful claim of any third person regarding infringement
18 # or the like. Any license provided herein, whether implied or
19 # otherwise, applies only to this software file. Patent licenses, if
20 # any, provided herein do not apply to combinations of this program with
21 # other software, or any other product whatsoever.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write the Free Software Foundation,
25 # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
29 : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
30 . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
31 . ${OCF_FUNCTIONS_DIR}/findif.sh
34 OCF_RESKEY_expected_ip4_default=""
35 OCF_RESKEY_expected_ip6_default=""
36 OCF_RESKEY_isp_default="provider"
37 OCF_RESKEY_pon_retries_default="30"
38 OCF_RESKEY_pon_wait_sec_default="5"
39 OCF_RESKEY_poff_wait_sec_default="3"
40 OCF_RESKEY_ip_wait_sec_default="30"
42 : ${OCF_RESKEY_expected_ip4=${OCF_RESKEY_expected_ip4_default}}
43 : ${OCF_RESKEY_expected_ip6=${OCF_RESKEY_expected_ip6_default}}
44 : ${OCF_RESKEY_isp=${OCF_RESKEY_isp_default}}
45 : ${OCF_RESKEY_pon_retries=${OCF_RESKEY_pon_retries_default}}
46 : ${OCF_RESKEY_pon_wait_sec=${OCF_RESKEY_pon_wait_sec_default}}
47 : ${OCF_RESKEY_poff_wait_sec=${OCF_RESKEY_poff_wait_sec_default}}
48 : ${OCF_RESKEY_ip_wait_sec=${OCF_RESKEY_ip_wait_sec_default}}
53 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
54 <resource-agent name="PPPConnection">
55 <version>0.2</version>
57 Handle ppp connection as OCF resource. This resource calls pon/poff to connect ppp.
60 Handle ppp connection as OCF resource. This resource calls pon/poff to connect ppp.
63 <parameter name="expected_ip4" unique="1" required="0">
65 Expected IPv4 address. If you specify this parameter,
66 startup and monitor proecesses will wait the address associated with ppp interface.
68 <shortdesc lang="en">Expected IPv4 address</shortdesc>
69 <content type="string" default="" />
71 <parameter name="expected_ip6" unique="1" required="0">
73 Expected IPv6 address. If you specify this parameter,
74 startup and monitor proecesses will wait the address associated with ppp interface.
76 <shortdesc lang="en">Expected IPv6 address</shortdesc>
77 <content type="string" default="" />
79 <parameter name="isp" unique="1" required="0">
81 ISP name. This will be passed to pon/poff, and pppd will be monitored with specified isp.
82 Default is "provider".
84 <shortdesc lang="en">ISP name (default: provider)</shortdesc>
85 <content type="string" default="provider" />
87 <parameter name="pon_retries" unique="0" required="0">
91 <shortdesc lang="en">Retry limit for pon</shortdesc>
92 <content type="integer" default="30" />
94 <parameter name="pon_wait_sec" unique="0" required="0">
96 Resource will wait specified seconds for ppp connection up. When it's exceeded, retry to run pon.
98 <shortdesc lang="en">Wait time for pon on each tries</shortdesc>
99 <content type="integer" default="5" />
101 <parameter name="poff_wait_sec" unique="0" required="0">
103 Resource will wait specified seconds for ppp connection down. When it's exceeded, retry to run poff.
105 <shortdesc lang="en">Wait time for poff on each tries</shortdesc>
106 <content type="integer" default="3" />
108 <parameter name="ip_wait_sec" unique="0" required="0">
110 Resource will wait specified seconds for ppp interface aquires expected IP address provided by expected_ip4 or expected_ip6.
112 <shortdesc lang="en">Wait time for expected ip</shortdesc>
113 <content type="integer" default="30" />
117 <action name="start" timeout="60s" />
118 <action name="stop" timeout="60s" />
119 <action name="monitor" timeout="10s" interval="30s" depth="0" />
120 <action name="meta-data" timeout="5s" />
121 <action name="validate-all" timeout="10s" />
131 usage: $0 {start|stop|status|monitor|validate-all|meta-data}
133 Expects to have a fully populated OCF RA-compliant environment set.
147 if [ ! -z "$IP4" -o ! -z "$IP6" ]; then
148 check_binary $IP2UTIL
151 if [ -z "$ISP" ]; then
152 ocf_log err "Isp name is not specified for PPPConnection"
153 exit $OCF_ERR_CONFIGURED
158 ISP="$OCF_RESKEY_isp"
159 IP4="$OCF_RESKEY_expected_ip4"
160 IP6="$OCF_RESKEY_expected_ip6"
166 while ! ppp_check_pppd; do
167 tries=`expr $tries + 1`
169 if [ "$tries" -gt "$OCF_RESKEY_pon_retries" ]; then
170 ocf_log err "Retry limit for pon is exceeded. Giving up!"
171 return $OCF_ERR_GENERIC
173 if [ "$tries" -eq 1 ]; then
176 sleep $OCF_RESKEY_pon_wait_sec
185 while ppp_check_pppd; do
186 tries=`expr $tries + 1`
188 if [ "$tries" -eq 1 ]; then
191 elif [ "$tries" -gt 10 ]; then
192 ocf_log err "ppp connection is still active with isp '${ISP}', giving up to stop!"
193 return $OCF_ERR_GENERIC
194 elif [ "$tries" -gt 8 ]; then
195 ocf_log warn "pppd still running with isp '${ISP}'. Trying to send KILL signal..."
196 kill -KILL `ps -ewwwo pid,args | $EGREP "[p]ppd call ${ISP}\$" | $AWK '{print $1}'`
197 elif [ "$tries" -gt 5 ]; then
198 ocf_log warn "pppd still running with isp '${ISP}'. Trying to send TERM signal..."
199 kill -TERM `ps -ewwwo pid,args | $EGREP "[p]ppd call ${ISP}\$" | $AWK '{print $1}'`
201 sleep $OCF_RESKEY_poff_wait_sec
208 ps -ewwo args | $EGREP -q "[p]ppd call ${ISP}\$" || return 1
214 if [ ! -z "$IP4" ]; then
215 $IP2UTIL -4 a list type ppp | grep -q "inet $IP4 " || return 1
217 if [ ! -z "$IP6" ]; then
218 $IP2UTIL -6 a list type ppp | grep -q "inet6 $IP6 " || return 1
224 if ! ppp_check_pppd; then
229 while ! ppp_check_ip; do
230 tries=`expr $tries + 1`
231 if [ "$tries" -gt "$OCF_RESKEY_ip_wait_sec" ]; then
232 ocf_log err "Timeout for waiting expected IP address (${IP4} ${IP6})."
244 status=`ppp_echo_status`
250 return $OCF_ERR_GENERIC
253 return $OCF_NOT_RUNNING
256 return $OCF_ERR_GENERIC
262 case $__OCF_ACTION in
274 case $__OCF_ACTION in
284 ip_status=`ppp_echo_status`
285 if [ $ip_status = "connected" ]; then
290 exit $OCF_NOT_RUNNING
302 exit $OCF_ERR_UNIMPLEMENTED