From 7fb03a0ade154b0c21a71ce0e776a06e50510016 Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Tue, 29 May 2012 01:33:31 +0530 Subject: extras: Restructuring hook-scripts directory - Fixed permissions of samba-start and samba-stop scripts - Fixed string comparison in sighup_samba function Change-Id: I5529cf2f4d7c08ac8fafcf64652be856345c9476 BUG: 806996 Signed-off-by: Krishnan Parthasarathi Signed-off-by: Vijay Bellur --- extras/hook-scripts/Makefile.am | 3 +- extras/hook-scripts/S29CTDBsetup.sh | 69 ------------------------ extras/hook-scripts/S30samba-start.sh | 62 --------------------- extras/hook-scripts/S30samba-stop.sh | 60 --------------------- extras/hook-scripts/start/Makefile.am | 2 + extras/hook-scripts/start/post/Makefile.am | 1 + extras/hook-scripts/start/post/S29CTDBsetup.sh | 69 ++++++++++++++++++++++++ extras/hook-scripts/start/post/S30samba-start.sh | 62 +++++++++++++++++++++ extras/hook-scripts/start/post/S30samba-stop.sh | 60 +++++++++++++++++++++ 9 files changed, 196 insertions(+), 192 deletions(-) delete mode 100644 extras/hook-scripts/S29CTDBsetup.sh delete mode 100755 extras/hook-scripts/S30samba-start.sh delete mode 100755 extras/hook-scripts/S30samba-stop.sh create mode 100644 extras/hook-scripts/start/Makefile.am create mode 100644 extras/hook-scripts/start/post/Makefile.am create mode 100644 extras/hook-scripts/start/post/S29CTDBsetup.sh create mode 100644 extras/hook-scripts/start/post/S30samba-start.sh create mode 100644 extras/hook-scripts/start/post/S30samba-stop.sh (limited to 'extras/hook-scripts') diff --git a/extras/hook-scripts/Makefile.am b/extras/hook-scripts/Makefile.am index 5c6249de707..2fa5f137a5d 100644 --- a/extras/hook-scripts/Makefile.am +++ b/extras/hook-scripts/Makefile.am @@ -1 +1,2 @@ -EXTRA_DIST = S29CTDBsetup.sh S30samba-start.sh S30samba-stop.sh +SUBDIRS = start +CLEANFILES = diff --git a/extras/hook-scripts/S29CTDBsetup.sh b/extras/hook-scripts/S29CTDBsetup.sh deleted file mode 100644 index e256be1f3ea..00000000000 --- a/extras/hook-scripts/S29CTDBsetup.sh +++ /dev/null @@ -1,69 +0,0 @@ -#! /bin/bash -#non-portable - RHS-2.0 only -# - The script mounts the 'meta-vol' on start 'event' on a known -# directory (eg. /gluster/lock) -# - Adds the necessary configuration changes for ctdb in smb.conf and -# restarts smb service. -# - P.S: There are other 'tasks' that need to be done outside this script -# to get CTDB based failover up and running. - -SMB_CONF=/etc/samba/smb.conf - -CTDB_MNT=/gluster/lock -PROGNAME="ctdb" -OPTSPEC="volname:" -VOL= -# $META is the volume that will be used by CTDB as a shared filesystem. -# It is not desirable to use this volume for storing 'data' as well. -# META is set to 'all' (viz. a keyword and hence not a legal volume name) -# to prevent the script from running for volumes it was not intended. -# User needs to set META to the volume that serves CTDB lockfile. -META="all" - -function sighup_samba () { - pid=`cat /var/run/smbd.pid` - if [ $pid != " " ] - then - kill -HUP $pid; - else - /etc/init.d/smb start - fi -} - -function parse_args () { - ARGS=$(getopt -l $OPTSPEC -name $PROGNAME $@) - eval set -- "$ARGS" - - while true; do - case $1 in - --volname) - shift - VOL=$1 - ;; - - *) - shift - break - ;; - - esac - - shift - done -} - -function add_glusterfs_ctdb_options () { - PAT="Share Definitions" - GLUSTER_CTDB_CONFIG="# ctdb config for glusterfs\n\tclustering = yes\n\tidmap backend = tdb2\n\tprivate dir = "$CTDB_MNT"\n" - - sed -i /"$PAT"/i\ "$GLUSTER_CTDB_CONFIG" $SMB_CONF -} - -parse_args $@ -if [ "$META" = "$VOL" ] -then - add_glusterfs_ctdb_options - sighup_samba - mount -t glusterfs `hostname`:$VOL "$CTDB_MNT" & -fi - diff --git a/extras/hook-scripts/S30samba-start.sh b/extras/hook-scripts/S30samba-start.sh deleted file mode 100755 index a42bb07eba8..00000000000 --- a/extras/hook-scripts/S30samba-start.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash -#Need to be copied to hooks//start/post - -PROGNAME="Ssamba-start" -OPTSPEC="volname:,mnt:" -VOL= -#FIXME: glusterd hook interface will eventually provide mntpt prefix as -# command line arg -MNT_PRE="/mnt/samba" - -function parse_args () { - ARGS=$(getopt -l $OPTSPEC -name $PROGNAME $@) - eval set -- "$ARGS" - - while true; do - case $1 in - --volname) - shift - VOL=$1 - ;; - --mnt) - shift - MNT_PRE=$1 - ;; - *) - shift - break - ;; - esac - shift - done -} - -function add_samba_export () { - volname=$1 - mnt_pre=$2 - mkdir -p $mnt_pre/$volname && \ - printf "\n[gluster-$volname]\ncomment=For samba export of volume $volname\npath=$mnt_pre/$volname\nread only=no\nguest ok=yes\n" >> /etc/samba/smb.conf -} - -function mount_volume () { - volname=$1 - mnt_pre=$2 - #Mount shouldn't block on glusterd to fetch volfile, hence the 'bg' - mount -t glusterfs `hostname`:$volname $mnt_pre/$volname & -} - -function sighup_samba () { - pid=`cat /var/run/smbd.pid` - if [ $pid != "" ] - then - kill -HUP $pid; - else - /etc/init.d/smb start - fi -} - - -parse_args $@ -add_samba_export $VOL $MNT_PRE -mount_volume $VOL $MNT_PRE -sighup_samba diff --git a/extras/hook-scripts/S30samba-stop.sh b/extras/hook-scripts/S30samba-stop.sh deleted file mode 100755 index 0e483bff835..00000000000 --- a/extras/hook-scripts/S30samba-stop.sh +++ /dev/null @@ -1,60 +0,0 @@ -#! /bin/bash -#Need to be copied to hooks//stop/post - -PROGNAME="Ssamba-stop" -OPTSPEC="volname:,mnt:" -VOL= -#FIXME: gluster will eventually pass mnt prefix as command line argument -MNT_PRE="/mnt/samba" - -function parse_args () { - ARGS=$(getopt -l $OPTSPEC -name $PROGNAME $@) - eval set -- "$ARGS" - - while true; do - case $1 in - --volname) - shift - VOL=$1 - ;; - --mnt) - shift - MNT_PRE=$1 - echo $1 - ;; - *) - shift - break - ;; - esac - shift - done -} - -function del_samba_export () { - volname=$1 - cp /etc/samba/smb.conf /tmp/smb.conf - sed -i "/gluster-$volname/,/^$/d" /tmp/smb.conf &&\ - mv /tmp/smb.conf /etc/samba/smb.conf -} - -function umount_volume () { - volname=$1 - mnt_pre=$2 - umount -l $mnt_pre/$volname -} - -function sighup_samba () { - pid=`cat /var/run/smbd.pid` - if [ $pid != "" ] - then - kill -HUP $pid; - else - /etc/init.d/smb start - fi -} - -parse_args $@ -del_samba_export $VOL -umount_volume $VOL $MNT_PRE -sighup_samba diff --git a/extras/hook-scripts/start/Makefile.am b/extras/hook-scripts/start/Makefile.am new file mode 100644 index 00000000000..1fcade4b07f --- /dev/null +++ b/extras/hook-scripts/start/Makefile.am @@ -0,0 +1,2 @@ +SUBDIRS = post +CLEANFILES = diff --git a/extras/hook-scripts/start/post/Makefile.am b/extras/hook-scripts/start/post/Makefile.am new file mode 100644 index 00000000000..5c6249de707 --- /dev/null +++ b/extras/hook-scripts/start/post/Makefile.am @@ -0,0 +1 @@ +EXTRA_DIST = S29CTDBsetup.sh S30samba-start.sh S30samba-stop.sh diff --git a/extras/hook-scripts/start/post/S29CTDBsetup.sh b/extras/hook-scripts/start/post/S29CTDBsetup.sh new file mode 100644 index 00000000000..e256be1f3ea --- /dev/null +++ b/extras/hook-scripts/start/post/S29CTDBsetup.sh @@ -0,0 +1,69 @@ +#! /bin/bash +#non-portable - RHS-2.0 only +# - The script mounts the 'meta-vol' on start 'event' on a known +# directory (eg. /gluster/lock) +# - Adds the necessary configuration changes for ctdb in smb.conf and +# restarts smb service. +# - P.S: There are other 'tasks' that need to be done outside this script +# to get CTDB based failover up and running. + +SMB_CONF=/etc/samba/smb.conf + +CTDB_MNT=/gluster/lock +PROGNAME="ctdb" +OPTSPEC="volname:" +VOL= +# $META is the volume that will be used by CTDB as a shared filesystem. +# It is not desirable to use this volume for storing 'data' as well. +# META is set to 'all' (viz. a keyword and hence not a legal volume name) +# to prevent the script from running for volumes it was not intended. +# User needs to set META to the volume that serves CTDB lockfile. +META="all" + +function sighup_samba () { + pid=`cat /var/run/smbd.pid` + if [ $pid != " " ] + then + kill -HUP $pid; + else + /etc/init.d/smb start + fi +} + +function parse_args () { + ARGS=$(getopt -l $OPTSPEC -name $PROGNAME $@) + eval set -- "$ARGS" + + while true; do + case $1 in + --volname) + shift + VOL=$1 + ;; + + *) + shift + break + ;; + + esac + + shift + done +} + +function add_glusterfs_ctdb_options () { + PAT="Share Definitions" + GLUSTER_CTDB_CONFIG="# ctdb config for glusterfs\n\tclustering = yes\n\tidmap backend = tdb2\n\tprivate dir = "$CTDB_MNT"\n" + + sed -i /"$PAT"/i\ "$GLUSTER_CTDB_CONFIG" $SMB_CONF +} + +parse_args $@ +if [ "$META" = "$VOL" ] +then + add_glusterfs_ctdb_options + sighup_samba + mount -t glusterfs `hostname`:$VOL "$CTDB_MNT" & +fi + diff --git a/extras/hook-scripts/start/post/S30samba-start.sh b/extras/hook-scripts/start/post/S30samba-start.sh new file mode 100644 index 00000000000..5c7b6574e36 --- /dev/null +++ b/extras/hook-scripts/start/post/S30samba-start.sh @@ -0,0 +1,62 @@ +#!/bin/bash +#Need to be copied to hooks//start/post + +PROGNAME="Ssamba-start" +OPTSPEC="volname:,mnt:" +VOL= +#FIXME: glusterd hook interface will eventually provide mntpt prefix as +# command line arg +MNT_PRE="/mnt/samba" + +function parse_args () { + ARGS=$(getopt -l $OPTSPEC -name $PROGNAME $@) + eval set -- "$ARGS" + + while true; do + case $1 in + --volname) + shift + VOL=$1 + ;; + --mnt) + shift + MNT_PRE=$1 + ;; + *) + shift + break + ;; + esac + shift + done +} + +function add_samba_export () { + volname=$1 + mnt_pre=$2 + mkdir -p $mnt_pre/$volname && \ + printf "\n[gluster-$volname]\ncomment=For samba export of volume $volname\npath=$mnt_pre/$volname\nread only=no\nguest ok=yes\n" >> /etc/samba/smb.conf +} + +function mount_volume () { + volname=$1 + mnt_pre=$2 + #Mount shouldn't block on glusterd to fetch volfile, hence the 'bg' + mount -t glusterfs `hostname`:$volname $mnt_pre/$volname & +} + +function sighup_samba () { + pid=`cat /var/run/smbd.pid` + if [ $pid != " " ] + then + kill -HUP $pid; + else + /etc/init.d/smb start + fi +} + + +parse_args $@ +add_samba_export $VOL $MNT_PRE +mount_volume $VOL $MNT_PRE +sighup_samba diff --git a/extras/hook-scripts/start/post/S30samba-stop.sh b/extras/hook-scripts/start/post/S30samba-stop.sh new file mode 100644 index 00000000000..0886f91bf9d --- /dev/null +++ b/extras/hook-scripts/start/post/S30samba-stop.sh @@ -0,0 +1,60 @@ +#! /bin/bash +#Need to be copied to hooks//stop/post + +PROGNAME="Ssamba-stop" +OPTSPEC="volname:,mnt:" +VOL= +#FIXME: gluster will eventually pass mnt prefix as command line argument +MNT_PRE="/mnt/samba" + +function parse_args () { + ARGS=$(getopt -l $OPTSPEC -name $PROGNAME $@) + eval set -- "$ARGS" + + while true; do + case $1 in + --volname) + shift + VOL=$1 + ;; + --mnt) + shift + MNT_PRE=$1 + echo $1 + ;; + *) + shift + break + ;; + esac + shift + done +} + +function del_samba_export () { + volname=$1 + cp /etc/samba/smb.conf /tmp/smb.conf + sed -i "/gluster-$volname/,/^$/d" /tmp/smb.conf &&\ + mv /tmp/smb.conf /etc/samba/smb.conf +} + +function umount_volume () { + volname=$1 + mnt_pre=$2 + umount -l $mnt_pre/$volname +} + +function sighup_samba () { + pid=`cat /var/run/smbd.pid` + if [ $pid != " " ] + then + kill -HUP $pid; + else + /etc/init.d/smb start + fi +} + +parse_args $@ +del_samba_export $VOL +umount_volume $VOL $MNT_PRE +sighup_samba -- cgit