[nfs-ganesha] nfs-ganesha-2.0.0-2. Build on RHEL6 and add sample init.d script

Kaleb S. KEITHLEY kkeithle at fedoraproject.org
Thu Jan 2 16:20:37 UTC 2014


commit 6fbb59cadfc97d47f90fa77d4a6ea3c2f9d3af48
Author: Kaleb S. KEITHLEY <kkeithle at redhat.com>
Date:   Thu Jan 2 11:20:03 2014 -0500

    nfs-ganesha-2.0.0-2. Build on RHEL6 and add sample init.d script

 nfs-ganesha-2.0.0-no-strict-aliasing.patch |   12 +
 nfs-ganesha.init                           |  105 ++++++++
 nfs-ganesha.spec                           |   75 +++++-
 nfs_ganesha.sh                             |  390 ++++++++++++++++++++++++++++
 4 files changed, 571 insertions(+), 11 deletions(-)
---
diff --git a/nfs-ganesha-2.0.0-no-strict-aliasing.patch b/nfs-ganesha-2.0.0-no-strict-aliasing.patch
new file mode 100644
index 0000000..e3925f9
--- /dev/null
+++ b/nfs-ganesha-2.0.0-no-strict-aliasing.patch
@@ -0,0 +1,12 @@
+*** nfs-ganesha-2.0.0/src/CMakeLists.txt.orig	2013-12-11 12:46:24.587001058 -0500
+--- nfs-ganesha-2.0.0/src/CMakeLists.txt	2013-12-11 12:47:27.314999423 -0500
+***************
+*** 34,39 ****
+--- 34,40 ----
+  
+  # find out which platform we are building on
+  if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
++   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-strict-aliasing")
+    set(LINUX ON)
+    set(UNIX ON)
+    # Now detects the Linux's distro
diff --git a/nfs-ganesha.init b/nfs-ganesha.init
new file mode 100644
index 0000000..39b85b7
--- /dev/null
+++ b/nfs-ganesha.init
@@ -0,0 +1,105 @@
+#!/bin/sh
+#
+# glusterd   Startup script for the Ganesha NFS server
+#
+# chkconfig:   - 20 80
+# description: NFSv4 file-system server
+
+### BEGIN INIT INFO
+# Provides: nfs-ganesha
+# Required-Start: $local_fs $network
+# Required-Stop: $local_fs $network
+# Should-Start: 
+# Should-Stop: 
+# Default-Start: 
+# Default-Stop: 0 1 2 3 4 5 6
+# Short-Description: Ganesha NFS server
+# Description:       NFSv4 file-system server
+### END INIT INFO
+
+# Source function library.
+. /etc/rc.d/init.d/functions
+
+exe="/usr/sbin/nfs-ganesha.sh"
+prog="nfs-ganesha"
+
+# Fedora File System Layout dictates /run
+[ -e /run ] && RUNDIR="/run"
+pidf="${RUNDIR:-/var/run}/$prog.pid"
+
+[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+lockfile=/var/lock/subsys/$prog
+
+start() {
+    [ -x $exe ] || exit 5
+    echo -n $"Starting $prog: "
+    daemon $exe
+    retval=$?
+    echo
+    [ $retval -eq 0 ] && touch $lockfile
+    return $retval
+}
+
+stop() {
+    echo -n $"Stopping $prog: "
+    killproc $prog
+    retval=$?
+    echo
+    [ $retval -eq 0 ] && rm -f $lockfile
+    return $retval
+}
+
+restart() {
+    stop
+    start
+}
+
+reload() {
+    restart
+}
+
+force_reload() {
+    restart
+}
+
+rh_status() {
+    status $prog
+}
+
+rh_status_q() {
+    rh_status &>/dev/null
+}
+
+
+case "$1" in
+    start)
+        rh_status_q && exit 0
+        $1
+        ;;
+    stop)
+        rh_status_q || exit 0
+        $1
+        ;;
+    restart)
+        $1
+        ;;
+    reload)
+        rh_status_q || exit 7
+        $1
+        ;;
+    force-reload)
+        force_reload
+        ;;
+    status)
+        rh_status
+        ;;
+    condrestart|try-restart)
+        rh_status_q || exit 0
+        restart
+        ;;
+    *)
+        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
+        exit 2
+esac
+exit $?
diff --git a/nfs-ganesha.spec b/nfs-ganesha.spec
index 8b9e8d8..c1a29da 100644
--- a/nfs-ganesha.spec
+++ b/nfs-ganesha.spec
@@ -7,9 +7,15 @@
 
 %global _hardened_build 1
 
+%if ( 0%{?fedora} && 0%{?fedora} > 16 ) || ( 0%{?rhel} && 0%{?rhel} > 6 )
+%global           _with_systemd true
+%endif
+
+%{!?_pkgdocdir: %global _pkgdocdir %{_docdir}/%{name}-%{version}}
+
 Name:              nfs-ganesha
 Version:           %{version}
-Release:           1%{?prereltag:.%{prereltag}}%{?dist}
+Release:           2%{?prereltag:.%{prereltag}}%{?dist}
 Summary:           Ganesha NFS Server
 Group:             System Environment/Libraries
 License:           LGPLv3+
@@ -20,37 +26,53 @@ ExclusiveArch:     aarch64
 Source0:           %{name}-%{version}.tar.gz
 Source1:           %{ntirpcname}-%{ntirpcvers}.tar.gz
 Source2:           nfs-ganesha.service
+Source3:           nfs-ganesha.init
+Source4:           nfs_ganesha.sh
 Patch1:            nfs-ganesha-2.0.0rc5.patch
 Patch2:            nfs-ganesha-2.0.0-lustre-strict.patch
+Patch3:            nfs-ganesha-2.0.0-no-strict-aliasing.patch
 
 # Bundling exception through Fedora 23
 # https://fedorahosted.org/fpc/ticket/363
 Provides:          bundled(libntirpc)
 
+%if ( 0%{?_with_systemd:1} )
 BuildRequires:     systemd
+%endif
+%if ( 0%{?rhel} && 0%{?rhel} < 7 )
+BuildRequires:     cmake28
+%else
 BuildRequires:     cmake >= 2.6.3
+%endif
 BuildRequires:     bison
 BuildRequires:     flex
 BuildRequires:     pkgconfig
 BuildRequires:     doxygen
 BuildRequires:     krb5-devel
-BuildRequires:     xfsprogs-devel
 BuildRequires:     dbus-devel
 BuildRequires:     jemalloc-devel
+%if ( !( 0%{?rhel} && 0%{?rhel} < 7 ) )
+BuildRequires:     xfsprogs-devel
 BuildRequires:     libnfsidmap-devel
 BuildRequires:     libwbclient-devel
+%endif
 BuildRequires:     libcap-devel
 # BuildRequires:     glusterfs-api-devel
 
+%if ( 0%{?_with_systemd:1} )
 Requires(post):    systemd
 Requires(preun):   systemd
 Requires(postun):  systemd
+%else
+Requires(post):   /sbin/chkconfig
+Requires(preun):  /sbin/service
+Requires(preun):  /sbin/chkconfig
+Requires(postun): /sbin/service
+%endif
 Requires:          dbus
 Requires:          jemalloc
 # Requires:          glusterfs-api
 
-%global _docdir_fmt %{name}
-
 %description
 NFS-Ganesha is a user mode file server with support for both the
 NFS suite and 9P, the Plan 9 remote file access protocol. It uses
@@ -85,8 +107,14 @@ rm -rf contrib/libzfswrapper
 mv %{ntirpcname}-%{ntirpcvers}/* src/libntirpc/
 %patch1 -p1
 %patch2 -p1
+%if ( 0%{?rhel} && 0%{?rhel} < 7 )
+%patch3 -p1
+%endif
 
 %build
+%if ( 0%{?rhel} && 0%{?rhel} < 7 )
+%global cmake %cmake28
+%endif
 %cmake -DCMAKE_BUILD_TYPE=Maintainer -DBUILD_CONFIG=everything -DCMAKE_INSTALL_PREFIX=%{buildroot}/usr ./src
 # _smp_mflags elided due to random build errors (cmake related?)
 make VERBOSE=1
@@ -96,34 +124,59 @@ make install
 rm  %{buildroot}%{_bindir}/libntirpc.*
 chmod ugo+x  %{buildroot}%{_bindir}/ganestat.pl
 rm %{buildroot}%{_libdir}/ganesha/*.so
+mkdir -p %{buildroot}%{_pkgdocdir}
+cp -p src/Docs/*.pdf %{buildroot}%{_pkgdocdir}/
+%if ( 0%{?_with_systemd:1} )
 install -D -p -m 0644 %{SOURCE2} %{buildroot}%{_unitdir}/nfs-ganesha.service
-mkdir -p %{buildroot}%{_defaultdocdir}/%{name}
-cp -p src/Docs/*.pdf %{buildroot}%{_defaultdocdir}/%{name}/
+%else
+install -D -p -m 0744 %{SOURCE3} %{buildroot}%{_sysconfdir}/init.d/nfs-ganesha
+install -D -p -m 0744 %{SOURCE4} %{buildroot}%{_sbindir}/nfs_ganesha.sh
+%endif
 
 %post
 /sbin/ldconfig
+%if ( 0%{?_with_systemd:1} )
 %systemd_post nfs-ganesha.service
+%else
+/sbin/chkconfig --add nfs-ganesha
+%endif
 
 %preun
+%if ( 0%{?_with_systemd:1} )
 %systemd_preun nfs-ganesha.service
+%else
+/sbin/service nfs-ganesha stop &>/dev/null
+/sbin/chkconfig --del nfs-ganesha
+/sbin/service nfs-ganesha condrestart &>/dev/null
+%endif
 
 %postun
 /sbin/ldconfig
+%if ( 0%{?_with_systemd:1} )
 %systemd_postun_with_restart nfs-ganesha.service
+%endif
 
 %files
-%doc src/ChangeLog src/LICENSE.txt src/TODO
-%exclude %{_defaultdocdir}/%{name}/*.pdf
+%doc src/ChangeLog src/LICENSE.txt src/TODO src/Docs/*.pdf
+%exclude %{_pkgdocdir}/*.pdf
 %{_libdir}/*
 %{_bindir}/*
+%if ( 0%{?_with_systemd:1} )
 %{_unitdir}/*
+%else
+%{_sysconfdir}/init.d/*
+%{_sbindir}/*
+%endif
 
 %files docs
-%{_defaultdocdir}/%{name}/LICENSE.txt
-%{_defaultdocdir}/%{name}/*.pdf
-%dir %{_defaultdocdir}/%{name}
+%{_pkgdocdir}/LICENSE.txt
+%{_pkgdocdir}/*
+%dir %{_pkgdocdir}
 
 %changelog
+* Thu Jan 2 2014 Kaleb S. KEITHLEY <kkeithle at redhat.com> 2.0.0-2
+- Build on RHEL6. Add sample init.d script
+
 * Wed Dec 11 2013 Jim Lieb <lieb at sea-troll.net> - 2.0.0-1
 - Update to V2.0.0 release
 
diff --git a/nfs_ganesha.sh b/nfs_ganesha.sh
new file mode 100644
index 0000000..419995c
--- /dev/null
+++ b/nfs_ganesha.sh
@@ -0,0 +1,390 @@
+#!/bin/bash
+
+VOLNAME=
+CONF=
+IP=
+LOG=
+DBGLVL=
+OPT=
+FILE1=
+
+trap    cleanup   SIGHUP SIGINT SIGTERM
+
+
+        if [ $EUID -ne 0 ];  then
+                echo "You have to be root to run this script"
+                exit 1
+        fi
+
+
+function usage {
+        echo " Usage : nfs-ganesha.sh [-l <logfile>][-n <dbg_lvl>] -v <volname> -i <ganesha_host_ip> -f <config_file> -o <start|stop>
+               [-h]                    display this help
+               [-l <logfile>]          set the logfile for the daemon
+               [-n <dbg_lvl>]          set the verbosity level
+	       dbg_lvl options        NIV_NULL, NIV_MAJ, NIV_CRIT, NIV_EVENT, NIV_DEBUG, NIV_MID_DEBUG, NIV_FULL_DEBUG 
+               -v <volname>            name of the volume to be exported
+               -i <ganesha_host_ip>    IP of the ganesha host
+               -f <config_file>        set the config file to be used
+               -o <start|stop>         start or stop ganesha server
+                ===========Default Values=============
+                LogFile    : /tmp/nfs-ganesha.log
+                DebugLevel : NIV_EVENT"
+        }
+
+while getopts "hf:i:l:n:v:o: -l help" OPTION
+           do
+             case $OPTION in
+                     f) CONF=$OPTARG
+                     ;;
+                     i) IP=$OPTARG
+                     ;;
+                     l) LOG=$OPTARG
+                     ;;
+                     n) DBGLVL=$OPTARG
+                     ;;
+                     h) usage 
+			exit 1
+                     ;;
+                     v) VOLNAME=$OPTARG
+                     ;;
+                     o) OPT=$OPTARG
+                     ;;
+             esac
+     done
+
+
+function cleanup ()
+{
+	if [ -f /tmp/old-ganesha.conf ] 
+	then  cp /tmp/old-ganesha.conf $CONF 
+	exit 1
+	fi 
+}
+
+
+function check_for_stop()
+{
+	if  echo $OPT | grep -i -q  "stop" 
+	then stop_ganesha
+	fi
+}
+
+function check_usage()
+{
+
+     if [ "$VOLNAME" = "" ]
+     then
+             usage
+             exit 1
+     fi
+     if [ "$CONF" = "" ]
+     then
+             usage
+             exit 1
+     fi
+     if [ "$IP" = "" ]
+     then
+             usage
+     exit 1
+     fi
+     if [ "$OPT" = "" ]
+     then
+             usage
+     exit 1
+     fi
+}
+function check_ip {
+        if [[ ! $IP =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
+                echo "Invalid  IP , please enter the correct IP of the ganesha host."
+                usage
+                exit 1
+        fi
+}
+
+
+function check_volname
+{
+        if ! ls /var/lib/glusterd/vols | grep -q "$VOLNAME" ;  then
+                echo "Volume doesn't exist. Please enter a  valid volume name."
+                exit 1
+        fi
+}
+
+function check_conf
+
+
+{
+
+        if ! [ -f "$CONF" ]; then
+                echo "The config_file $CONF doesn't exist."
+                usage
+                exit 1
+        else
+                if ! [ -s "$CONF" ]; then
+                        echo "The cofig_file $CONF is empty "
+                        exit 1
+                fi
+        fi
+}
+
+function  check_option
+{
+        if ! echo $OPT | grep -i  -q  -e "start"  -q -e "stop"
+        then
+                        echo  "Invalid value for option 'o': start or stop expected"
+                                exit 1
+        else if echo $OPT | grep -i -q "start"
+        then
+                OPT="start"
+        else
+                OPT="stop"
+        fi
+        fi
+}
+
+
+function check_debug
+{
+        if [ "$DBGLVL" = "" ] ; then
+                DBGLVL="NIV_EVENT"
+        else
+                if ! echo $DBGLVL | grep -q -e " NIV_NULL" -q -e  "NIV_MAJOR" -q -e " NIV_CRIT" -q -e "NIV_EVENT" -q -e "NIV_DEBUG" -q -e "NIV_FULL_DEBUG"
+                then
+                        echo  "Invalid value for option 'n': NIV_NULL, NIV_MAJ, NIV_CRIT, NIV_EVENT, NIV_DEBUG, NIV_MID_DEBUG or NIV_FULL_DEBUG expected."
+                        exit 1
+                fi
+        fi
+
+}
+
+
+function check_logfile
+{
+        if [ "$LOG" = "" ]; then
+                LOG="/tmp/nfs-ganesha.log"
+        else if [ -f $LOG ]
+        then
+                cp $LOG /tmp/old-ganesha.log
+                FILE1="1"
+        fi
+        fi
+}
+
+function call_checks
+{
+        check_ip
+        check_conf
+	cp $CONF /tmp/old-ganesha.conf
+
+        check_debug
+        check_logfile
+        check_option
+        check_volname
+}
+function check_glusterd()
+{
+
+        if ! ps aux | grep -q -e "[g]lusterd$" -q -e "[g]lusterd.pid"
+        then
+                echo "glusterd not started , please start glusterd. "
+                exit 1
+        fi
+}
+
+function check_bricks()
+{
+        gluster volume status $VOLUME | grep -q  "N/A"
+        if [ "$?" -eq 0 ]
+        then
+                echo "Brick(s) not online , please check $VOLUME volume status"
+                exit 1
+        fi
+}
+
+function check_glusternfs
+{
+        if  echo "$(ls /var/lib/glusterd/vols | wc -l)" | grep -q "1" ; then
+                if   ps aux | grep -q "[g]luster/nfs" ; then
+                echo "gluster-nfs server is active, needs to be disabled to proceed. "
+                while true; do
+                        read -p "Do you wish to disable gluster-nfs server ? [Y\N]" yn
+                        case $yn in
+                                [Yy]* ) gluster volume set $VOLNAME nfs.disable ON >/dev/null 2>/dev/null; break;;
+                                [Nn]* ) exit 1;;
+                                * ) echo "Please answer yes or no.";;
+                        esac
+                done
+                sleep 2
+                        if ps aux | grep -q "[g]luster/nfs" ; then
+                                 echo "Volume set unsuccessful , please try disabling gluster-nfs server "
+                                exit 1
+                         fi
+                sleep 2
+                        if rpcinfo -p | grep -q -e  "nfs_acl" ; then
+                                 echo " gluster-nfs ports still in use; please try again"
+                        exit 1
+                        fi
+
+         fi
+ else
+         if    ps aux | grep -q  "[g]luster/nfs"; then
+                echo "Please disable gluster-nfs servers on all the volumes"
+                exit 1
+                 fi
+        fi
+}
+
+function check_kernelnfs()
+{
+        service nfs status  | grep -q -e "dead" -q -e "stopped" -q -e "disabled" 
+        if [ "$?" -eq 1 ]; then
+                echo "kernel-NFS server is active , it needs to disabled to proceed. "
+                while true; do
+                        read -p "Do you wish to disable kernel-nfs server ? [Y\N]" yn
+                                case $yn in
+                                         [Yy]* ) service nfs stop; break;;
+                                         [Nn]* ) exit 1;;
+                                          * ) echo "Please answer yes or no.";;
+                                esac
+                done
+                sleep 2
+                service nfs status | grep -q -e "dead" -q -e "stopped" -q -e "inactive" >>/dev/null
+                if [ "$?" -eq 1 ]; then
+                        echo " kernel-NFS server couldn't be disabled , please try again"
+                        exit 1
+                else
+                        echo "kernel-NFS server successfully disabled"
+                fi
+        fi
+}
+
+
+function check_volstart()
+{
+
+        if ! cat /var/lib/glusterd/vols/$1/info | grep -q "status=1" 
+        then
+                echo "Volume $1 is not started, please start the volume."
+                exit 1
+        fi
+}
+
+function check_ganesha
+{
+        if  ps aux | grep -q "[g]anesha.nfsd" ;  then
+                echo "NFS-ganesha server is already active , nothing to do."
+                exit 1
+        fi
+}
+
+
+function check_ports
+{
+        if netstat -an | grep -q "2049$" ; then
+                echo "Port 2049 is already in use , exiting"
+                exit 1
+        fi
+}
+
+function check_fsal
+{
+
+       if !  ls /usr/lib64/ganesha | grep -q "libfsalgluster.so"  ; then
+               echo "Cannot find shared object libfsalgluster.so , exiting"
+               exit 1
+       fi
+}
+
+
+
+
+function start_ganesha
+{
+	check_ganesha
+        #check_rpms
+        check_fsal
+        check_glusterd
+        check_volstart $1
+        check_kernelnfs
+        check_glusternfs  $1
+        check_ports
+        check_conf $3
+        check_bricks $1
+        sed -i /^[[:space:]]*\#/!s/volume.*/"volume=$1,hostname=$2\";"/ $3
+        sed -i /^[[:space:]]*\#/!s/Pseudo.*/Pseudo="\"\/$1\";"/ $3
+        sed -i s/Path.*/Path="\"\/$1\";"/ $3
+        sed -i 's/\r//g' $3
+        /usr/bin/ganesha.nfsd -f $CONF  -L  $LOG -N $DBGLVL -d  >/dev/null 2>/dev/null
+
+        sleep 5
+
+}
+
+
+function stop_ganesha
+{
+        if ! ps aux | grep -q "[g]anesha.nfsd" ;  then
+                echo "NFS-ganesha server already inactive,nothing to do."
+                exit 1
+        fi
+        kill -9 `cat /var/run/ganesha.pid`
+        if ps aux | ganesha.nfsd ; then
+                if  rpcinfo -p | grep -q -e "nfs" ; then
+                        echo "NFS-ganesha server could not be stopped, please try again"
+                fi
+        else
+                echo " NFS-ganesha server is now inactive."
+		exit 0
+        fi
+}
+
+
+
+function check_for_stop()
+{
+        if  echo $OPT | grep -i -q  "stop"
+        then stop_ganesha
+        fi
+}
+
+
+
+check_for_stop
+check_usage
+call_checks
+
+if [ "$OPT" = "start"  ]
+then
+        start_ganesha $VOLNAME $IP $CONF
+        if  ! ps aux | grep -q "[g]anesha.nfsd" ; then
+                start_ganesha $VOLNAME $IP $CONF
+        fi
+        sleep 5
+        if ! ps aux | grep  -q "[g]anesha.nfsd"
+        then
+                if [ "$FILE1" = "1" ]
+                then
+                cp /tmp/old-ganesha.log $LOG
+                rm -rf /tmp/ganesha.log
+                fi
+                cp /tmp/old-ganesha.conf $CONF
+		rm -rf /tmp/ganesha.conf
+                 echo "Failed to start NFS-ganesha server , please see $LOG for details"
+         else
+                echo ""
+                echo "NFS-ganesha server started."
+                 echo "============Volume exports============"
+                 showmount -e $IP
+		echo "======================================"
+		rm -rf /tmp/old-ganesha.conf
+         fi
+fi
+
+  if  [ "$OPT" = "stop" ]
+then
+                stop_ganesha
+		exit 0
+
+fi
+


More information about the scm-commits mailing list