Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # chkconfig: 345 99 01
- # description: # Gluster client startup and shutdown script
- #
- # J. Burnash 2010
- #
- # $Id: gluster-client.prod 100 2011-02-02 14:57:15Z jburnash $
- function load_modules {
- (lsmod | fgrep fuse) || modprobe fuse
- if [ $? -ne 0 ]
- then
- echo "Could not load fuse module successfully. Exiting"
- exit 2
- else
- return 0
- fi
- }
- function mount_filesystem {
- if [ "$1" = "YES" ]
- then
- GLUSTERFS_ARGS=" -O --disable-direct-io-mode"
- fi
- mount -t glusterfs $GLUSTERFS_ARGS ${GLUSTER_RO}:/pfs-ro1 /pfs2 && mount -t glusterfs $GLUSTERFS_ARGS ${GLUSTER_RW}:/pfs-rw1 /pfs1
- if [ $? -ne 0 ]
- then
- echo "Could not mount Gluster filesystems. Exiting"
- exit 3
- fi
- }
- function unload_modules {
- # make sure command exists and is executable
- if (lsmod | fgrep fuse >/dev/null)
- then
- /etc/init.d/glusterd stop >/dev/null 2>&1
- (umount /sys/fs/fuse/connections 2>/dev/null; modprobe -r fuse 2>/dev/null)
- else
- :
- fi
- if [ $? -ne 0 ]
- then
- echo "Could not unload all modules successfully. Exiting"
- exit 2
- else
- return 0
- fi
- }
- function unmount_filesystem {
- MOUNTED_FS=$(mount | fgrep 'glusterfs' | cut -d " " -f3 2>/dev/null)
- if [ -z "$MOUNTED_FS" ]
- then
- :
- else
- mount | fgrep 'glusterfs' | cut -d " " -f3 | xargs umount 2>/dev/null
- fi
- if [ $? -ne 0 ]
- then
- echo "Could not unmount Gluster filesystems. Exiting"
- exit 3
- fi
- }
- function force_unmount_filesystem {
- # Unmount the /pfs subdirectories that you can do gracefully first:
- #mount | fgrep 'glusterfs' | cut -d " " -f1 | xargs umount --force 2>/dev/null
- mount | fgrep 'glusterfs' | cut -d " " -f3 | xargs umount 2>/dev/null
- if [ $? -ne 0 ]
- then
- # Now kill the processes (if any) that are holding the /pfs sub-directories open:
- #BUSY_GLUSTER_MOUNTS=$(mount | fgrep 'glusterfs' | awk '{print $NF}') 2>/dev/null && kill -9 $(lsof -t ${BUSY_GLUSTER_MOUNTS:-none} 2>/dev/null) 2>/dev/null; sleep 1; echo $BUSY_GLUSTER_MOUNTS | xargs umount 2>/dev/null; df -l | egrep "glusterfs"
- BUSY_GLUSTER_MOUNTS=$(mount | fgrep 'glusterfs' | cut -d " " -f3) 2>/dev/null && kill -9 $(lsof -t ${BUSY_GLUSTER_MOUNTS:-none} 2>/dev/null) 2>/dev/null; sleep 1; echo $BUSY_GLUSTER_MOUNTS | xargs umount 2>/dev/null; mount | egrep "glusterfs"
- if [ $? -ne 0 ]
- then
- :
- else
- echo "Could not unmount Gluster filesystems. Exiting"
- exit 3
- fi
- fi
- }
- function is_running {
- (mount | grep -q [p"]fs-") && (/etc/init.d/glusterd status >/dev/null 2>&1)
- if [ $? -eq 0 ]
- then
- RETVAL=0
- else
- RETVAL=1
- fi
- return $RETVAL
- }
- start () {
- VMCHECK=$(ps ax | grep -q [v]mware && echo YES)
- is_running
- if [ $RETVAL -eq 0 ]; then
- echo "$prog is already running"
- else
- [ -d /pfs1 ] || mkdir -p /pfs1
- [ -d /pfs2 ] || mkdir -p /pfs2
- echo -n "Starting $prog: "
- /etc/init.d/glusterd start
- load_modules && mount_filesystem $VMCHECK
- fi
- RETVAL=$?
- echo
- [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
- return $RETVAL
- }
- stop () {
- is_running
- if [ $RETVAL -eq 0 ]; then
- echo -n $"Stopping $prog: "
- if [ "$1" = force ]
- then
- force_unmount_filesystem && unload_modules
- else
- unmount_filesystem && unload_modules
- fi
- RETVAL=$?
- rm -f /var/lock/subsys/$prog
- echo $"$prog shutdown"
- else
- echo $"$prog was not running"
- fi
- echo
- return $RETVAL
- }
- restart() {
- stop
- # give fuse module time to unload before reloading
- sleep 2
- start
- }
- if [ $# -ne 1 ]
- then
- echo $"Usage: $0 {start|stop|restart}"
- fi
- prog=$(basename $0)
- RETVAL=0
- GLUSTER_RO=jc1lpfsnfsro
- GLUSTER_RW=jc1lpfsnfsrw
- # See how we were called.
- case "$1" in
- start)
- start
- RETVAL=$?
- ;;
- stop)
- stop
- RETVAL=$?
- ;;
- force-stop)
- stop force
- RETVAL=$?
- ;;
- status)
- is_running
- if [ $RETVAL -eq 0 ]; then
- echo $"$prog is running"
- else
- echo $"$prog is NOT running"
- fi
- RETVAL=$?
- ;;
- restart)
- restart
- RETVAL=$?
- ;;
- #try-restart | condrestart)
- #[ -e /var/lock/subsys/nscd ] && restart
- #RETVAL=$?
- #;;
- #force-reload | reload)
- #echo -n $"Reloading $prog: "
- #killproc /usr/sbin/nscd -HUP
- #RETVAL=$?
- #echo
- #;;
- *)
- #echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}"
- echo $"Usage: $0 {start|stop|force-stop|restart}"
- RETVAL=1
- ;;
- esac
- exit $RETVAL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement