[zfs-fuse] Migrate to systemd.

Jon Ciesla limb at fedoraproject.org
Wed Mar 14 18:45:47 UTC 2012


commit 1c50d5e79b9266a45f91d70eacec10fb745529f1
Author: Jon Ciesla <limburgher at gmail.com>
Date:   Wed Mar 14 13:45:36 2012 -0500

    Migrate to systemd.

 zfs-fuse-helper  |  216 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 zfs-fuse.service |   12 +++
 zfs-fuse.spec    |   49 ++++++++----
 3 files changed, 261 insertions(+), 16 deletions(-)
---
diff --git a/zfs-fuse-helper b/zfs-fuse-helper
new file mode 100644
index 0000000..ac086c5
--- /dev/null
+++ b/zfs-fuse-helper
@@ -0,0 +1,216 @@
+#! /bin/bash
+
+# Source function library.
+. /etc/rc.d/init.d/functions
+
+prog="zfs-fuse"
+exec="/usr/bin/$prog"
+config=/etc/sysconfig/$prog
+
+[ -e $config ] && . $config
+
+PIDFILE=/var/run/$prog.pid
+
+unset LANG
+ulimit -v unlimited
+ulimit -c 512000
+ulimit -l unlimited
+ulimit -s unlimited
+
+start() {
+    [ -x $exec ] || (echo "$prog binary not present or executable" && exit 5)
+    PID=`pidofproc $prog`
+    start_status=$?
+    case "$start_status" in
+    0)
+        echo "ZFS-FUSE is already running with pid $pid"
+        exit 3
+        ;;
+    1)
+        echo "Cleaning up stale $prog PID file in $PIDFILE"
+        rm -f "$PIDFILE"
+        ;;
+    3)
+        # not running
+        ;;
+    *)
+    	echo "Huh?"
+    	exit 99
+    esac
+
+    if [ "$ZFS_KILL_ORPHANS" == "yes_really" ] ; then
+      echo -n Killing processes with unknown working directory:
+      for a in 1 2 3 4 5 ; do
+        orphans=`lsof -w -n | awk '$4 == "cwd" && $5 == "unknown" {print $2}'`
+        echo -n $orphans
+        [ "$orphans" == "" ] && break
+        echo -n .
+        kill $orphans
+        sleep 1
+      done
+      orphans=`lsof -w -n | awk '$4 == "cwd" && $5 == "unknown" {print $2}'`
+      if [ "$orphans" != "" ] ; then
+        echo_failure ; echo
+        echo -n Some orphans still live: $orphans  Killing with signal 9
+        kill -9 $orphans
+      fi
+      orphans=`lsof -w -n | awk '$4 == "cwd" && $5 == "unknown" {print $2}'`
+      if [ "$orphans" != "" ] ; then
+        echo_failure ; echo
+        echo -n Some orphans still live: $orphans
+        echo_failure ; echo
+        exit 8
+      fi
+      echo_success ; echo
+    fi
+
+    echo -n $"Starting $prog: "
+    daemon $exec -p "$PIDFILE"
+    exec_retval=$?
+    echo
+    [ $exec_retval -ne 0 ] && return $exec_retval
+	
+    for a in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ; do
+        PID=`pidofproc $prog`
+        [ "$PID" != "" ] && break
+        echo -n "."
+        sleep 1
+    done
+
+    if [ "$PID" = "" ] ; then
+        echo "ZFS-FUSE did not start or create $PIDFILE"
+        exit 3
+    fi
+
+    echo -n "Immunizing $prog against OOM kills"
+    echo -17 > "/proc/$PID/oom_adj"
+    ES_TO_REPORT=$?
+    if [ "$ES_TO_REPORT" -ne 0 ] ; then
+		echo_warning
+        echo "code $ES_TO_REPORT"
+        exit 3
+    fi
+    echo_success
+    echo
+
+	if [ "$ZFS_AUTOMOUNT" == "1" ] ; then
+		echo "Deprecated use of ZFS_AUTOMOUNT option.  Use ZFS_AUTOMOUNT=yes instead."
+		ZFS_AUTOMOUNT=yes
+	fi
+
+	if [ "$ZFS_AUTOMOUNT" == "yes" ] ; then
+		echo -n $"Mounting zfs partitions: "
+    	sleep 1
+        rm -f /var/lib/random-seed
+		zfs mount -a
+		zfs_mount_retval=$?
+		if [ $zfs_mount_retval = 0 ]; then
+			echo_success
+		else
+			echo_warning
+			echo zfs mount failed with code $zfs_mount_retval
+		fi
+		echo
+    fi
+    
+    
+#    if [ -x /nonexistent -a -x /usr/bin/renice ] ; then # DISABLED
+#        log_action_begin_msg "Increasing ZFS-FUSE priority"
+#        /usr/bin/renice -15 -g $PID > /dev/null
+#        ES_TO_REPORT=$?
+#        if [ 0 = "$ES_TO_REPORT" ] ; then
+#            log_action_end_msg 0
+#        else
+#            log_action_end_msg 1 "code $ES_TO_REPORT"
+#            exit 3
+#        fi
+#        true
+#    fi 
+        
+    
+    return $exec_retval
+}
+
+stop() {
+    status_quiet || return 0
+    [ -x $exec ] || (echo "$prog binary not present or executable" && exit 5)
+    PID=`pidofproc $prog`
+    if [ "$PID" != "" ] ; then
+        echo -n "Syncing disks"
+        sync
+        echo_success
+        echo
+
+        echo -n "Unmounting ZFS filesystems"
+        zfs unmount -a
+        ES_TO_REPORT=$?
+        if [ 0 = "$ES_TO_REPORT" ] ; then
+            echo_success
+        else
+            echo_warning
+        fi
+        echo
+    fi
+
+    echo -n $"Stopping $prog: "
+    killproc $prog
+    kill_retval=$?
+    echo
+	
+    if [ "$PID" != "" ] ; then
+    	echo -n "Syncing disks again"
+    	sync
+    	echo_success
+    	echo
+    fi
+
+    return $kill_retval
+}
+
+restart() {
+	stop
+	start
+}
+
+pool_status() {
+    # run checks to determine if the service is running or use generic status
+    status $prog && /usr/bin/zpool status
+}
+
+pool_status_quiet() {
+    pool_status >/dev/null 2>&1
+}
+
+status_quiet() {
+    status $prog  >/dev/null 2>&1
+}
+
+case "$1" in
+    start)
+        status_quiet && exit 0
+        $1
+        ;;
+    stop)
+        $1
+        ;;
+#    restart)
+#    	restart 
+#        ;;
+#    reload)
+#	restart
+#        ;;
+#    force-reload)
+#	restart
+#        ;;
+#    status)
+#        pool_status
+#        ;;
+#    condrestart|try-restart)
+#        pool_status_quiet || exit 0
+#        restart
+#        ;;
+    *)
+#        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
+        exit 2
+esac
+exit $?
diff --git a/zfs-fuse.service b/zfs-fuse.service
new file mode 100644
index 0000000..79eaef3
--- /dev/null
+++ b/zfs-fuse.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=zfs-fuse daemon
+After=syslog.target
+
+[Service]
+Type=forking
+PrivateTmp=True
+ExecStart=/usr/bin/zfs-fuse-helper start
+ExecStop==/usr/bin/zfs-fuse-helper stop
+
+[Install]
+WantedBy=multi-user.target
diff --git a/zfs-fuse.spec b/zfs-fuse.spec
index 88e0688..6efc7d3 100644
--- a/zfs-fuse.spec
+++ b/zfs-fuse.spec
@@ -1,20 +1,21 @@
 Name:             zfs-fuse
 Version:          0.7.0
-Release:          3%{?dist}
+Release:          4%{?dist}
 Summary:          ZFS ported to Linux FUSE
 Group:            System Environment/Base
 License:          CDDL
 URL:              http://zfs-fuse.net/
 Source00:         http://zfs-fuse.net/releases/0.7.0/%{name}-%{version}.tar.bz2
-Source01:         zfs-fuse.init
+Source01:         zfs-fuse.service
 Source02:         zfs-fuse.scrub
 Source03:         zfs-fuse.sysconfig
+Source04:         zfs-fuse-helper
 Patch0:           zfs-fuse-0.7.0-umem.patch
 BuildRequires:    fuse-devel libaio-devel scons zlib-devel openssl-devel libattr-devel
 Requires:         fuse >= 2.7.4-1
-Requires(post):   chkconfig
-Requires(preun):  chkconfig initscripts
-Requires(postun): initscripts
+Requires(post): systemd-units
+Requires(preun): systemd-units
+Requires(postun): systemd-units
 # (2010 karsten at redhat.com) zfs-fuse doesn't have s390(x) implementations for atomic instructions
 ExcludeArch:      s390
 ExcludeArch:      s390x
@@ -52,9 +53,10 @@ scons debug=1 optim='%{optflags}'
 %{__rm} -rf %{buildroot}
 pushd src
 scons debug=1 install install_dir=%{buildroot}%{_bindir} man_dir=%{buildroot}%{_mandir}/man8/ cfg_dir=%{buildroot}/%{_sysconfdir}/%{name}
-%{__install} -Dp -m 0755 %{SOURCE1} %{buildroot}%{_initrddir}/%{name}
+%{__install} -Dp -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}/%{name}.service
 %{__install} -Dp -m 0755 %{SOURCE2} %{buildroot}%{_sysconfdir}/cron.weekly/98-%{name}-scrub
 %{__install} -Dp -m 0644 %{SOURCE3} %{buildroot}%{_sysconfdir}/sysconfig/%{name}
+%{__install} -Dp -m 0755 %{SOURCE4} %{buildroot}%{_bindir}/zfs-fuse-helper
 
 %clean
 %{__rm} -rf %{buildroot}
@@ -74,27 +76,38 @@ else
   fi
 fi
 
-if [ $1 = 1 ] ; then
-    /sbin/chkconfig --add %{name}
+if [ $1 -eq 1 ] ; then 
+    # Initial installation 
+    /bin/systemctl daemon-reload >/dev/null 2>&1 || :
 fi
 
 %preun
-if [ $1 = 0 ] ; then
-    echo "Stopping service since we are uninstalling last package"
-    /sbin/service %{name} stop >/dev/null 2>&1 || :
-    /sbin/chkconfig --del %{name}
+if [ $1 -eq 0 ] ; then
+    # Package removal, not upgrade
+    /bin/systemctl --no-reload disable zfs-fuse.service > /dev/null 2>&1 || :
+    /bin/systemctl stop zfs-fuse.service > /dev/null 2>&1 || :
 fi
 
 %postun
+/bin/systemctl daemon-reload >/dev/null 2>&1 || :
 if [ $1 -ge 1 ] ; then
-    echo "Restarting since we have updated the package"
-    /sbin/service %{name} condrestart >/dev/null 2>&1 || :
-else
+    # Package upgrade, not uninstall
+    /bin/systemctl try-restart zfs-fuse.service >/dev/null 2>&1 || :
     echo "Removing files since we removed the last package"
     rm -rf /var/run/zfs
     rm -rf /var/lock/zfs
 fi
 
+%triggerun -- zfs-fuse < 0.7.0-4
+# Save the current service runlevel info
+# User must manually run systemd-sysv-convert --apply zfs-fuse
+# to migrate them to systemd targets
+/usr/bin/systemd-sysv-convert --save zfs-fuse >/dev/null 2>&1 ||:
+
+# Run these because the SysV package being removed won't do them
+/sbin/chkconfig --del zfs-fuse >/dev/null 2>&1 || :
+/bin/systemctl try-restart zfs-fuse.service >/dev/null 2>&1 || :
+
 %files
 %defattr(-, root, root, -)
 %doc BUGS CHANGES contrib HACKING LICENSE README 
@@ -102,10 +115,11 @@ fi
 %{_bindir}/zdb
 %{_bindir}/zfs
 %{_bindir}/zfs-fuse
+%{_bindir}/zfs-fuse-helper
 %{_bindir}/zpool
 %{_bindir}/zstreamdump
 %{_bindir}/ztest
-%{_initrddir}/%{name}
+%{_unitdir}/%{name}.service
 %{_sysconfdir}/cron.weekly/98-%{name}-scrub
 %config(noreplace) %{_sysconfdir}/sysconfig/%{name}
 %{_sysconfdir}/%{name}/zfs_pool_alert
@@ -116,6 +130,9 @@ fi
 %{_mandir}/man8/zstreamdump.8.gz
 
 %changelog
+* Wed Mar 14 2012 Jon Ciesla <limburgher at gmail.com> - 0.7.0-4
+- Migrate to systemd.
+
 * Tue Feb 28 2012 Jon Ciesla <limburgher at gmail.com> - 0.7.0-3
 - Partially decrufted spec.
 


More information about the scm-commits mailing list