├── 20.nfs-ganesha.check ├── LICENSE ├── nfs-ganesha-callout ├── storhaug ├── storhaug.8 └── storhaug.spec /20.nfs-ganesha.check: -------------------------------------------------------------------------------- 1 | # nfs_ganesha 2 | restart_every=2 3 | unhealthy_after=6 4 | service_stop_cmd="$CTDB_NFS_CALLOUT stop nfs" 5 | service_start_cmd="$CTDB_NFS_CALLOUT start nfs" 6 | service_check_cmd="$CTDB_NFS_CALLOUT check nfs" 7 | # Ganesha initscript restarts rpc.statd and stack trace is desirable! 8 | service_debug_cmd="program_stack_traces status 5" 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /nfs-ganesha-callout: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This CTDB NFS callout script for Ganesha is based on the example 4 | # nfs-ganesha-callout shipped with CTDB. 5 | 6 | # To use this: 7 | # 8 | # * Set CTDB_NFS_CALLOUT in your CTDB configuration to point to (a 9 | # copy of) this script, making sure it is executable. 10 | # 11 | # * Create a new directory alongside the nfs-checks.d directory, for 12 | # example nfs-checks-ganesha.d. Install 20.nfs-ganesha.check in 13 | # this directory. Symlink to any other check files from 14 | # nfs-checks.d that should still be used, such as 15 | # 00.portmapper.check. Set CTDB_NFS_CHECKS_DIR to point to this new 16 | # directory of check files. 17 | # 18 | # I (Martin Schwenke) hereby relicense all of my contributions to this 19 | # callout (and, previously, to 60.ganesha) to a license compatible 20 | # with NFS Ganesha (right now this is LGPLv3, but I'm flexible). 21 | # There may be other contributions to be considered for relicensing, 22 | # particularly those in commit 28cbe527d47822f870e8252495ab2a1c8fddd12f. 23 | 24 | ###################################################################### 25 | 26 | # Exit on 1st error 27 | set -e 28 | 29 | # Filesystem type and mount point for the (typically clustered) 30 | # volume that will contain the NFS-Ganesha state. 31 | state_fs="${CTDB_NFS_STATE_FS_TYPE:-glusterfs}" 32 | state_dir="${CTDB_NFS_STATE_MNT:-/run/gluster/shared_storage}" 33 | 34 | # To change the following, edit the default values below. Do not set 35 | # these - they aren't configuration variables, just hooks for testing. 36 | nfs_exports_file="${CTDB_NFS_EXPORTS_FILE:-/etc/ganesha/ganesha.conf}" 37 | nfs_service="${CTDB_NFS_SERVICE:-nfs-ganesha}" 38 | ganesha_rec_subdir=${CTDB_GANESHA_REC_SUBDIR:-.ganesha} 39 | procfs=${PROCFS_PATH:-/proc} 40 | 41 | case "$state_fs" in 42 | gpfs) 43 | GANRECDIR="/var/lib/nfs/ganesha" 44 | ;; 45 | glusterfs) 46 | if [ -z "${state_dir}" ]; then 47 | echo "CTDB_NFS_STATE_MNT not defined for GlusterFS" 48 | exit 1 49 | fi 50 | eval hostaddrs=( $(hostname -I || hostname -i) ) 51 | hostaddr="${hostaddrs[0]}" 52 | NODESTATEDIR="${state_dir}/nfs-ganesha/${hostaddr}" 53 | GANSTATEDIR="${state_dir}/nfs-ganesha/.noderefs" 54 | NODESTATELN="${GANSTATEDIR}/${hostaddr}" 55 | ;; 56 | esac 57 | 58 | 59 | ################################################## 60 | 61 | usage () 62 | { 63 | _c=$(basename "$0") 64 | cat < 141 | check_ln () 142 | { 143 | if [ ! -L "${2}" ] ; then 144 | rm -vrf "${2}" 145 | else 146 | _t=$(readlink "${2}") 147 | if [ "$_t" != "${1}" ] ; then 148 | rm -v "${2}" 149 | fi 150 | fi 151 | # This is not an "else". It also re-creates the link if it was 152 | # removed above! 153 | if [ ! -e "${2}" ]; then 154 | ln -sfv "${1}" "${2}" 155 | fi 156 | } 157 | 158 | # Return 'active' if the shared filesystem is accessible. 159 | get_cluster_fs_state () 160 | { 161 | case $state_fs in 162 | gpfs) 163 | /usr/lpp/mmfs/bin/mmgetstate | awk 'NR == 4 { print $3 }' 164 | ;; 165 | glusterfs) 166 | # Since we're past create_ganesha_recdirs(), we're active. 167 | echo "active" 168 | ;; 169 | *) 170 | echo "File system $state_fs not supported" 171 | exit 1 172 | ;; 173 | esac 174 | } 175 | 176 | create_ganesha_recdirs () 177 | { 178 | if ! _mounts=$(mount | grep "$state_fs"); then 179 | echo "Failed to find mounts of type $state_fs" 180 | exit 1 181 | fi 182 | if [ -z "$_mounts" ]; then 183 | echo "startup $state_fs not ready" 184 | exit 0 185 | fi 186 | 187 | case $state_fs in 188 | gpfs) 189 | _mntpt=$(echo "$_mounts" | sort | awk 'NR == 1 {print $3}') 190 | _link_dst="${_mntpt}/${ganesha_rec_subdir}" 191 | mkdir -vp "$_link_dst" 192 | check_ln "$_link_dst" "$GANRECDIR" 193 | ;; 194 | glusterfs) 195 | [ -d /var/lib/nfs.backup ] || \ 196 | mv /var/lib/nfs /var/lib/nfs.backup 197 | check_ln "$NODESTATEDIR" /var/lib/nfs 198 | 199 | mkdir -p "${NODESTATEDIR}/ganesha/v4recov" 200 | mkdir -p "${NODESTATEDIR}/ganesha/v4old" 201 | mkdir -p "${NODESTATEDIR}/statd/sm" 202 | mkdir -p "${NODESTATEDIR}/statd/sm.bak" 203 | touch "${NODESTATEDIR}/state" 204 | touch "${NODESTATEDIR}/statd/state" 205 | 206 | mkdir -p "$GANSTATEDIR" 207 | check_ln "$NODESTATEDIR" "$NODESTATELN" 208 | for _dir in "${GANSTATEDIR}/"* ; do 209 | # Handle no directories case 210 | if [ ! -d "$_dir" ] ; then 211 | break 212 | fi 213 | 214 | _node="${_dir##*/}" # basename 215 | if [ "${_node}" != "${hostaddr}" ]; then 216 | check_ln "${GANSTATEDIR}/${_node}/ganesha" \ 217 | "${NODESTATEDIR}/ganesha/${_node}" 218 | check_ln "${GANSTATEDIR}/${_node}/statd" \ 219 | "${NODESTATEDIR}/statd/${_node}" 220 | fi 221 | done 222 | ;; 223 | esac 224 | } 225 | 226 | service_check () 227 | { 228 | create_ganesha_recdirs 229 | 230 | # Always succeed if cluster filesystem is not active 231 | _cluster_fs_state=$(get_cluster_fs_state) 232 | if [ "$_cluster_fs_state" != "active" ] ; then 233 | return 0 234 | fi 235 | 236 | # Check that NFS Ganesha is running, according to PID file 237 | _pidfile="/var/run/ganesha.pid" 238 | _ganesha="/usr/bin/ganesha.nfsd" 239 | if ! { read -r _pid < "$_pidfile" && \ 240 | grep "$_ganesha" "${procfs}/${_pid}/cmdline" ; } >/dev/null 2>&1 241 | then 242 | 243 | echo "ERROR: NFS Ganesha not running according to PID file" 244 | return 1 245 | fi 246 | 247 | return 0 248 | } 249 | 250 | #------------------------------------------------- 251 | 252 | nfs_releaseip () 253 | { 254 | logger "nfs_releaseip $*" 255 | /usr/sbin/storhaug --releaseip ${2} 256 | } 257 | 258 | nfs_takeip () 259 | { 260 | logger "nfs_takeip $*" 261 | case $state_fs in 262 | glusterfs) 263 | check_ln "$NODESTATEDIR" "${GANSTATEDIR}/${2}" 264 | ;; 265 | esac 266 | /usr/sbin/storhaug --takeip ${2} 267 | } 268 | 269 | ################################################## 270 | # service init startup and final shutdown 271 | 272 | nfs_shutdown () 273 | { 274 | basic_stop "nfs" 275 | } 276 | 277 | nfs_startup () 278 | { 279 | basic_stop "nfs" || true 280 | 281 | create_ganesha_recdirs 282 | 283 | basic_start "nfs" 284 | _f="${procfs}/sys/net/ipv4/tcp_tw_recycle" 285 | if [ -f "$_f" ] ; then 286 | echo 1 >"$_f" 287 | fi 288 | } 289 | 290 | ################################################## 291 | # list share directories 292 | 293 | nfs_monitor_list_shares () 294 | { 295 | grep Path "$nfs_exports_file" | 296 | cut -f2 -d\" | 297 | sort -u 298 | } 299 | 300 | ################################################## 301 | 302 | nfs_register () 303 | { 304 | cat < " 35 | echo "Delete node : storhaug delete " 36 | echo "Reload : storhaug reload" 37 | echo "Export : storhaug export " 38 | echo "Unexport : storhaug unexport " 39 | } 40 | 41 | storlog() 42 | { 43 | LEVEL=${1}; shift 44 | case ${LEVEL} in 45 | ERR|ERROR) 46 | echo "ERROR: $1" >&2 47 | logger --tag="storhaug" -p "daemon.err" "${1}" 48 | exit 1 49 | ;; 50 | WARN|WARNING) 51 | echo "WARNING: $1" 52 | logger --tag="storhaug" -p "daemon.warn" "${1}" 53 | ;; 54 | INFO) 55 | echo "$1" 56 | logger --tag="storhaug" -p "daemon.info" "${1}" 57 | ;; 58 | DEBUG) 59 | logger --tag="storhaug" -p "daemon.debug" "${1}" 60 | ;; 61 | esac 62 | } 63 | 64 | ssh_do() 65 | { 66 | if [[ ${1} = ${MY_IPS[0]} ]]; then 67 | eval ${2} 68 | else 69 | ssh -q -oPasswordAuthentication=no -oStrictHostKeyChecking=no -i ${SECRET_PEM} root@${1} "${2}" 70 | fi 71 | 72 | local _ret=$? 73 | if [ $_ret -ne 0 ]; then 74 | storlog "WARN" "Command failed on ${1}: ${2}" 75 | fi 76 | return $_ret 77 | } 78 | 79 | scp_do() 80 | { 81 | # avoid prompting for password, even with password-less scp 82 | # scp $host1:$file $host2:$file prompts for the password 83 | scp -q -3 -r -oPasswordAuthentication=no -oStrictHostKeyChecking=no -i ${SECRET_PEM} ${1} ${2} 84 | local _ret=$? 85 | if [ $_ret -ne 0 ]; then 86 | storlog "WARN" "SCP failed from ${1} to ${2}" 87 | fi 88 | return ${_ret} 89 | } 90 | 91 | # Check that a directory exists, create it otherwise. 92 | # Only use on paths guaranteed to be directories. 93 | ensure_dir() 94 | { 95 | if [ ! -d "${1}" ] ; then 96 | mkdir -p "${1}" 97 | fi 98 | } 99 | 100 | # Check that a file exists, touch it otherwise. 101 | 102 | ### General cluster functions 103 | 104 | determine_servers() 105 | { 106 | local cmd=${1} 107 | declare -a servers 108 | declare -a addrs 109 | 110 | local num_servers=0 111 | if [ -s /etc/ctdb/nodes ]; then 112 | eval servers=( $(< /etc/ctdb/nodes) ) 113 | fi 114 | while [ "x${servers[${num_servers}]}x" != "xx" ]; do 115 | num_servers=$(( ${num_servers} + 1 )) 116 | done 117 | 118 | HA_NUM_SERVERS=${num_servers} 119 | HA_SERVERS=( ${servers[*]} ) 120 | 121 | if [[ "X${cmd}X" = "XsetupX" ]]; then 122 | 123 | if [ -s /etc/ctdb/public_addresses ]; then 124 | eval addrs=( $(< /etc/ctdb/public_addresses) ) 125 | fi 126 | local num_addrs=0 127 | local index=0 128 | while [ "x${addrs[${index}]}x" != "xx" ]; do 129 | index=$(( ${index} + 2 )) 130 | num_addrs=$(( ${num_addrs} + 1 )) 131 | done 132 | 133 | if [[ "${num_servers}" != "${num_addrs}" ]]; then 134 | storlog "ERR" "num_servers != num_addrs in /etc/ctdb/nodes and /etc/ctdb/public_addresses" 135 | return 1 136 | fi 137 | 138 | fi 139 | } 140 | 141 | ### Setup functions 142 | 143 | setup_move_ganesha_config() 144 | { 145 | # we don't do this in the nfs-ganesha-callout. That 146 | # would do it on every host, we only want to do it 147 | # once, on a single node 148 | 149 | local mnt=$(mktemp -d /run/gluster/storhaug.XXXXXXXX) 150 | 151 | mount -t glusterfs ${HA_SERVERS[0]}:gluster_shared_storage ${mnt} 152 | ensure_dir ${mnt}/nfs-ganesha/exports 153 | cp /etc/ganesha/ganesha.conf ${mnt}/nfs-ganesha/ 154 | eval exports=( $(ls -1 /etc/ganesha/exports) ) 155 | if [[ ! -z ${exports[0]} ]]; then 156 | cp /etc/ganesha/exports/* ${mnt}/nfs-ganesha/exports/ 157 | fi 158 | umount ${mnt} 159 | rmdir ${mnt} 160 | 161 | for srv in ${HA_SERVERS[*]}; do 162 | ssh_do ${srv} "mv /etc/ganesha/ganesha.conf /etc/ganesha/ganesha.conf.orig" 163 | ssh_do ${srv} "ln -s /run/gluster/shared_storage/nfs-ganesha/ganesha.conf /etc/ganesha/ganesha.conf" 164 | done 165 | } 166 | 167 | setup_copy_ctdb_config() 168 | { 169 | for srv in ${HA_SERVERS[*]}; do 170 | if [[ ${srv} != ${MY_IPS[0]} ]]; then 171 | scp_do /etc/ctdb/ctdbd.conf "${srv}:/etc/ctdb/" 172 | scp_do /etc/ctdb/nodes "${srv}:/etc/ctdb/" 173 | scp_do /etc/ctdb/public_addresses "${srv}:/etc/ctdb/" 174 | ssh_do ${srv} firewall-cmd --add-service=ctdb --permanent 175 | ssh_do ${srv} firewall-cmd --reload 176 | fi 177 | done 178 | } 179 | 180 | setup_start_ctdb() 181 | { 182 | for srv in ${HA_SERVERS[*]}; do 183 | ssh_do ${srv} "systemctl start ctdb" 184 | done 185 | } 186 | 187 | ### Teardown functions 188 | 189 | teardown_stop_ctdb() 190 | { 191 | for srv in ${HA_SERVERS[*]}; do 192 | ssh_do ${srv} "systemctl stop ctdb" 193 | done 194 | } 195 | 196 | teardown_restore_ganesha_config() 197 | { 198 | ensure_dir /etc/ganesha/exports 199 | for srv in ${HA_SERVERS[*]}; do 200 | ssh_do ${srv} "rm /etc/ganesha/ganesha.conf" 201 | done 202 | cp /run/gluster/shared_storage/nfs-ganesha/ganesha.conf /etc/ganesha/ 203 | eval exports=( $(ls -1 /run/gluster/shared_storage/nfs-ganesha/exports) ) 204 | if [[ ! -z ${exports[0]} ]]; then 205 | cp /run/gluster/shared_storage/nfs-ganesha/exports/* /etc/ganesha/exports/ 206 | fi 207 | } 208 | 209 | ### take_ip, release_ip functions 210 | 211 | take_ip() 212 | { 213 | local fixed_ip="" 214 | 215 | if [ -L /run/gluster/shared_storage/nfs-ganesha/.noderefs/${1} ]; then 216 | t=$(readlink /run/gluster/shared_storage/nfs-ganesha/.noderefs/${1}) 217 | fixed_ip=$(basename ${t}) 218 | 219 | for srv in ${HA_SERVERS[*]}; do 220 | ssh_do ${srv} "dbus-send --print-reply --system --dest=org.ganesha.nfsd \ 221 | /org/ganesha/nfsd/admin org.ganesha.nfsd.admin.grace \ 222 | string:5:${fixed_ip}" 223 | done 224 | fi 225 | } 226 | 227 | release_ip() 228 | { 229 | local fixed_ip="" 230 | 231 | if [ -L /run/gluster/shared_storage/nfs-ganesha/.noderefs/${1} ]; then 232 | t=$(readlink /run/gluster/shared_storage/nfs-ganesha/.noderefs/${1}) 233 | fixed_ip=$(basename ${t}) 234 | 235 | for srv in ${HA_SERVERS[*]}; do 236 | ssh_do ${srv} "dbus-send --print-reply --system --dest=org.ganesha.nfsd \ 237 | /org/ganesha/nfsd/admin org.ganesha.nfsd.admin.grace \ 238 | string:2:${fixed_ip}" 239 | done 240 | fi 241 | } 242 | 243 | ### export_vol 244 | 245 | get_export_id() 246 | { 247 | local ids=() 248 | 249 | for file in /run/gluster/shared_storage/nfs-ganesha/exports/export.*.conf; do 250 | eval ids+=( $(awk '/Export_Id/' $file | cut -d= -f2 | tr -d ' ;') ) 251 | done 252 | 253 | while true; do 254 | found=false 255 | ((exp_id++)) 256 | 257 | for id in ${ids[*]}; do 258 | if [[ ${exp_id} == ${id} ]]; then 259 | found=true 260 | fi 261 | done 262 | if [ $found == false ]; then return 0; fi 263 | done 264 | } 265 | 266 | export_vol() 267 | { 268 | exp_id=0 269 | local vol_started="" 270 | 271 | vol_started=$(gluster volume status ${1} 2>&1) 272 | if [ "${vol_started}" = "Volume ${1} is not started" ]; then 273 | echo "${1} is not started" 274 | return 275 | fi 276 | 277 | if [ -f "/run/gluster/shared_storage/nfs-ganesha/exports/export.${1}.conf" ]; then 278 | echo "${1} already exported" 279 | return 280 | fi 281 | 282 | get_export_id 283 | 284 | cat << EOF > /run/gluster/shared_storage/nfs-ganesha/exports/export.${1}.conf 285 | EXPORT { 286 | Export_Id =${exp_id}; 287 | Path = "/${1}"; 288 | Pseudo = "/${1}"; 289 | Access_Type = RW; 290 | Squash = No_root_squash; 291 | Disable_ACL = true; 292 | Protocols = "3","4"; 293 | Transports = "UDP","TCP"; 294 | SecType = "sys"; 295 | FSAL { 296 | Name = "GLUSTER"; 297 | Hostname = localhost; 298 | Volume = "${1}"; 299 | } 300 | } 301 | EOF 302 | 303 | echo "%include \"/run/gluster/shared_storage/nfs-ganesha/exports/export.${1}.conf\"" >> \ 304 | /run/gluster/shared_storage/nfs-ganesha/ganesha.conf 305 | 306 | for srv in ${HA_SERVERS[*]}; do 307 | ssh_do ${srv} "dbus-send --print-reply --system --dest=org.ganesha.nfsd /org/ganesha/nfsd/ExportMgr org.ganesha.nfsd.exportmgr.AddExport string:/run/gluster/shared_storage/nfs-ganesha/exports/export.${1}.conf string:EXPORT\(Path=/${1}\)" 308 | done 309 | } 310 | 311 | unexport_vol() 312 | { 313 | eval unexport_id=( $(awk '/Export_Id/' /run/gluster/shared_storage/nfs-ganesha/exports/export.${1}.conf | cut -d= -f2 | tr -d ' ;') ) 314 | for srv in ${HA_SERVERS[*]}; do 315 | ssh_do ${srv} "dbus-send --print-reply --system --dest=org.ganesha.nfsd /org/ganesha/nfsd/ExportMgr org.ganesha.nfsd.exportmgr.RemoveExport uint16:${unexport_id}" 316 | done 317 | sed -i '/export.${1}.conf/d' /run/gluster/shared_storage/nfs-ganesha/ganesha.conf 318 | rm /run/gluster/shared_storage/nfs-ganesha/exports/export.${1}.conf 319 | } 320 | 321 | ### Mainline 322 | 323 | cmd=${1}; shift 324 | if [[ ${cmd} == *help || ${cmd} == "-h" ]]; then 325 | usage 326 | exit 0 327 | elif [[ ${cmd} == *status ]]; then 328 | exit 0 329 | fi 330 | 331 | case "${cmd}" in 332 | setup | --setup) 333 | storlog "INFO" "Setting up" 334 | 335 | if [[ -e /run/ctdb/ctdbd.pid && -e /proc/$(cat /run/ctdb/ctdbd.pid) ]]; then 336 | storlog "INFO" "nfs-ganesha is already running" 337 | else 338 | determine_servers "setup" 339 | if [ ${HA_NUM_SERVERS} -gt 1 ]; then 340 | setup_move_ganesha_config 341 | setup_copy_ctdb_config 342 | setup_start_ctdb 343 | else 344 | storlog "ERR" "Insufficient servers for HA, aborting" 345 | fi 346 | fi 347 | ;; 348 | teardown | --teardown) 349 | storlog "INFO" "Tearing down" 350 | 351 | determine_servers "teardown" 352 | teardown_stop_ctdb 353 | teardown_restore_ganesha_config 354 | ;; 355 | takeip | --takeip) 356 | storlog "INFO" "takeip" 357 | 358 | determine_servers "teardown" 359 | take_ip ${1} 360 | ;; 361 | releaseip | --releaseip) 362 | storlog "INFO" "releaseip" 363 | 364 | determine_servers "teardown" 365 | release_ip ${1} 366 | ;; 367 | reload | --reload) 368 | storlog "INFO" "Not implemented: ${cmd}" 369 | ;; 370 | export | --export) 371 | if [[ ${1} == "" ]]; then 372 | storlog "WARN" "missing volume name" 373 | usage 374 | exit 0 375 | fi 376 | storlog "INFO" "export ${1}" 377 | 378 | determine_servers "teardown" 379 | export_vol ${1} 380 | ;; 381 | unexport | --unexport) 382 | if [[ ${1} == "" ]]; then 383 | storlog "WARN" "missing volume name" 384 | usage 385 | exit 0 386 | fi 387 | storlog "INFO" "unexport ${1}" 388 | 389 | determine_servers "unexport" 390 | unexport_vol ${1} 391 | ;; 392 | add | --add | delete | --delete | remove | --remove) 393 | storlog "ERR" "Not implemented: ${cmd}" 394 | ;; 395 | *) 396 | usage 397 | ;; 398 | esac 399 | 400 | -------------------------------------------------------------------------------- /storhaug.8: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2018 Red Hat, Inc 2 | .\" 3 | .\" This is free documentation; you can redistribute it and/or 4 | .\" modify it under the terms of the GNU General Public License as 5 | .\" published by the Free Software Foundation; either version 2 of 6 | .\" the License, or (at your option) any later version. 7 | .\" 8 | .\" The GNU General Public License's references to "object code" 9 | .\" and "executables" are to be interpreted as the output of any 10 | .\" document formatting or typesetting system, including 11 | .\" intermediate and printed output. 12 | .\" 13 | .\" This manual is distributed in the hope that it will be useful, 14 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | .\" GNU General Public License for more details. 17 | .\" 18 | .\" You should have received a copy of the GNU General Public License along 19 | .\" with this program; if not, write to the Free Software Foundation, Inc., 20 | .\" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21 | .\" 22 | .TH STORHAUG 8 "August 2018" "storhaug" "System Administration" 23 | .SH NAME 24 | storhaug \- Manage Highly Available NFS-Ganesha NFS Server using CTDB 25 | .SH SYNOPSIS 26 | .B storhaug 27 | .RB [ setup | teardown | reload ] 28 | .LP 29 | .B storhaug 30 | .RB [ add | delete ] 31 | .I IP VIP 32 | .LP 33 | .B storhaug 34 | .RB [ export | unexport ] 35 | .I vol 36 | .SH DESCRIPTION 37 | The 38 | .B storhaug 39 | utility is used to manage an active-active highly available cluster of 40 | NFS-Ganesha NFS servers using CTDB and GlusterFS. 41 | .SH "SEE ALSO" 42 | .na 43 | .BR ganesha-config (2), 44 | .BR ganesha-cache-config (2), 45 | .BR ganesha-core-config (2), 46 | .BR ganesha-export-config (2), 47 | .BR ganesha-gluster-config (2), 48 | .BR ganesha-log-config (2), 49 | .BR ctdb (1), 50 | .BR ctdbd (1), 51 | .BR ctdbd.conf (5), 52 | .BR gluster (8) 53 | .ad 54 | .SH BUGS 55 | Probably 56 | .SH AUTHORS 57 | .nf 58 | Kaleb S. KEITHLEY 59 | .fi 60 | .SH AVAILABILITY 61 | The storhaug command is part of the storhaug package and is available from 62 | https://github.com/gluster/storhaug 63 | -------------------------------------------------------------------------------- /storhaug.spec: -------------------------------------------------------------------------------- 1 | Name: storhaug 2 | Summary: High-Availability Add-on for NFS-Ganesha 3 | Version: 1.0 4 | Release: 1%{?prereltag:.%{prereltag}}%{?dist} 5 | License: GPLv2 6 | URL: https://github.com/gluster/storhaug 7 | BuildArch: noarch 8 | Obsoletes: storhaug-smb < 1.0 9 | Source0: https://github.com/gluster/%{name}/archive/v%{version}/%{name}-%{version}.tar.gz 10 | 11 | Requires: glusterfs-server 12 | Requires: ctdb 13 | Requires: firewalld 14 | 15 | %description 16 | High-Availability add-on for storage servers 17 | 18 | ### NFS (NFS-Ganesha) 19 | %package nfs 20 | Summary: storhaug NFS-Ganesha module 21 | Requires: %{name} = %{version}-%{release} 22 | Requires: nfs-ganesha-gluster 23 | 24 | %description nfs 25 | High-Availability NFS add-on for NFS-Ganesha 26 | 27 | %build 28 | 29 | %prep 30 | %setup -q -n %{name}-%{version} 31 | 32 | %install 33 | install -d -m 0755 %{buildroot}%{_sbindir} 34 | mkdir -p %{buildroot}%{_sysconfdir}/ctdb/nfs-checks-ganesha.d 35 | mkdir -p %{buildroot}%{_sysconfdir}/sysconfig/storhaug.d 36 | install -m 0744 storhaug %{buildroot}%{_sbindir}/storhaug 37 | install -m 0744 20.nfs-ganesha.check %{buildroot}%{_sysconfdir}/ctdb/nfs-checks-ganesha.d/ 38 | install -m 0744 nfs-ganesha-callout %{buildroot}%{_sysconfdir}/ctdb 39 | mkdir -p %{buildroot}/%{_mandir}/man8 40 | gzip -c storhaug.8 > %{buildroot}/%{_mandir}/man8/storhaug.8.gz 41 | 42 | %clean 43 | 44 | %files 45 | %{!?_licensedir:%global license %%doc} 46 | %license LICENSE 47 | %{_sbindir}/storhaug 48 | %dir %{_sysconfdir}/sysconfig/storhaug.d 49 | %{_mandir}/man8/storhaug.8.* 50 | 51 | %files nfs 52 | %dir %{_sysconfdir}/ctdb/nfs-checks-ganesha.d 53 | %{_sysconfdir}/ctdb/nfs-checks-ganesha.d/20.nfs-ganesha.check 54 | %{_sysconfdir}/ctdb/nfs-ganesha-callout 55 | 56 | %changelog 57 | * Wed Jul 11 2018 Kaleb S. KEITHLEY 58 | - /etc/sysconfig/storhaug.d, Vendor 59 | 60 | * Fri Jun 8 2018 Kaleb S. KEITHLEY 1.0-1 61 | - Reboot, Initial version 62 | --------------------------------------------------------------------------------