[arch-commits] Commit in mdadm/trunk (mdadm)

Dave Reisner dreisner at archlinux.org
Sat Apr 21 19:15:38 EDT 2012


    Date: Saturday, April 21, 2012 @ 19:15:37
  Author: dreisner
Revision: 156620

refactor rc.d script

- move pidfile to /run
- use pidfile to find running PID, discard when stale
- simplify if/then/else/fi blocks in start/stop

Modified:
  mdadm/trunk/mdadm

-------+
 mdadm |   31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

Modified: mdadm
===================================================================
--- mdadm	2012-04-21 23:01:31 UTC (rev 156619)
+++ mdadm	2012-04-21 23:15:37 UTC (rev 156620)
@@ -3,28 +3,33 @@
 . /etc/rc.conf
 . /etc/rc.d/functions
 
-PID=`pidof -o %PPID /sbin/mdadm`
-case "$1" in
+pidfile=/run/mdadm.pid
+if [[ -r $pidfile ]]; then
+  read -r PID <"$pidfile"
+  if [[ $PID && ! -d /proc/$PID ]]; then
+    # stale pidfile
+    unset PID
+    rm -f "$pidfile"
+  fi
+fi
+
+case $1 in
   start)
     stat_busy "Starting mdadm RAID Monitor"
-    if [ -z "$PID" ]; then 
-       /sbin/mdadm --monitor --scan -i /var/run/mdadm.pid -f
-    fi
-    if [ ! -z "$PID" -o $? -gt 0 ]; then
-      stat_fail
-    else
+    if [[ -z $PID ]] && mdadm --monitor --scan -i "$pidfile" -f; then
       add_daemon mdadm
       stat_done
+    else
+      stat_fail
     fi
     ;;
   stop)
     stat_busy "Stopping mdadm RAID Monitor"
-    [ ! -z "$PID" ] && kill $PID &>/dev/null
-    if [ $? -gt 0 ]; then
-      stat_fail
-    else
+    if [[ $PID ]] && kill "$PID" &>/dev/null; then
       rm_daemon mdadm
       stat_done
+    else
+      stat_fail
     fi
     ;;
   restart)
@@ -33,5 +38,5 @@
     $0 start
     ;;
   *)
-    echo "usage: $0 {start|stop|restart}"  
+    echo "usage: $0 {start|stop|restart}"
 esac



More information about the arch-commits mailing list