summaryrefslogtreecommitdiffstats
path: root/extras/hook-scripts/start
diff options
context:
space:
mode:
authorKrishnan Parthasarathi <kp@gluster.com>2012-05-29 01:33:31 +0530
committerVijay Bellur <vijay@gluster.com>2012-06-12 14:39:49 +0530
commit7fb03a0ade154b0c21a71ce0e776a06e50510016 (patch)
tree51f3b201036c2cad207ddd09ba732b08af8b6c24 /extras/hook-scripts/start
parent7ded1a6e11dae194f04d8717125ff5c18066731e (diff)
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 <kp@gluster.com> Signed-off-by: Vijay Bellur <vijay@gluster.com>
Diffstat (limited to 'extras/hook-scripts/start')
-rw-r--r--extras/hook-scripts/start/Makefile.am2
-rw-r--r--extras/hook-scripts/start/post/Makefile.am1
-rw-r--r--extras/hook-scripts/start/post/S29CTDBsetup.sh69
-rw-r--r--extras/hook-scripts/start/post/S30samba-start.sh62
-rw-r--r--extras/hook-scripts/start/post/S30samba-stop.sh60
5 files changed, 194 insertions, 0 deletions
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/<HOOKS_VER>/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/<HOOKS_VER>/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