initial code repo
[stor4nfv.git] / src / ceph / src / upstart / rbdmap.conf
diff --git a/src/ceph/src/upstart/rbdmap.conf b/src/ceph/src/upstart/rbdmap.conf
new file mode 100644 (file)
index 0000000..eeefec3
--- /dev/null
@@ -0,0 +1,48 @@
+# rbdmap - Ceph RBD Mapping
+#
+# This script does not manage mount and unmount fs which depends on rbd device.
+# You should use _netdev option in fstab to mount and umount in the correct order.
+
+description "ceph rbd mapping"
+
+start on (started networking
+    and remote-filesystems)
+stop on unmounted-remote-filesystems
+
+env RBDMAPFILE="/etc/ceph/rbdmap"
+
+pre-start script
+    if [ ! -f "$RBDMAPFILE" ]; then
+        exit 0
+    fi
+
+    while read DEV PARAMS; do
+        case "$DEV" in
+          ""|\#*)
+            continue
+            ;;
+          */*)
+            ;;
+          *)
+            DEV=rbd/$DEV
+            ;;
+        esac
+        for PARAM in $(echo $PARAMS | tr ',' '\n'); do
+            CMDPARAMS="$CMDPARAMS --$(echo $PARAM | tr '=' ' ')"
+        done
+        if [ ! -b /dev/rbd/$DEV ]; then
+            echo "rbd map $DEV"
+            rbd map $DEV $CMDPARAMS
+        fi
+    done < $RBDMAPFILE
+end script
+
+post-stop script
+    if ls /dev/rbd[0-9]* >/dev/null 2>&1; then
+        for DEV in /dev/rbd[0-9]*; do
+            echo "rbd unmap $DEV"
+            rbd unmap $DEV
+        done
+    fi
+end script
+