github.com/rohankumardubey/proxyfs@v0.0.0-20210108201508-653efa9ab00e/saio/bin/start_and_mount_pfs (about) 1 #!/bin/bash 2 3 # A simple script to start the services and mount the sample mount point 4 # The PATH, etc should already be setup by systemctl environment 5 6 function await_proxyfsd_startup { 7 /usr/bin/systemctl -q is-active proxyfsd 8 if [ $? -ne 0 ]; then 9 echo "ProxyFS failed to start. Exiting..." 10 exit 1 11 fi 12 while true; do 13 curl http://127.0.0.1:15346/ 2>/dev/null >/dev/null 14 if [ $? -eq 0 ]; then 15 break 16 fi 17 echo "Waiting for ProxyFS to be started..." 18 sleep 1 19 done 20 } 21 22 function await_pfsagentd_startup { 23 /usr/bin/systemctl -q is-active pfsagentd 24 if [ $? -ne 0 ]; then 25 echo "PFSAgent failed to start. Exiting..." 26 exit 1 27 fi 28 while true; do 29 curl http://127.0.0.1:9090/version 2>/dev/null >/dev/null 30 if [ $? -eq 0 ]; then 31 # Service is active and curl to the HTTP server succeeded. 32 # We're go to go. 33 break 34 fi 35 echo "Waiting for PFSAgent to be started..." 36 sleep 1 37 done 38 } 39 40 function await_swift_startup { 41 while true 42 do 43 curl http://127.0.0.1:8090/info 2>/dev/null >/dev/null 44 if [ $? -eq 0 ] 45 then 46 break 47 fi 48 echo "Waiting for Swift to be started..." 49 sleep 1 50 done 51 } 52 53 function format_volume_if_necessary { 54 sudo /vagrant/bin/mkproxyfs -I $1 /vagrant/src/github.com/swiftstack/ProxyFS/saio/proxyfs.conf SwiftClient.RetryLimit=1 55 if [ $? -ne 0 ] 56 then 57 echo "Could not pre-format $1" 58 exit 1 59 fi 60 } 61 62 function containsElement () { 63 local e match="$1" 64 shift 65 for e; do [[ "$e" == "$match" ]] && return 0; done 66 return 1 67 } 68 69 help() { 70 echo "Usage: $0 [mount type]" 71 echo "Mount type options:" 72 echo " all: NFS v3 and SMB v3.0 (default option)" 73 echo " keepmounts: don't umount/mount any mountpoints" 74 echo " nfs: NFS v3" 75 echo " smb: SMB v3.0" 76 echo " smb1: SMB v1.0" 77 echo " smb2: SMB v2.1" 78 echo " smb3: SMB v3.0" 79 echo " pfsa: PFSAgent" 80 } 81 82 MOUNT_OPTIONS=() 83 if [ $# -gt 0 ]; then 84 while [[ $# -gt 0 ]]; do 85 key="$1" 86 case $key in 87 -h|--help) 88 help 89 exit 0 90 ;; 91 all|keepmounts|smb|smb1|smb2|smb3|nfs|pfsa) 92 if containsElement "$key" "${MOUNT_OPTIONS[@]}"; then 93 echo "Error: duplicated option '${key}'." 94 echo 95 help 96 exit 1 97 fi 98 MOUNT_OPTIONS+=("$1") 99 shift 100 ;; 101 *) 102 echo "Invalid argument '$key'." 103 echo 104 help 105 exit 1 106 esac 107 done 108 109 # Now that we allow more than one mount option to be passed, we have to check 110 # for incompatible options. 111 if [ ${#MOUNT_OPTIONS[@]} -gt 1 ] && containsElement "all" "${MOUNT_OPTIONS[@]}"; then 112 echo "Error: no other options are allowed while using 'all'." 113 echo 114 help 115 exit 1 116 fi 117 118 if [ ${#MOUNT_OPTIONS[@]} -gt 1 ] && containsElement "keepmounts" "${MOUNT_OPTIONS[@]}"; then 119 echo "Error: no other options are allowed while using 'keepmounts'." 120 echo 121 help 122 exit 1 123 fi 124 125 # I know the next 4 'if' clauses are gross, but I don't have the patience to 126 # find out the proper way to do it in bash. 127 if [ ${#MOUNT_OPTIONS[@]} -gt 1 ] && containsElement "smb" "${MOUNT_OPTIONS[@]}"; then 128 if containsElement "smb1" "${MOUNT_OPTIONS[@]}" || containsElement "smb2" "${MOUNT_OPTIONS[@]}" || containsElement "smb3" "${MOUNT_OPTIONS[@]}"; then 129 echo "Error: only one SMB option can be specified at a time." 130 echo 131 help 132 exit 1 133 fi 134 fi 135 136 if [ ${#MOUNT_OPTIONS[@]} -gt 1 ] && containsElement "smb1" "${MOUNT_OPTIONS[@]}"; then 137 if containsElement "smb" "${MOUNT_OPTIONS[@]}" || containsElement "smb2" "${MOUNT_OPTIONS[@]}" || containsElement "smb3" "${MOUNT_OPTIONS[@]}"; then 138 echo "Error: only one SMB option can be specified at a time." 139 echo 140 help 141 exit 1 142 fi 143 fi 144 145 if [ ${#MOUNT_OPTIONS[@]} -gt 1 ] && containsElement "smb2" "${MOUNT_OPTIONS[@]}"; then 146 if containsElement "smb1" "${MOUNT_OPTIONS[@]}" || containsElement "smb" "${MOUNT_OPTIONS[@]}" || containsElement "smb3" "${MOUNT_OPTIONS[@]}"; then 147 echo "Error: only one SMB option can be specified at a time." 148 echo 149 help 150 exit 1 151 fi 152 fi 153 154 if [ ${#MOUNT_OPTIONS[@]} -gt 1 ] && containsElement "smb3" "${MOUNT_OPTIONS[@]}"; then 155 if containsElement "smb1" "${MOUNT_OPTIONS[@]}" || containsElement "smb2" "${MOUNT_OPTIONS[@]}" || containsElement "smb" "${MOUNT_OPTIONS[@]}"; then 156 echo "Error: only one SMB option can be specified at a time." 157 echo 158 help 159 exit 1 160 fi 161 fi 162 else 163 MOUNT_OPTIONS+=("all") 164 fi 165 166 if containsElement "all" "${MOUNT_OPTIONS[@]}"; then 167 NFS_VERS=3 168 SMB_VERS=3.0 169 else 170 if containsElement "nfs" "${MOUNT_OPTIONS[@]}"; then 171 NFS_VERS=3 172 fi 173 174 if containsElement "smb1" "${MOUNT_OPTIONS[@]}"; then 175 SMB_VERS=1.0 176 elif containsElement "smb2" "${MOUNT_OPTIONS[@]}"; then 177 SMB_VERS=2.1 178 elif containsElement "smb" "${MOUNT_OPTIONS[@]}" || containsElement "smb3" "${MOUNT_OPTIONS[@]}"; then 179 SMB_VERS=3.0 180 fi 181 fi 182 183 MOUNT_POINT_NFS=127.0.0.1:/CommonMountPoint 184 SHARE_NFS=/mnt/nfs_proxyfs_mount/ 185 186 MOUNT_POINT_SMB=//127.0.0.1/proxyfs 187 SHARE_SMB=/mnt/smb_proxyfs_mount/ 188 189 UID_SMB=`id -u` 190 GID_SMB=`id -g` 191 192 sudo mount -a 193 194 # "keepmounts" means "keep everything as it was", but PFSAgent works differently, 195 # so just preserving the mount points is not enough. What we'll do is check if 196 # it's running before trying to stop it, and if it is, save it as a "MOUNT_OPTION" 197 if [ -f /usr/bin/systemctl ] && containsElement "keepmounts" "${MOUNT_OPTIONS[@]}"; then 198 /usr/bin/systemctl is-active --quiet pfsagentd && MOUNT_OPTIONS+=("pfsa") 199 fi 200 201 if containsElement "keepmounts" "${MOUNT_OPTIONS[@]}"; then 202 echo "Shutting down services..." 203 /vagrant/src/github.com/swiftstack/ProxyFS/saio/bin/unmount_and_stop_pfs keepmounts 204 else 205 echo "Shutting down services and mount points..." 206 /vagrant/src/github.com/swiftstack/ProxyFS/saio/bin/unmount_and_stop_pfs 207 fi 208 echo 209 210 echo "Bringing up services..." 211 if [ -f /usr/bin/systemctl ]; then 212 # Centos 213 MOUNT=/usr/bin/mount 214 sudo /usr/bin/systemctl start memcached 215 sudo /usr/bin/swift-init main start 216 await_swift_startup 217 format_volume_if_necessary CommonVolume 218 sudo /usr/bin/systemctl start proxyfsd 219 await_proxyfsd_startup 220 echo "ProxyFS successfully started" 221 sudo /usr/bin/systemctl start smb 222 sudo /usr/bin/systemctl start rpcbind 223 sudo /usr/bin/systemctl start nfs-server 224 sudo /usr/bin/systemctl start nfs-lock 225 sudo /usr/bin/systemctl start nfs-idmap 226 if containsElement "all" "${MOUNT_OPTIONS[@]}" || containsElement "pfsa" "${MOUNT_OPTIONS[@]}"; then 227 echo "Starting PFSAgent..." 228 sudo /usr/bin/systemctl start pfsagentd 229 await_pfsagentd_startup 230 fi 231 else 232 # Ubuntu (not tested!) 233 MOUNT=/bin/mount 234 sudo /usr/sbin/service memcached start 235 sudo /usr/bin/swift-init main start 236 await_swift_startup 237 format_volume_if_necessary CommonVolume 238 sudo /usr/sbin/service proxyfsd start 239 await_proxyfsd_startup 240 echo "ProxyFS successfully started" 241 sudo /usr/sbin/service smbd start 242 sudo /usr/sbin/service rpcbind start 243 sudo /usr/sbin/service nfs-server start 244 sudo /usr/sbin/service nfs-lock start 245 sudo /usr/sbin/service nfs-idmap start 246 # Here we should start pfsagentd (if 'all' or 'pfsa' are present in 247 # $MOUNT_OPTIONS), but we don't support Ubuntu 248 fi 249 echo 250 251 if containsElement "all" "${MOUNT_OPTIONS[@]}" || containsElement "nfs" "${MOUNT_OPTIONS[@]}"; then 252 mountpoint -q $SHARE_NFS 253 if [ $? -ne 0 ]; then 254 for i in $(seq 5); do 255 sleep 5 256 sudo $MOUNT -t nfs -o vers=$NFS_VERS $MOUNT_POINT_NFS $SHARE_NFS && break 257 echo "Mount of $SHARE_NFS failed. Retrying..." 258 done 259 fi 260 261 mountpoint -q $SHARE_NFS 262 if [ $? -ne 0 ]; then 263 echo "ERROR: Could not mount $SHARE_NFS." 264 exit 1 265 else 266 echo "$SHARE_NFS successfully mounted" 267 fi 268 fi 269 270 if containsElement "all" "${MOUNT_OPTIONS[@]}" || containsElement "smb" "${MOUNT_OPTIONS[@]}" || containsElement "smb1" "${MOUNT_OPTIONS[@]}" || containsElement "smb2" "${MOUNT_OPTIONS[@]}" || containsElement "smb3" "${MOUNT_OPTIONS[@]}"; then 271 mountpoint -q $SHARE_SMB 272 if [ $? -ne 0 ]; then 273 for i in $(seq 5); do 274 sleep 5 275 sudo $MOUNT -t cifs -o user=swift,password=swift,uid=$UID_SMB,gid=$GID_SMB,vers=$SMB_VERS,iocharset=utf8,actimeo=0 $MOUNT_POINT_SMB $SHARE_SMB && break 276 echo "Mount of $SHARE_SMB failed. Retrying..." 277 done 278 fi 279 280 mountpoint -q $SHARE_SMB 281 if [ $? -ne 0 ]; then 282 echo "ERROR: Could not mount $SHARE_SMB." 283 exit 1 284 else 285 echo "$SHARE_SMB successfully mounted" 286 fi 287 fi