blob: cab91b9acc2984b2697a4031e4132d9e3bf39249 [file] [log] [blame]
Andrew Geissler99467da2019-02-25 18:54:23 -06001#!/bin/sh
2#
3# Start the MD monitor daemon for all active MD arrays if desired.
4#
5### BEGIN INIT INFO
6# Provides: mdadm
7# Required-Start: $local_fs $syslog mdadm-raid
8# Required-Stop: $local_fs $syslog mdadm-raid
9# Default-Start: 2 3 4 5
10# Default-Stop: 0 1 6
11# Short-Description: MD monitoring daemon
12# Description: mdadm provides a monitor mode, in which it will scan for
13# problems with the MD devices. If a problem is found, the
14# administrator is alerted via email, or a custom script is
15# run.
16### END INIT INFO
17#
18
19MDADM=/sbin/mdadm
20RUNDIR=/var/run/mdadm
21PIDFILE=$RUNDIR/monitor.pid
22DEBIANCONFIG=/etc/default/mdadm
23
24test -x "$MDADM" || exit 0
25
26test -f /proc/mdstat || exit 0
27
28START_DAEMON=true
29test -f $DEBIANCONFIG && . $DEBIANCONFIG
30
31. /lib/lsb/init-functions
32
33# Include functions
34. /etc/init.d/functions
35
36case "${1:-}" in
37 start)
38 if is_true $START_DAEMON; then
39 log_daemon_msg "Starting MD monitoring service" "mdadm --monitor"
40 mkdir -p $RUNDIR
41 start-stop-daemon -S -p $PIDFILE -x $MDADM -- \
42 --monitor --pid-file $PIDFILE --daemonise --scan ${DAEMON_OPTIONS:-}
43 RETVAL=$?
44 log_end_msg $RETVAL
45 exit $RETVAL
46 fi
47 ;;
48 stop)
49 if [ -f $PIDFILE ] ; then
50 log_daemon_msg "Stopping MD monitoring service" "mdadm --monitor"
51 start-stop-daemon -K -p $PIDFILE -x $MDADM
52 RETVAL=$?
53 rm -f $PIDFILE
54 log_end_msg $RETVAL
55 exit $RETVAL
56 fi
57 ;;
58 status)
59 status -p $PIDFILE "$MDADM" && exit 0 || exit $?
60 ;;
61 restart|reload|force-reload)
62 ${0:-} stop
63 ${0:-} start
64 ;;
65 *)
66 echo "Usage: ${0:-} {start|stop|status|restart|reload|force-reload}" >&2
67 exit 1
68 ;;
69esac
70
71exit 0
72