summaryrefslogtreecommitdiffstats
path: root/extras/hook-scripts/set
diff options
context:
space:
mode:
Diffstat (limited to 'extras/hook-scripts/set')
-rw-r--r--extras/hook-scripts/set/post/Makefile.am7
-rwxr-xr-xextras/hook-scripts/set/post/S30samba-set.sh50
-rwxr-xr-xextras/hook-scripts/set/post/S31ganesha-set.sh290
-rwxr-xr-xextras/hook-scripts/set/post/S32gluster_enable_shared_storage.sh136
4 files changed, 174 insertions, 309 deletions
diff --git a/extras/hook-scripts/set/post/Makefile.am b/extras/hook-scripts/set/post/Makefile.am
index 3ec25d94134..506a25a8666 100644
--- a/extras/hook-scripts/set/post/Makefile.am
+++ b/extras/hook-scripts/set/post/Makefile.am
@@ -1 +1,6 @@
-EXTRA_DIST = S30samba-set.sh S31ganesha-set.sh
+EXTRA_DIST = S30samba-set.sh S32gluster_enable_shared_storage.sh
+
+hookdir = $(GLUSTERD_WORKDIR)/hooks/1/set/post/
+if WITH_SERVER
+hook_SCRIPTS = $(EXTRA_DIST)
+endif
diff --git a/extras/hook-scripts/set/post/S30samba-set.sh b/extras/hook-scripts/set/post/S30samba-set.sh
index b8c5acf4cde..854f131f6c8 100755
--- a/extras/hook-scripts/set/post/S30samba-set.sh
+++ b/extras/hook-scripts/set/post/S30samba-set.sh
@@ -28,7 +28,7 @@ USERSMB_SET=""
USERCIFS_SET=""
function parse_args () {
- ARGS=$(getopt -l $OPTSPEC -o "o" -name $PROGNAME $@)
+ ARGS=$(getopt -o 'o:' -l $OPTSPEC -n $PROGNAME -- "$@")
eval set -- "$ARGS"
while true; do
@@ -41,10 +41,13 @@ function parse_args () {
shift
GLUSTERD_WORKDIR=$1
;;
- *)
+ --)
shift
- for pair in $@; do
- read key value < <(echo "$pair" | tr "=" " ")
+ break
+ ;;
+ -o)
+ shift
+ read key value < <(echo "$1" | tr "=" " ")
case "$key" in
"user.cifs")
USERCIFS_SET="YES"
@@ -55,7 +58,8 @@ function parse_args () {
*)
;;
esac
- done
+ ;;
+ *)
shift
break
;;
@@ -85,7 +89,7 @@ function add_samba_share () {
STRING+="glusterfs:loglevel = 7\n"
STRING+="path = /\n"
STRING+="read only = no\n"
- STRING+="guest ok = yes\n"
+ STRING+="kernel share modes = no\n"
printf "$STRING" >> ${CONFIGFILE}
}
@@ -95,13 +99,13 @@ function sighup_samba () {
then
kill -HUP "$pid";
else
- /etc/init.d/smb condrestart
+ service smb condrestart
fi
}
-function del_samba_share () {
+function deactivate_samba_share () {
volname=$1
- sed -i "/\[gluster-$volname\]/,/^$/d" ${CONFIGFILE}
+ sed -i -e '/^\[gluster-'"$volname"'\]/{ :a' -e 'n; /available = no/H; /^$/!{$!ba;}; x; /./!{ s/^/available = no/; $!{G;x}; $H; }; s/.*//; x; };' ${CONFIGFILE}
}
function is_volume_started () {
@@ -119,29 +123,39 @@ function get_smb () {
usersmbvalue=$(grep user.smb $GLUSTERD_WORKDIR/vols/"$volname"/info |\
cut -d"=" -f2)
- if [[ $usercifsvalue = "disable" || $usersmbvalue = "disable" ]]; then
- uservalue="disable"
+ if [ -n "$usercifsvalue" ]; then
+ if [ "$usercifsvalue" = "disable" ] || [ "$usercifsvalue" = "off" ]; then
+ uservalue="disable"
+ fi
+ fi
+
+ if [ -n "$usersmbvalue" ]; then
+ if [ "$usersmbvalue" = "disable" ] || [ "$usersmbvalue" = "off" ]; then
+ uservalue="disable"
+ fi
fi
+
echo "$uservalue"
}
-parse_args $@
-if [ "0" = $(is_volume_started "$VOL") ]; then
+parse_args "$@"
+if [ "0" = "$(is_volume_started "$VOL")" ]; then
exit 0
fi
-if [[ "$USERCIFS_SET" = "YES" || "$USERSMB_SET" = "YES" ]]; then
+if [ "$USERCIFS_SET" = "YES" ] || [ "$USERSMB_SET" = "YES" ]; then
#Find smb.conf, smbd pid directory and smbd logfile path
find_config_info
- if [ $(get_smb "$VOL") = "disable" ]; then
- del_samba_share $VOL
- sighup_samba
+ if [ "$(get_smb "$VOL")" = "disable" ]; then
+ deactivate_samba_share $VOL
else
if ! grep --quiet "\[gluster-$VOL\]" ${CONFIGFILE} ; then
add_samba_share $VOL
- sighup_samba
+ else
+ sed -i '/\[gluster-'"$VOL"'\]/,/^$/!b;/available = no/d' ${CONFIGFILE}
fi
fi
+ sighup_samba
fi
diff --git a/extras/hook-scripts/set/post/S31ganesha-set.sh b/extras/hook-scripts/set/post/S31ganesha-set.sh
deleted file mode 100755
index f839aa37061..00000000000
--- a/extras/hook-scripts/set/post/S31ganesha-set.sh
+++ /dev/null
@@ -1,290 +0,0 @@
-#!/bin/bash
-PROGNAME="Sganesha-set"
-OPTSPEC="volname:,gd-workdir:"
-VOL=
-declare -i EXPORT_ID
-ganesha_key="FALSE"
-GANESHA_DIR="/var/lib/glusterfs-ganesha"
-CONF1="$GANESHA_DIR/nfs-ganesha.conf"
-GANESHA_LOG_DIR="/var/log/nfs-ganesha/"
-LOG="$GANESHA_LOG_DIR/ganesha.nfsd.log"
-gnfs="enabled"
-enable_ganesha=""
-host_name="none"
-LOC=""
-GLUSTERD_WORKDIR=
-
-function parse_args ()
-{
- ARGS=$(getopt -l $OPTSPEC -o "o" -name $PROGNAME $@)
- eval set -- "$ARGS"
-
- while true; do
- case $1 in
- --volname)
- shift
- VOL=$1
- ;;
- --gd-workdir)
- shift
- GLUSTERD_WORKDIR=$1
- ;;
- *)
- shift
- for pair in $@; do
- read key value < <(echo "$pair" | tr "=" " ")
- case "$key" in
- "nfs-ganesha.enable")
- enable_ganesha=$value
- ganesha_key="TRUE"
- ;;
- "nfs-ganesha.host")
- host_name=$value
- ganesha_key="TRUE"
- ;;
- *)
- ;;
- esac
- done
- shift
- break
- ;;
- esac
- shift
- done
-}
-
-
-function check_if_host_set()
-{
- if ! cat $GLUSTERD_WORKDIR/vols/$VOL/info | grep -q "nfs-ganesha.host"
- then
- exit 1
- fi
-}
-
-function check_nfsd_loc()
-{
- if ls /usr/bin | grep "[g]anesha.nfsd"
- then
- LOC="/usr"
- else
- LOC="/usr/local"
- fi
-}
-
-
-function check_gluster_nfs()
-{
- if cat $GLUSTERD_WORKDIR/vols/$VOL/info | grep -q "nfs.disable=ON"
- then
- gnfs="disabled"
- fi
-}
-
-function check_cmd_status()
-{
- if [ "$1" != "0" ]
- then
- rm -rf $GANESHA_DIR/exports/export.$VOL.conf
- exit 1
- fi
-}
-
-
-
-#This function generates a new export entry as export.volume_name.conf
-function write_conf()
-{
- echo "EXPORT{
- "
- echo "Export_Id = ;"
- echo "Path=\"/$1\";"
- echo "FSAL {
- "
- echo "name = "GLUSTER";"
- echo "hostname=\"$2\";"
- echo "volume=\"$1\";"
- echo "}"
- echo "Access_type = RW;"
- echo "Squash = No_root_squash;"
- echo "Disable_ACL = TRUE;"
- echo "Pseudo=\"/$1\";"
- echo "Protocols = \"3,4\" ;"
- echo "Transports = \"UDP,TCP\" ;"
- echo "SecType = \"sys\";"
- echo "Tag = \"$1\";"
- echo "}"
-}
-
-#This function keeps track of export IDs and increments it with every new entry
-function export_add()
-{
- count=`ls -l $GANESHA_DIR/exports/*.conf | wc -l`
- if [ "$count" = "1" ] ;
- then
- EXPORT_ID=1
- else
- #if [ -s /var/lib/ganesha/export_removed ];
- # then
- # EXPORT_ID=`head -1 /var/lib/ganesha/export_removed`
- # sed -i -e "1d" /var/lib/ganesha/export_removed
- # else
-
- EXPORT_ID=`cat $GANESHA_DIR/.export_added`
- check_cmd_status `echo $?`
- EXPORT_ID=EXPORT_ID+1
- #fi
- fi
- echo $EXPORT_ID > $GANESHA_DIR/.export_added
- check_cmd_status `echo $?`
- sed -i s/Export_Id.*/"Export_Id = $EXPORT_ID ;"/ \
-$GANESHA_DIR/exports/export.$VOL.conf
- echo "%include \"$GANESHA_DIR/exports/export.$VOL.conf\"" >> $CONF1
- check_cmd_status `echo $?`
-}
-
-#This function removes an export dynamically(uses the export_id of the export)
-function dynamic_export_remove()
-{
- removed_id=`cat $GANESHA_DIR/exports/export.$VOL.conf |\
-grep Export_Id | cut -d " " -f3`
- check_cmd_status `echo $?`
- dbus-send --print-reply --system \
---dest=org.ganesha.nfsd /org/ganesha/nfsd/ExportMgr \
-org.ganesha.nfsd.exportmgr.RemoveExport uint16:$removed_id
- check_cmd_status `echo $?`
-
-}
-
-#This function adds a new export dynamically by sending dbus signals
-function dynamic_export_add()
-{
- dbus-send --print-reply --system --dest=org.ganesha.nfsd \
-/org/ganesha/nfsd/ExportMgr org.ganesha.nfsd.exportmgr.AddExport \
-string:$GANESHA_DIR/exports/export.$VOL.conf string:"EXPORT(Tag=$VOL)"
- check_cmd_status `echo $?`
-
-}
-
-function start_ganesha()
-{
- check_gluster_nfs
- #Remove export entry from nfs-ganesha.conf
- sed -i /$VOL.conf/d $CONF1
- #Create a new export entry
- export_add
- if ! ps aux | grep -q "[g]anesha.nfsd"
- then
- if ls /usr/bin/ganesha.nfsd
- then
- /usr/bin/ganesha.nfsd -f $CONF1 -L $LOG -N NIV_EVENT -d
- sleep 2
- else
- /usr/local/bin/ganesha.nfsd -f $CONF1 -L $LOG -N NIV_EVENT -d
- sleep 2
- fi
- else
- dynamic_export_add $VOL
- fi
-
-
- if !( ps aux | grep -q "[g]anesha.nfsd")
- then
- rm -rf $GANESHA_DIR/exports/*
- rm -rf $GANESHA_DIR/.export_added
- exit 1
- fi
-
-}
-
-#This function generates a new config file when ganesha.host is set
-#If the volume is already exported, only hostname is changed
-function set_hostname()
-{
- if ! ls $GANESHA_DIR/exports/ | grep -q $VOL.conf
- then
- write_conf $VOL $host_name >\
-$GANESHA_DIR/exports/export.$VOL.conf
- else
- sed -i s/hostname.*/"hostname=\
-\"$host_name\";"/ $GANESHA_DIR/exports/export.$VOL.conf
- fi
-}
-
-
-function check_ganesha_dir()
-{
- #Check if the configuration file is placed in /etc/glusterfs-ganesha
- if ! ls /etc/glusterfs-ganesha | grep "nfs-ganesha.conf"
- then
- exit 1
- else
- if [ ! -d "$GANESHA_DIR" ];
- then
- mkdir $GANESHA_DIR
- check_cmd_status `echo $?`
- fi
- cp /etc/glusterfs-ganesha/nfs-ganesha.conf $GANESHA_DIR/
- check_cmd_status `echo $?`
- fi
- if [ ! -d "$GANESHA_DIR/exports" ];
- then
- mkdir $GANESHA_DIR/exports
- check_cmd_status `echo $?`
- fi
- if [ ! -d "$GANESHA_LOG_DIR" ] ;
- then
- mkdir $GANESHA_LOG_DIR
- check_cmd_status `echo $?`
- fi
-
-
-
-}
-
-function stop_ganesha()
-{
- dynamic_export_remove $VOL
- #Remove the specfic export configuration file
- rm -rf $GANESHA_DIR/exports/export.$VOL.conf
- #Remove that entry from nfs-ganesha.conf
- sed -i /$VOL.conf/d $CONF1
- #If there are no other volumes exported, stop nfs-ganesha
- if [ ! "$(ls -A $GANESHA_DIR/exports)" ];
- then
- pkill ganesha.nfsd
- rm -rf $GANESHA_DIR/.export_added
- fi
-}
-
- parse_args $@
- if [ "$ganesha_key" == "FALSE" ]
- then
- exit 0
- fi
- check_ganesha_dir $VOL
- if echo $enable_ganesha | grep -q -i "ON"
- then
- check_if_host_set $VOL
- if ! showmount -e localhost | cut -d "" -f1 | grep -q "$VOL[[:space:]]"
- then
- start_ganesha
- fi
- elif echo $enable_ganesha | grep -q -i "OFF"
- then
- check_if_host_set $VOL
- stop_ganesha
- fi
- if [ "$host_name" != "none" ];
- then
- if showmount -e localhost | cut -d "" -f1 | grep -q "$VOL[[:space:]]"
- then
- dynamic_export_remove $VOL
- set_hostname
- start_ganesha
- else
- set_hostname
- fi
-
- fi
diff --git a/extras/hook-scripts/set/post/S32gluster_enable_shared_storage.sh b/extras/hook-scripts/set/post/S32gluster_enable_shared_storage.sh
new file mode 100755
index 00000000000..1f2564b44ff
--- /dev/null
+++ b/extras/hook-scripts/set/post/S32gluster_enable_shared_storage.sh
@@ -0,0 +1,136 @@
+#!/bin/bash
+
+key=`echo $3 | cut -d '=' -f 1`
+val=`echo $3 | cut -d '=' -f 2`
+if [ "$key" != "cluster.enable-shared-storage" ] && [ "$key" != "enable-shared-storage" ]; then
+ exit;
+fi
+if [ "$val" != 'enable' ]; then
+ if [ "$val" != 'disable' ]; then
+ exit;
+ fi
+fi
+
+option=$val
+
+key_val_pair1=`echo $4 | cut -d ',' -f 1`
+key_val_pair2=`echo $4 | cut -d ',' -f 2`
+
+key=`echo $key_val_pair1 | cut -d '=' -f 1`
+val=`echo $key_val_pair1 | cut -d '=' -f 2`
+if [ "$key" != "is_originator" ]; then
+ exit;
+fi
+is_originator=$val;
+
+key=`echo $key_val_pair2 | cut -d '=' -f 1`
+val=`echo $key_val_pair2 | cut -d '=' -f 2`
+if [ "$key" != "local_node_hostname" ]; then
+ exit;
+fi
+local_node_hostname=$val;
+
+# Read gluster peer status to find the peers
+# which are in 'Peer in Cluster' mode and
+# are connected.
+
+number_of_connected_peers=0
+while read -r line
+do
+ # Already got two connected peers. Including the current node
+ # we have 3 peers which is enough to create a shared storage
+ # with replica 3
+ if [ "$number_of_connected_peers" == "2" ]; then
+ break;
+ fi
+
+ key=`echo $line | cut -d ':' -f 1`
+ if [ "$key" == "Hostname" ]; then
+ hostname=`echo $line | cut -d ':' -f 2 | xargs`
+ fi
+
+ if [ "$key" == "State" ]; then
+ peer_state=`echo $line | cut -d ':' -f 2 | cut -d '(' -f 1 | xargs`
+ conn_state=`echo $line | cut -d '(' -f 2 | cut -d ')' -f 1 | xargs`
+
+ if [ "$peer_state" == "Peer in Cluster" ]; then
+ if [ "$conn_state" == "Connected" ]; then
+ ((number_of_connected_peers++))
+ connected_peer[$number_of_connected_peers]=$hostname
+ fi
+ fi
+ fi
+
+done < <(gluster peer status)
+
+# Include current node in connected peer list
+((number_of_connected_peers++))
+connected_peer[$number_of_connected_peers]=$local_node_hostname
+
+# forming the create vol command
+create_cmd="gluster --mode=script --wignore volume create \
+ gluster_shared_storage replica $number_of_connected_peers"
+
+# Adding the brick names in the command
+for i in "${connected_peer[@]}"
+do
+ create_cmd=$create_cmd" "$i:"$GLUSTERD_WORKDIR"/ss_brick
+done
+
+if [ "$option" == "disable" ]; then
+ # Unmount the volume on all the nodes
+ umount /run/gluster/shared_storage
+ cat /etc/fstab | grep -v "gluster_shared_storage /run/gluster/shared_storage/" > /run/gluster/fstab.tmp
+ mv /run/gluster/fstab.tmp /etc/fstab
+fi
+
+if [ "$is_originator" == 1 ]; then
+ if [ "$option" == "enable" ]; then
+ # Create and start the volume
+ $create_cmd
+ gluster --mode=script --wignore volume start gluster_shared_storage
+ fi
+
+ if [ "$option" == "disable" ]; then
+ # Stop and delete the volume
+ gluster --mode=script --wignore volume stop gluster_shared_storage
+ gluster --mode=script --wignore volume delete gluster_shared_storage
+ fi
+fi
+
+function check_volume_status()
+{
+ status=`gluster volume info gluster_shared_storage | grep Status | cut -d ':' -f 2 | xargs`
+ echo $status
+}
+
+key=`echo $5 | cut -d '=' -f 1`
+val=`echo $5 | cut -d '=' -f 2`
+if [ "$key" == "transport.address-family" ]; then
+ mount_cmd="mount -t glusterfs -o xlator-option=transport.address-family=inet6 \
+ $local_node_hostname:/gluster_shared_storage /run/gluster/shared_storage"
+else
+ mount_cmd="mount -t glusterfs $local_node_hostname:/gluster_shared_storage \
+ /run/gluster/shared_storage"
+fi
+
+if [ "$option" == "enable" ]; then
+ retry=0;
+ # Wait for volume to start before mounting
+ status=$(check_volume_status)
+ while [ "$status" != "Started" ]; do
+ sleep 5;
+ ((retry++))
+ if [ "$retry" == 3 ]; then
+ break;
+ fi
+ status=$(check_volume_status)
+ done
+ # Mount the volume on all the nodes
+ umount /run/gluster/shared_storage
+ mkdir -p /run/gluster/shared_storage
+ $mount_cmd
+ cp /etc/fstab /run/gluster/fstab.tmp
+ echo "$local_node_hostname:/gluster_shared_storage /run/gluster/shared_storage/ glusterfs defaults 0 0" >> /run/gluster/fstab.tmp
+ mv /run/gluster/fstab.tmp /etc/fstab
+fi