Advertisement
Guest User

Untitled

a guest
May 6th, 2011
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # chkconfig: 345 99 01
  4. # description: # Gluster client startup and shutdown script
  5. #
  6. # J. Burnash 2010
  7. #
  8. # $Id: gluster-client.prod 100 2011-02-02 14:57:15Z jburnash $
  9.  
  10. function load_modules {
  11. (lsmod | fgrep fuse) || modprobe fuse
  12. if [ $? -ne 0 ]
  13. then
  14. echo "Could not load fuse module successfully. Exiting"
  15. exit 2
  16. else
  17. return 0
  18. fi
  19. }
  20.  
  21. function mount_filesystem {
  22. if [ "$1" = "YES" ]
  23. then
  24. GLUSTERFS_ARGS=" -O --disable-direct-io-mode"
  25. fi
  26. mount -t glusterfs $GLUSTERFS_ARGS ${GLUSTER_RO}:/pfs-ro1 /pfs2 && mount -t glusterfs $GLUSTERFS_ARGS ${GLUSTER_RW}:/pfs-rw1 /pfs1
  27. if [ $? -ne 0 ]
  28. then
  29. echo "Could not mount Gluster filesystems. Exiting"
  30. exit 3
  31. fi
  32. }
  33.  
  34. function unload_modules {
  35. # make sure command exists and is executable
  36. if (lsmod | fgrep fuse >/dev/null)
  37. then
  38. /etc/init.d/glusterd stop >/dev/null 2>&1
  39. (umount /sys/fs/fuse/connections 2>/dev/null; modprobe -r fuse 2>/dev/null)
  40. else
  41. :
  42. fi
  43. if [ $? -ne 0 ]
  44. then
  45. echo "Could not unload all modules successfully. Exiting"
  46. exit 2
  47. else
  48. return 0
  49. fi
  50. }
  51.  
  52. function unmount_filesystem {
  53. MOUNTED_FS=$(mount | fgrep 'glusterfs' | cut -d " " -f3 2>/dev/null)
  54. if [ -z "$MOUNTED_FS" ]
  55. then
  56. :
  57. else
  58. mount | fgrep 'glusterfs' | cut -d " " -f3 | xargs umount 2>/dev/null
  59. fi
  60. if [ $? -ne 0 ]
  61. then
  62. echo "Could not unmount Gluster filesystems. Exiting"
  63. exit 3
  64. fi
  65.  
  66. }
  67.  
  68. function force_unmount_filesystem {
  69. # Unmount the /pfs subdirectories that you can do gracefully first:
  70.  
  71. #mount | fgrep 'glusterfs' | cut -d " " -f1 | xargs umount --force 2>/dev/null
  72. mount | fgrep 'glusterfs' | cut -d " " -f3 | xargs umount 2>/dev/null
  73. if [ $? -ne 0 ]
  74. then
  75.  
  76. # Now kill the processes (if any) that are holding the /pfs sub-directories open:
  77. #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"
  78. 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"
  79.  
  80. if [ $? -ne 0 ]
  81. then
  82. :
  83. else
  84. echo "Could not unmount Gluster filesystems. Exiting"
  85. exit 3
  86. fi
  87. fi
  88. }
  89.  
  90. function is_running {
  91. (mount | grep -q [p"]fs-") && (/etc/init.d/glusterd status >/dev/null 2>&1)
  92. if [ $? -eq 0 ]
  93. then
  94. RETVAL=0
  95. else
  96. RETVAL=1
  97. fi
  98. return $RETVAL
  99. }
  100.  
  101. start () {
  102. VMCHECK=$(ps ax | grep -q [v]mware && echo YES)
  103. is_running
  104. if [ $RETVAL -eq 0 ]; then
  105. echo "$prog is already running"
  106. else
  107. [ -d /pfs1 ] || mkdir -p /pfs1
  108. [ -d /pfs2 ] || mkdir -p /pfs2
  109. echo -n "Starting $prog: "
  110. /etc/init.d/glusterd start
  111. load_modules && mount_filesystem $VMCHECK
  112. fi
  113. RETVAL=$?
  114. echo
  115. [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
  116. return $RETVAL
  117. }
  118.  
  119. stop () {
  120. is_running
  121. if [ $RETVAL -eq 0 ]; then
  122. echo -n $"Stopping $prog: "
  123. if [ "$1" = force ]
  124. then
  125. force_unmount_filesystem && unload_modules
  126. else
  127. unmount_filesystem && unload_modules
  128. fi
  129. RETVAL=$?
  130. rm -f /var/lock/subsys/$prog
  131. echo $"$prog shutdown"
  132. else
  133. echo $"$prog was not running"
  134. fi
  135. echo
  136. return $RETVAL
  137. }
  138.  
  139. restart() {
  140. stop
  141. # give fuse module time to unload before reloading
  142. sleep 2
  143. start
  144. }
  145.  
  146. if [ $# -ne 1 ]
  147. then
  148. echo $"Usage: $0 {start|stop|restart}"
  149. fi
  150.  
  151. prog=$(basename $0)
  152. RETVAL=0
  153. GLUSTER_RO=jc1lpfsnfsro
  154. GLUSTER_RW=jc1lpfsnfsrw
  155. # See how we were called.
  156. case "$1" in
  157. start)
  158. start
  159. RETVAL=$?
  160. ;;
  161. stop)
  162. stop
  163. RETVAL=$?
  164. ;;
  165. force-stop)
  166. stop force
  167. RETVAL=$?
  168. ;;
  169. status)
  170. is_running
  171. if [ $RETVAL -eq 0 ]; then
  172. echo $"$prog is running"
  173. else
  174. echo $"$prog is NOT running"
  175. fi
  176. RETVAL=$?
  177. ;;
  178. restart)
  179. restart
  180. RETVAL=$?
  181. ;;
  182. #try-restart | condrestart)
  183. #[ -e /var/lock/subsys/nscd ] && restart
  184. #RETVAL=$?
  185. #;;
  186. #force-reload | reload)
  187. #echo -n $"Reloading $prog: "
  188. #killproc /usr/sbin/nscd -HUP
  189. #RETVAL=$?
  190. #echo
  191. #;;
  192. *)
  193. #echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}"
  194. echo $"Usage: $0 {start|stop|force-stop|restart}"
  195. RETVAL=1
  196. ;;
  197. esac
  198. exit $RETVAL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement