github.com/swiftstack/ProxyFS@v0.0.0-20210203235616-4017c267d62f/cookbooks/proxyfs/files/default/usr/bin/start_and_mount_pfs (about)

     1  #!/bin/bash
     2  
     3  # Copyright (c) 2015-2021, NVIDIA CORPORATION.
     4  # SPDX-License-Identifier: Apache-2.0
     5  
     6  # A simple script to start the services and mount the sample mount point
     7  # The PATH, etc should already be setup by systemctl environment
     8  
     9  function await_proxyfsd_startup {
    10      /usr/bin/systemctl -q is-active proxyfsd
    11      if [ $? -ne 0 ]; then
    12          echo "ProxyFS failed to start. Exiting..."
    13          exit 1
    14      fi
    15      while true; do
    16          curl http://127.0.0.1:15346/ 2>/dev/null >/dev/null
    17          if [ $? -eq 0 ]; then
    18              break
    19          fi
    20          echo "Waiting for ProxyFS to be started..."
    21          sleep 1
    22      done
    23  }
    24  
    25  function await_pfsagentd_startup {
    26      /usr/bin/systemctl -q is-active pfsagentd
    27      if [ $? -ne 0 ]; then
    28          echo "PFSAgent failed to start. Exiting..."
    29          exit 1
    30      fi
    31      while true; do
    32          curl http://127.0.0.1:9090/version 2>/dev/null >/dev/null
    33          if [ $? -eq 0 ]; then
    34              # Service is active and curl to the HTTP server succeeded.
    35              # We're go to go.
    36              break
    37          fi
    38          echo "Waiting for PFSAgent to be started..."
    39          sleep 1
    40      done
    41  }
    42  
    43  function await_swift_startup {
    44      while true
    45      do
    46          curl http://127.0.0.1:8090/info 2>/dev/null >/dev/null
    47          if [ $? -eq 0 ]
    48          then
    49              break
    50          fi
    51          echo "Waiting for Swift to be started..."
    52          sleep 1
    53      done
    54  }
    55  
    56  function format_volume_if_necessary {
    57      sudo $GOPATH/bin/mkproxyfs -I $1 /etc/proxyfsd/saioproxyfsd0.conf SwiftClient.RetryLimit=1
    58      if [ $? -ne 0 ]
    59      then
    60          echo "Could not pre-format $1"
    61          exit 1
    62      fi
    63  }
    64  
    65  function containsElement () {
    66    local e match="$1"
    67    shift
    68    for e; do [[ "$e" == "$match" ]] && return 0; done
    69    return 1
    70  }
    71  
    72  # Making sure $GOPATH contains something:
    73  source ~/.bashrc
    74  if [ -z "$GOPATH" ]; then
    75      GOPATH=/home/swift/code/ProxyFS
    76  fi
    77  
    78  sudo mount -a
    79  
    80  echo "Shutting down services and mount points..."
    81  /usr/bin/unmount_and_stop_pfs
    82  echo
    83  
    84  echo "Bringing up services..."
    85  if [ -f /usr/bin/systemctl ]; then
    86      # Centos
    87      MOUNT=/usr/bin/mount
    88      sudo /usr/bin/systemctl start memcached
    89      sudo /usr/bin/swift-init main start
    90      await_swift_startup
    91      format_volume_if_necessary CommonVolume
    92      sudo /usr/bin/systemctl start proxyfsd
    93      await_proxyfsd_startup
    94      echo "ProxyFS successfully started"
    95      echo "Starting PFSAgent..."
    96      sudo /usr/bin/systemctl start pfsagentd
    97      await_pfsagentd_startup
    98  else
    99      # Ubuntu (not tested!)
   100      MOUNT=/bin/mount
   101      sudo /usr/sbin/service memcached start
   102      sudo /usr/bin/swift-init main start
   103      await_swift_startup
   104      format_volume_if_necessary CommonVolume
   105      sudo /usr/sbin/service proxyfsd start
   106      await_proxyfsd_startup
   107      echo "ProxyFS successfully started"
   108      # Here we should start pfsagentd (if 'all' or 'pfsa' are present in
   109      # $MOUNT_OPTIONS), but we don't support Ubuntu
   110  fi
   111  echo