OCFS2_DRBD: mount ocfs2 filesystems with "noatime" option
[ocf-ra.git] / TunCtl
1 #!/bin/sh
2 #
3 # OCF RA for tunctl(1) TUN/TAP device initialization
4 #
5 # Copyright (c) 2008,2009 Barton IT-Consulting
6 # Copyright (c) 2004 SUSE LINUX AG, Lars Marowsky-BrĂ©e
7 #                    All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of version 2 of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 #
17 # Further, this software is distributed without any warranty that it is
18 # free of the rightful claim of any third person regarding infringement
19 # or the like.  Any license provided herein, whether implied or
20 # otherwise, applies only to this software file.  Patent licenses, if
21 # any, provided herein do not apply to combinations of this program with
22 # other software, or any other product whatsoever.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write the Free Software Foundation,
26 # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
27 #
28
29 # Initialization:
30 . ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
31
32 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
33
34 meta_data() {
35         cat <<END
36 <?xml version="1.0"?>
37 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
38 <resource-agent name="TunCtl">
39 <version>1.1</version>
40
41 <longdesc lang="en">
42 OCF RA for tunctl(1) TUN/TAP device initialization.
43 </longdesc>
44 <shortdesc lang="en">TUN/TAP device initialization</shortdesc>
45
46 <parameters>
47 <parameter name="if_name" unique="1">
48 <longdesc lang="en">Name of TUN/TAP interface</longdesc>
49 <shortdesc lang="en">Name of TUN/TAP interface</shortdesc>
50 <content type="string" default="" />
51 </parameter>
52 <parameter name="if_owner" unique="1">
53 <longdesc lang="en">TUN/TAP interface owner</longdesc>
54 <shortdesc lang="en">TUN/TAP interface owner</shortdesc>
55 <content type="string" default="" />
56 </parameter>
57 <parameter name="host_ip" unique="1">
58 <longdesc lang="en">Host-side IP address</longdesc>
59 <shortdesc lang="en">Host-side IP address</shortdesc>
60 <content type="string" default="" />
61 </parameter>
62 <parameter name="host_netmask" unique="1">
63 <longdesc lang="en">Host-side netmask</longdesc>
64 <shortdesc lang="en">Host-side netmask</shortdesc>
65 <content type="string" default="" />
66 </parameter>
67 <parameter name="client_ip" unique="1">
68 <longdesc lang="en">Client-side IP address</longdesc>
69 <shortdesc lang="en">Client-side IP address</shortdesc>
70 <content type="string" default="" />
71 </parameter>
72 <parameter name="if_proxyarp" unique="1">
73 <longdesc lang="en">Interface for Proxy-ARP</longdesc>
74 <shortdesc lang="en">Interface for Proxy-ARP</shortdesc>
75 <content type="string" default="" />
76 </parameter>
77 </parameters>
78
79 <actions>
80 <action name="start" timeout="10" />
81 <action name="stop" timeout="10" />
82 <action name="monitor" timeout="10" interval="15" depth="0" start-delay="5" />
83 <action name="meta-data" timeout="5" />
84 <action name="validate-all" timeout="30" />
85 </actions>
86 </resource-agent>
87 END
88 }
89
90 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
91
92 TunCtl_usage() {
93         echo "usage: $0 {start|stop|monitor|validate-all|meta-data}"
94 }
95
96 TunCtl_start() {
97         tunctl -u "${OCF_RESKEY_if_owner:-root}" -t "$OCF_RESKEY_if_name"
98         if [ $? -ne 0 ]; then
99                 return $OCF_ERR_GENERIC
100         fi
101         ifconfig "$OCF_RESKEY_if_name" "$OCF_RESKEY_host_ip" \
102          netmask "${OCF_RESKEY_host_netmask:-255.255.255.0}" up
103         if [ $? -ne 0 ]; then
104                 return $OCF_ERR_GENERIC
105         fi
106         echo 1 >/proc/sys/net/ipv4/ip_forward
107         route add -host "$OCF_RESKEY_client_ip" dev "$OCF_RESKEY_if_name"
108         if [ $? -ne 0 ]; then
109                 return $OCF_ERR_GENERIC
110         fi
111         if [ -n "$OCF_RESKEY_if_proxyarp" ]; then
112                 # Proxy ARP
113                 echo 1 >/proc/sys/net/ipv4/conf/"$OCF_RESKEY_if_name"/proxy_arp
114                 if [ $? -ne 0 ]; then
115                         return $OCF_ERR_GENERIC
116                 fi
117                 arp -Ds "$OCF_RESKEY_client_ip" "$OCF_RESKEY_if_proxyarp" pub
118                 if [ $? -ne 0 ]; then
119                         return $OCF_ERR_GENERIC
120                 fi
121         fi
122         return $OCF_SUCCESS
123 }
124
125 TunCtl_stop() {
126         if [ -n "$OCF_RESKEY_if_proxyarp" ]; then
127                 # Proxy ARP
128                 arp -d "$OCF_RESKEY_client_ip" -i "$OCF_RESKEY_if_proxyarp" pub
129         fi
130         ifconfig "$OCF_RESKEY_if_name" down >/dev/null 2>&1
131         tunctl -d "$OCF_RESKEY_if_name"
132         if [ $? -eq 0 ]; then
133                 return $OCF_SUCCESS
134         fi
135         return $OCF_ERR_GENERIC
136 }
137
138 TunCtl_monitor() {
139         ip link show "$OCF_RESKEY_if_name" | grep "UP" >/dev/null 2>&1
140         if [ $? -eq 0 ]; then
141                 return $OCF_SUCCESS
142         fi
143         return $OCF_NOT_RUNNING
144 }
145
146 TunCtl_validate() {
147         if [ -z "$OCF_RESKEY_if_name" ]; then
148                 return $OCF_ERR_ARGS
149         fi
150         if [ -z "$OCF_RESKEY_host_ip" ]; then
151                 return $OCF_ERR_ARGS
152         fi
153         if [ -z "$OCF_RESKEY_client_ip" ]; then
154                 return $OCF_ERR_ARGS
155         fi
156         return $OCF_SUCCESS
157 }
158
159 case $__OCF_ACTION in
160         meta-data)
161                 meta_data
162                 exit $OCF_SUCCESS
163                 ;;
164         start)
165                 TunCtl_start
166                 ;;
167         stop)
168                 TunCtl_stop
169                 ;;
170         monitor)
171                 TunCtl_monitor
172                 ;;
173         validate-all)
174                 TunCtl_validate
175                 ;;
176         usage|help)
177                 TunCtl_usage
178                 exit $OCF_SUCCESS
179                 ;;
180         *)
181                 TunCtl_usage
182                 exit $OCF_ERR_UNIMPLEMENTED
183                 ;;
184 esac
185
186 rc=$?
187 ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
188 exit $rc
189
190 # -eof-