[OE-core] [PATCH] mdadm: add systemd service files
Li xin
lixin.fnst at cn.fujitsu.com
Tue Jun 16 05:27:50 UTC 2015
Add mdmonitor.service to support systemd systems and add configuration
file.
Signed-off-by: Li Xin <lixin.fnst at cn.fujitsu.com>
---
meta/recipes-extended/mdadm/files/mdadm.conf | 1 +
meta/recipes-extended/mdadm/files/mdadm.default | 25 ++++++++
meta/recipes-extended/mdadm/files/mdadm.init | 71 ++++++++++++++++++++++
.../recipes-extended/mdadm/files/mdmonitor.service | 13 ++++
meta/recipes-extended/mdadm/mdadm_3.3.2.bb | 32 +++++++++-
5 files changed, 140 insertions(+), 2 deletions(-)
create mode 100644 meta/recipes-extended/mdadm/files/mdadm.conf
create mode 100644 meta/recipes-extended/mdadm/files/mdadm.default
create mode 100755 meta/recipes-extended/mdadm/files/mdadm.init
create mode 100644 meta/recipes-extended/mdadm/files/mdmonitor.service
diff --git a/meta/recipes-extended/mdadm/files/mdadm.conf b/meta/recipes-extended/mdadm/files/mdadm.conf
new file mode 100644
index 0000000..b869d8f
--- /dev/null
+++ b/meta/recipes-extended/mdadm/files/mdadm.conf
@@ -0,0 +1 @@
+MAILADDR root at mydomain.com
diff --git a/meta/recipes-extended/mdadm/files/mdadm.default b/meta/recipes-extended/mdadm/files/mdadm.default
new file mode 100644
index 0000000..2e74fdb
--- /dev/null
+++ b/meta/recipes-extended/mdadm/files/mdadm.default
@@ -0,0 +1,25 @@
+# mdadm configuration
+#
+# You can run 'dpkg-reconfigure mdadm' to modify the values in this file, if
+# you want. You can also change the values here and changes will be preserved.
+# Do note that only the values are preserved; the rest of the file is
+# rewritten.
+#
+
+# AUTOCHECK:
+# should mdadm run periodic redundancy checks over your arrays? See
+# /etc/cron.d/mdadm.
+AUTOCHECK=true
+
+# START_DAEMON:
+# should mdadm start the MD monitoring daemon during boot?
+START_DAEMON=true
+
+# DAEMON_OPTIONS:
+# additional options to pass to the daemon.
+DAEMON_OPTIONS="--syslog"
+
+# VERBOSE:
+# if this variable is set to true, mdadm will be a little more verbose e.g.
+# when creating the initramfs.
+VERBOSE=false
diff --git a/meta/recipes-extended/mdadm/files/mdadm.init b/meta/recipes-extended/mdadm/files/mdadm.init
new file mode 100755
index 0000000..8a9fbe3
--- /dev/null
+++ b/meta/recipes-extended/mdadm/files/mdadm.init
@@ -0,0 +1,71 @@
+#!/bin/sh
+#
+# Start the MD monitor daemon for all active MD arrays if desired.
+#
+### BEGIN INIT INFO
+# Provides: mdadm
+# Required-Start: $local_fs $syslog mdadm-raid
+# Required-Stop: $local_fs $syslog mdadm-raid
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: MD monitoring daemon
+# Description: mdadm provides a monitor mode, in which it will scan for
+# problems with the MD devices. If a problem is found, the
+# administrator is alerted via email, or a custom script is
+# run.
+### END INIT INFO
+#
+
+MDADM=/sbin/mdadm
+RUNDIR=/var/run/mdadm
+PIDFILE=$RUNDIR/monitor.pid
+DEBIANCONFIG=/etc/default/mdadm
+
+test -x "$MDADM" || exit 0
+
+test -f /proc/mdstat || exit 0
+
+START_DAEMON=true
+test -f $DEBIANCONFIG && . $DEBIANCONFIG
+
+. /lib/lsb/init-functions
+
+# Include functions
+. /etc/init.d/functions
+
+case "${1:-}" in
+ start)
+ if is_true $START_DAEMON; then
+ log_daemon_msg "Starting MD monitoring service" "mdadm --monitor"
+ mkdir -p $RUNDIR
+ start-stop-daemon -S -p $PIDFILE -x $MDADM -- \
+ --monitor --pid-file $PIDFILE --daemonise --scan ${DAEMON_OPTIONS:-}
+ RETVAL=$?
+ log_end_msg $RETVAL
+ exit $RETVAL
+ fi
+ ;;
+ stop)
+ if [ -f $PIDFILE ] ; then
+ log_daemon_msg "Stopping MD monitoring service" "mdadm --monitor"
+ start-stop-daemon -K -p $PIDFILE -x $MDADM
+ RETVAL=$?
+ rm -f $PIDFILE
+ log_end_msg $RETVAL
+ exit $RETVAL
+ fi
+ ;;
+ status)
+ status -p $PIDFILE "$MDADM" && exit 0 || exit $?
+ ;;
+ restart|reload|force-reload)
+ ${0:-} stop
+ ${0:-} start
+ ;;
+ *)
+ echo "Usage: ${0:-} {start|stop|status|restart|reload|force-reload}" >&2
+ exit 1
+ ;;
+esac
+
+exit 0
diff --git a/meta/recipes-extended/mdadm/files/mdmonitor.service b/meta/recipes-extended/mdadm/files/mdmonitor.service
new file mode 100644
index 0000000..3664ceb
--- /dev/null
+++ b/meta/recipes-extended/mdadm/files/mdmonitor.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=Software RAID monitoring and management
+After=syslog.target
+ConditionPathExists=@sysconfdir@/mdadm.conf
+
+[Service]
+Type=forking
+PIDFile=@localstatedir@/run/mdadm/mdadm.pid
+EnvironmentFile=- at sysconfdir@/sysconfig/mdmonitor
+ExecStart=@basesbindir@/mdadm --monitor --scan -f --pid-file=@localstatedir@/run/mdadm/mdadm.pid
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta/recipes-extended/mdadm/mdadm_3.3.2.bb b/meta/recipes-extended/mdadm/mdadm_3.3.2.bb
index 87e06f5..3e7e399 100644
--- a/meta/recipes-extended/mdadm/mdadm_3.3.2.bb
+++ b/meta/recipes-extended/mdadm/mdadm_3.3.2.bb
@@ -14,6 +14,10 @@ SRC_URI = "${KERNELORG_MIRROR}/linux/utils/raid/mdadm/${BPN}-${PV}.tar.xz \
file://mdadm-3.3.2_x32_abi_time_t.patch \
file://inline.patch \
file://run-ptest \
+ file://mdadm.init \
+ file://mdadm.default \
+ file://mdadm.conf \
+ file://mdmonitor.service \
"
SRC_URI[md5sum] = "44698d351501cac6a89072dc877eb220"
@@ -21,7 +25,7 @@ SRC_URI[sha256sum] = "0f3a7e1a76b13892b79f9fceaf99ecb23513260389a768ac644ffa3ae0
CFLAGS += "-fno-strict-aliasing"
-inherit autotools-brokensep
+inherit autotools-brokensep systemd
# We don't DEPEND on binutils for ansidecl.h so ensure we don't use the header
do_configure_prepend () {
@@ -46,7 +50,31 @@ do_install() {
autotools_do_install
}
-FILES_${PN} += "${base_libdir}/udev/rules.d/*.rules"
+do_install_append() {
+ install -d ${D}/${sysconfdir}/
+ install -m 644 ${WORKDIR}/mdadm.conf ${D}${sysconfdir}/
+ install -d ${D}/${systemd_unitdir}/system
+ install -m 644 ${WORKDIR}/mdmonitor.service ${D}/${systemd_unitdir}/system
+ sed -i -e 's, at basesbindir@,${base_sbindir},g' \
+ -e 's, at localstatedir@,${localstatedir},g' \
+ -e 's, at sysconfdir@,${sysconfdir},g' \
+ ${D}/${systemd_unitdir}/system/mdmonitor.service
+ install -d ${D}/${localstatedir}
+ install -d ${D}/${localstatedir}/run
+ install -d -m 700 ${D}/${localstatedir}/run/mdadm
+
+ install -d ${D}/${sysconfdir}/init.d
+ install -d ${D}/${sysconfdir}/default
+ install -m 755 ${WORKDIR}/mdadm.init ${D}${sysconfdir}/init.d/mdmonitor
+ install -m 755 ${WORKDIR}/mdadm.default ${D}${sysconfdir}/default/mdadm
+}
+SYSTEMD_SERVICE_${PN} = "mdmonitor.service"
+SYSTEMD_AUTO_ENABLE = "disable"
+
+FILES_${PN} += "${base_libdir}/udev/rules.d/*.rules \
+ /run/mdadm \
+ ${systemd_unitdir} \
+ "
inherit ptest
--
1.8.4.2
More information about the Openembedded-core
mailing list