"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/extras/hook-scripts/start/post/S31ganesha-start.sh" (16 Sep 2020, 3524 Bytes) of package /linux/misc/glusterfs-8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/bash
    2 PROGNAME="Sganesha-start"
    3 OPTSPEC="volname:,gd-workdir:"
    4 VOL=
    5 declare -i EXPORT_ID
    6 ganesha_key="ganesha.enable"
    7 GANESHA_DIR="/var/run/gluster/shared_storage/nfs-ganesha"
    8 CONF1="$GANESHA_DIR/ganesha.conf"
    9 GLUSTERD_WORKDIR=
   10 
   11 function parse_args ()
   12 {
   13         ARGS=$(getopt -l $OPTSPEC  -o "o" -name $PROGNAME $@)
   14         eval set -- "$ARGS"
   15 
   16         while true; do
   17             case $1 in
   18                 --volname)
   19                     shift
   20                     VOL=$1
   21                     ;;
   22                 --gd-workdir)
   23                     shift
   24                     GLUSTERD_WORKDIR=$1
   25                     ;;
   26                 *)
   27                     shift
   28                     break
   29                     ;;
   30             esac
   31             shift
   32         done
   33 }
   34 
   35 
   36 
   37 #This function generates a new export entry as export.volume_name.conf
   38 function write_conf()
   39 {
   40 echo -e "# WARNING : Using Gluster CLI will overwrite manual
   41 # changes made to this file. To avoid it, edit the
   42 # file, copy it over to all the NFS-Ganesha nodes
   43 # and run ganesha-ha.sh --refresh-config."
   44 
   45 echo "EXPORT{"
   46 echo "      Export_Id = 2;"
   47 echo "      Path = \"/$VOL\";"
   48 echo "      FSAL {"
   49 echo "           name = \"GLUSTER\";"
   50 echo "           hostname=\"localhost\";"
   51 echo "           volume=\"$VOL\";"
   52 echo "           }"
   53 echo "      Access_type = RW;"
   54 echo "      Disable_ACL = true;"
   55 echo "      Squash=\"No_root_squash\";"
   56 echo "      Pseudo=\"/$VOL\";"
   57 echo "      Protocols = \"3\", \"4\" ;"
   58 echo "      Transports = \"UDP\",\"TCP\";"
   59 echo "      SecType = \"sys\";"
   60 echo "}"
   61 }
   62 
   63 #It adds the export dynamically by sending dbus signals
   64 function export_add()
   65 {
   66         dbus-send --print-reply --system --dest=org.ganesha.nfsd \
   67 /org/ganesha/nfsd/ExportMgr org.ganesha.nfsd.exportmgr.AddExport \
   68 string:$GANESHA_DIR/exports/export.$VOL.conf string:"EXPORT(Export_Id=$EXPORT_ID)"
   69 
   70 }
   71 
   72 # based on src/scripts/ganeshactl/Ganesha/export_mgr.py
   73 function is_exported()
   74 {
   75         local volume="${1}"
   76 
   77         dbus-send --type=method_call --print-reply --system \
   78                   --dest=org.ganesha.nfsd /org/ganesha/nfsd/ExportMgr \
   79                   org.ganesha.nfsd.exportmgr.ShowExports \
   80             | grep -w -q "/${volume}"
   81 
   82         return $?
   83 }
   84 
   85 # Check the info file (contains the volume options) to see if Ganesha is
   86 # enabled for this volume.
   87 function ganesha_enabled()
   88 {
   89         local volume="${1}"
   90         local info_file="${GLUSTERD_WORKDIR}/vols/${VOL}/info"
   91         local enabled="off"
   92 
   93         enabled=$(grep -w ${ganesha_key} ${info_file} | cut -d"=" -f2)
   94 
   95         [ "${enabled}" == "on" ]
   96 
   97         return $?
   98 }
   99 
  100 parse_args $@
  101 
  102 if ganesha_enabled ${VOL} && ! is_exported ${VOL}
  103 then
  104         if [ ! -e ${GANESHA_DIR}/exports/export.${VOL}.conf ]
  105         then
  106                 #Remove export entry from nfs-ganesha.conf
  107                 sed -i /$VOL.conf/d  $CONF1
  108                 write_conf ${VOL} > ${GANESHA_DIR}/exports/export.${VOL}.conf
  109                 EXPORT_ID=`cat $GANESHA_DIR/.export_added`
  110                 EXPORT_ID=EXPORT_ID+1
  111                 echo $EXPORT_ID > $GANESHA_DIR/.export_added
  112                 sed -i s/Export_Id.*/"Export_Id=$EXPORT_ID;"/ \
  113                         $GANESHA_DIR/exports/export.$VOL.conf
  114                 echo "%include \"$GANESHA_DIR/exports/export.$VOL.conf\"" >> $CONF1
  115         else
  116                 EXPORT_ID=$(grep ^[[:space:]]*Export_Id $GANESHA_DIR/exports/export.$VOL.conf |\
  117                           awk -F"[=,;]" '{print $2}' | tr -d '[[:space:]]')
  118         fi
  119         export_add $VOL
  120 fi
  121 
  122 exit 0