svn commit: r225989 - in projects/geom-events: etc etc/devd
sbin/geom/core usr.sbin usr.sbin/geom-events
Lev A. Serebryakov
lev at FreeBSD.org
Tue Oct 4 16:54:22 UTC 2011
Author: lev (ports committer)
Date: Tue Oct 4 16:54:21 2011
New Revision: 225989
URL: http://svn.freebsd.org/changeset/base/225989
Log:
Add geom-events(8) script ad all needeed configuration files and
references.
More details are in geom-events(8).
Added:
projects/geom-events/etc/devd/geom.conf
projects/geom-events/etc/geom-events.conf
projects/geom-events/usr.sbin/geom-events/
projects/geom-events/usr.sbin/geom-events/Makefile
projects/geom-events/usr.sbin/geom-events/geom-events.8
projects/geom-events/usr.sbin/geom-events/geom-events.conf.5
projects/geom-events/usr.sbin/geom-events/geom-events.sh
Modified:
projects/geom-events/etc/Makefile
projects/geom-events/etc/devd/Makefile
projects/geom-events/sbin/geom/core/geom.8
projects/geom-events/usr.sbin/Makefile
Modified: projects/geom-events/etc/Makefile
==============================================================================
--- projects/geom-events/etc/Makefile Tue Oct 4 16:53:11 2011 (r225988)
+++ projects/geom-events/etc/Makefile Tue Oct 4 16:54:21 2011 (r225989)
@@ -10,7 +10,7 @@ SUBDIR= sendmail
BIN1= auth.conf \
crontab devd.conf devfs.conf \
ddb.conf dhclient.conf disktab fbtab \
- ftpusers gettytab group \
+ ftpusers geom-events.conf gettytab group \
hosts hosts.allow hosts.equiv \
inetd.conf libalias.conf login.access login.conf mac.conf motd \
netconfig network.subr networks newsyslog.conf nsswitch.conf \
Modified: projects/geom-events/etc/devd/Makefile
==============================================================================
--- projects/geom-events/etc/devd/Makefile Tue Oct 4 16:53:11 2011 (r225988)
+++ projects/geom-events/etc/devd/Makefile Tue Oct 4 16:54:21 2011 (r225989)
@@ -1,6 +1,6 @@
# $FreeBSD$
-FILES= asus.conf uath.conf usb.conf
+FILES= asus.conf geom.conf uath.conf usb.conf
NO_OBJ=
FILESDIR= /etc/devd
Added: projects/geom-events/etc/devd/geom.conf
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/geom-events/etc/devd/geom.conf Tue Oct 4 16:54:21 2011 (r225989)
@@ -0,0 +1,32 @@
+# $FreeBSD$
+#
+# GEOM Events processing
+
+notify 100 {
+ match "system" "GEOM";
+ match "type" "DISCONNECT";
+ action "/usr/sbin/geom-events $type $subsystem $geom $provider $disk $state";
+};
+
+notify 100 {
+ match "system" "GEOM";
+ match "type" "SYNCSTART";
+ action "/usr/sbin/geom-events $type $subsystem $geom $provider";
+};
+
+notify 100 {
+ match "system" "GEOM";
+ match "type" "SYNCSTOP";
+ action "/usr/sbin/geom-events $type $subsystem $geom $provider $complete";
+};
+
+notify 100 {
+ match "system" "GEOM";
+ match "type" "DESTROYED";
+ action "/usr/sbin/geom-events $type $subsystem $geom $provider";
+};
+
+notify 0 {
+ match "system" "GEOM";
+ action "/usr/sbin/geom-events $type $subsystem $geom $provider";
+};
Added: projects/geom-events/etc/geom-events.conf
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/geom-events/etc/geom-events.conf Tue Oct 4 16:54:21 2011 (r225989)
@@ -0,0 +1,52 @@
+# $FreeBSD$
+#
+# Settings for GEOM events processing
+#
+# This file contains "system-wide" settings. Variables in this file could be
+# overwritten with class- and device-specific configs.
+#
+# Class-specific configs are read from
+# /etc/geom-events/${class}.conf
+# /usr/local/etc/geom-events/${class}.conf
+#
+# Device-specific configs are read from
+# /etc/geom-events/${class}/${device}.conf
+# /usr/local/etc/geom-events/${class}/${device}.conf
+#
+# Spare disks are selected by peculiarity of config variables,
+# not by config file, in which variables were set.
+#
+# Please, consult to geom-events(8) for details.
+#
+
+geom_events_notify=root # E-mail or user to sent reports about GEOM events to
+geom_events_log="YES" # Log all events with logger(1)
+
+###########################################
+# Special commands for non-standard classes
+###########################################
+geom_insert_cmd_multipath='/sbin/g${class} add ${geom} ${spare}'
+
+geom_remove_cmd_mirror='/sbin/g${class} forget ${geom}'
+
+######################################
+# Example of spare disks configuration
+######################################
+
+# Default spares. They will be used, if no more specific settings could be
+# found
+#geom_spares="ada2 ada3 ada4"
+
+# Spares for class "mirror". they will be used only for geom_mirror(8),
+# if no more specific setting weill be found
+#geom_spares_mirror="da0 da1"
+
+# Spares for class "raid3", device name "data".
+#geom_spares_raid3_data="da2 da3"
+
+# Spares to replace very specific component in mirror with name "homes"
+# This is most-specific form.
+#geom_spares_mirror_homes_ada4="ada5 ada6"
+
+# Disable spares for all geom_raid(8) instances
+#geom_spares_raid=""
Modified: projects/geom-events/sbin/geom/core/geom.8
==============================================================================
--- projects/geom-events/sbin/geom/core/geom.8 Tue Oct 4 16:53:11 2011 (r225988)
+++ projects/geom-events/sbin/geom/core/geom.8 Tue Oct 4 16:54:21 2011 (r225989)
@@ -182,6 +182,7 @@ geom md unload
.Sh SEE ALSO
.Xr libgeom 3 ,
.Xr geom 4 ,
+.Xr geom-events 8 ,
.Xr gcache 8 ,
.Xr gconcat 8 ,
.Xr geli 8 ,
Modified: projects/geom-events/usr.sbin/Makefile
==============================================================================
--- projects/geom-events/usr.sbin/Makefile Tue Oct 4 16:53:11 2011 (r225988)
+++ projects/geom-events/usr.sbin/Makefile Tue Oct 4 16:54:21 2011 (r225989)
@@ -26,6 +26,7 @@ SUBDIR= adduser \
extattrctl \
fifolog \
fwcontrol \
+ geom-events \
getfmac \
getpmac \
ggetmode \
Added: projects/geom-events/usr.sbin/geom-events/Makefile
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/geom-events/usr.sbin/geom-events/Makefile Tue Oct 4 16:54:21 2011 (r225989)
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+SCRIPTS=geom-events.sh
+MAN= geom-events.conf.5 geom-events.8
+
+.include <bsd.prog.mk>
Added: projects/geom-events/usr.sbin/geom-events/geom-events.8
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/geom-events/usr.sbin/geom-events/geom-events.8 Tue Oct 4 16:54:21 2011 (r225989)
@@ -0,0 +1,398 @@
+.\"
+.\" Copyright (c) 2011 Lev Serebryakov <lev at FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd September 12, 2011
+.Dt GEOM-EVENTS 8
+.Os
+.Sh NAME
+.Nm geom-events
+.Nd command for processing
+.Xr geom 4
+events passed to
+.Xr devd 8 .
+.Sh SYNOPSIS
+.Nm
+.Ar event-name
+.Ar geom-class-name
+.Ar geom-name
+.Ar provider-name
+.Op Ar ...
+.Sh DESCRIPTION
+The
+.Nm
+utility is a shell script which processes different events from
+.Xr geom 4
+system via
+.Xr devd 8
+mechanism.
+Its main functions are to notify the administrator about these events
+by e-mail, to log such events with
+.Xr logger 1
+and to replace failed components with spare drives for
+.Xr geom 4
+classes which supports redundancy.
+.Pp
+Every event has these mandatory attributes, passed as arguments
+to
+.Nm :
+.Bl -tag -width "PROVIDER" -offset indent
+.It Ar TYPE
+Type of the event. See section
+.Sx EVENT_TYPES .
+.It Ar CLASS
+Class of geom that sends the given event. Class name should be in lower case,
+as used in first argument to userland
+.Xr geom 8
+utility.
+.It Ar GEOM
+Name of geom that sends the given event. It is usable as an argument for
+various userland utilities like
+.Xr gmirror 8 ,
+.Xr graid3 8
+and more general
+.Xr geom 8 .
+.It Ar PROVIDER
+Name of provider to which the given event is related. Most of geom classes have
+only one provider and this attribute is redundant, as it the same as
+.Ar GEOM ,
+maybe prefixed with
+.Ar CLASS/ ,
+but some classes could have more than one providers. Examples of such classes
+are
+.Xr gpart 8
+and
+.Xr graid 8 .
+.El
+.Sh EVENT TYPES
+.Ss DISCONNECT
+This event is sent when geom loses one of its components. The component is
+a provider of some other geom.
+.Pp
+This event is
+sent only by geoms which use many components. For
+example,
+.Xr gmirror 8
+sends this message, and
+.Xr geli 8
+doens't.
+.Pp
+Additional attributes passed with this event are
+.Va component
+and
+.Va state .
+.Pp
+The first one is the name of the disconnected component (provider of
+underlying geom). It is a name as it is seen in
+.Pa /dev
+tree, without
+.Pa /dev
+prefix itself, like
+.Pa ada0
+or
+.Pa mirror/gm0
+.Pp
+.Va state
+is state of geom after disconnection. It could be one of four values:
+.Bl -tag -width "FIXABLE" -offset indent
+.It Fixable
+This state means that geom is accessible (could be read and written) and
+the disconnected component could be replaced with a spare drive. In this case,
+.Nm
+tries to find a configured spare drive and use it to fix geom.
+.Pp
+This state is typical for geoms which implement volumes
+with redundancy, as
+.Xr gmirror 8
+and
+.Xr graid3 8
+.It Alive
+This state means that geom is accessible, but maybe not fully-functional, or
+no automatic replacement is possible, and operator needs to perform some manual
+operations to be sure that the disconnection is repaired.
+.Pp
+This state is typical for geoms which implement volumes
+without redundancy, like
+.Xr gstripe 8 .
+.It Dead
+This state means that geom's provider is completely destroyed by the
+disconnection and will be removed from system.
+.El
+.Pp
+.Nm
+tries to replace disconnected component in fixable cases. List of
+spare components should be configured in config files (see
+.Sx CONFIGURATION ) .
+.Pp
+.Nm
+checks every configured spare drive with
+.Xr ggetmode 8
+utility to ensure that the drive isn't used.
+.Pp
+It then
+tries to remove the failed component from geom, if configured to do so by
+.Va geom_remove_verb_ Ns Ao Ar class Ac
+variable.
+By default, no removal command is called.
+.Pp
+After that,
+.Nm
+calls shell command to insert the new
+component into array. Default command is
+.Bd -literal -offset indent
+/sbin/g${class} insert ${geom} ${spare}
+.Ed
+.Pp
+and after parameter substitution looks like this:
+.Bd -literal -offset indent
+/sbin/gmirror insert data ada12
+.Ed
+.Pp
+This command could be configured, see
+variable
+.Va geom_remove_verb_ Ns Ao Ar class Ac
+in
+.Sx CONFIGURATION
+section.
+.Pp
+.Nm
+repeats trying till success or end of available spare drives.
+.Pp
+If
+.Va geom_events_notify
+variable is set,
+.Nm
+sents e-mail to the specified address with report about
+a component disconnection and all oprations with spare drives,
+including configured list, availiable drives and the result
+of the insert command.
+.Pp
+Message for
+.Xr syslogd 8
+includes class and name of device,
+disconnected component, status of device (whether disconnect was fatal or not)
+and the result of the component replacement, if one succeeded.
+.Pp
+Manual component removals should not trigger this event.
+.Ss SYNCSTART
+This event is sent when geom starts rebuilding parity or synchronization
+of the volume. No additional parameters are passed.
+.Pp
+.Nm
+sents mail and/or logs this event with
+.Xr syslogd 8
+if configured to do so.
+.Pp
+Manual request for rebuilding or synchronization will trigger this
+event, as here is no way to distinguish the reason for rebuilding
+in most cases.
+.Ss SYNCSTOP
+This event is sent when geom stops rebuilding parity or synchronization
+of the volume. One additional parameter is passed which indicates
+whether synchronization was finished successfully or not.
+.Pp
+.Nm
+sents mail and/or logs this event with
+.Xr syslogd 8
+if configured to do so. The message includes the name of the device and
+the reason for stopping.
+.Pp
+Manual request for abort of rebuilding will trigger this
+event, as here is no way to distinguish reason of stopping in
+most cases.
+.Ss DESTROYED
+This event is sent when geom destroys its provider due to errors.
+.Pp
+.Nm
+sents mail and/or logs this event with
+.Xr syslogd 8
+if configured to do so. Message includes only name of device.
+.Pp
+Manual request for geom removal will not trigger this
+event.
+.Ss UNKNOWN EVENTS
+All unknown events are reported by e-mail and logged to system log with
+.Xr logger 1
+if configured to do so. Reported information includes class and name of device
+and name of event.
+.Sh CONFIGURATION
+The
+.Nm
+utility reads its configuration information from several files.
+The main configuration file which is always read, if it is present, is
+.Pa /etc/geom-events.conf .
+After that,
+.Nm
+determines which class and device has sent event and reads these files
+in this particular order:
+.Bl -enum -offset indent -compact
+.It
+.Pa /etc/geom-events/ Ns Ao Ar class Ac Ns Pa .conf
+.It
+.Pa /usr/local/etc/geom-events/ Ns Ao Ar class Ac Ns Pa .conf
+.It
+.Pa /etc/geom-events/ Ns Ao Ar class Ac Ns Pa / Ns Ao Ar geom Ac Ns Pa .conf
+.It
+.Pa /usr/local/etc/geom-events/ Ns Ao Ar class Ac Ns Pa / Ns Ao Ar geom Ac Ns Pa .conf
+.El
+These files are read as any
+.Pa rc.conf - like
+configuration files by sourcing them into script.
+.Pp
+.Nm
+uses these variabels from this config files:
+.Bl -tag -width indent-two
+.It Va geom_events_notify
+.Pq Vt str
+Set to e-mail for sending notifications about events to. If it is left empty
+or unset, no e-mail notifications will be sent.
+.It Va geom_events_log
+.Pq Vt bool
+If set to
+.Dq Li YES ,
+enables logging events with
+.Xr logger 1
+.It Va geom_insert_cmd_ Ns Ao Ar class Ac
+.Pq Vt str
+Set to
+.Xr sh 1
+command is used instead of the default one when
+.Nm
+tries to replace the disconnected component. If no
+variable is set for given class, default
+.Ql /sbin/g${class} insert ${geom} ${spare}
+is used.
+.Pp
+This command could contain references to special
+shell variables
+.Va ${class} , ${geom} , ${provider}
+and
+.Va ${spare}
+which will be substituted at execution time. Please note that
+configuration file is a shell script by itsef, so you need
+to quote commandcontaining variables with single quotes or escape
+varaible references with backslashes.
+.It Va geom_remove_cmd_ Ns Ao Ar class Ac
+.Pq Vt str
+Set to
+.Xr sh 1
+command which should be used by
+.Nm
+to completely remove the failed component from geom
+before replacing it with a spare. By default, no such command
+is configured and no removal is performed.
+.Pp
+This command could contain references to special
+shell variables
+.Va ${class} , ${geom} , ${provider}
+and
+.Va ${failed}
+which will be substituted at execution time. Same precautions should
+be used as with
+.Va geom_remove_cmd_ Ns Ao Ar class Ac .
+.It Va geom_spares
+.Pq Vt str
+Set to list of spare drives (or other geom providers) to use. This is the most
+non-specific list.
+.Nm
+will use more sepcific spare lists if they are configured.
+.It Va geom_spares_ Ns Ao Ar class Ac
+.Pq Vt str
+Set to list of spare drivers (or other geom providers) to use when
+.Nm
+needs to replace the disconnected component in geom with class
+.Aq Ar class .
+.Pp
+Could be overwritten for specific geom instance.
+.It Va geom_spares_ Ns Ao Ar class Ac Ns Va _ Ns Ao Ar geom Ac
+.Pq Vt str
+Set to list of spare drivers (or other geom providers) to use when
+.Nm
+needs to replace the disconnected component in geom with class
+.Aq Ar class
+and name
+.Aq Ar geom .
+.It Va geom_spares_ Ns Ao Ar class Ac Ns Va _ Ns Ao Ar geom Ac _ Ns Ao Ar component Ac
+.Pq Vt str
+Set to list of the spare drivers (or other geom providers) to use when
+.Nm
+needs to replace disconnected component with name
+.Aq Ar component
+in geom with class
+.Aq Ar class
+and name
+.Aq Ar geom .
+.El
+.Pp
+.Nm
+selects the most specific variable for spare devices. The variable is
+selected if it is set. An empty variable counts as a set one.
+.Pp
+If your have such configuration:
+.Bd -literal -offset indent
+geom_spares_raid3="ada2 ada3"
+geom_spares_raid3_test=""
+.Ed
+.Pp
+.Nm
+will select
+.Qq ada2 ada3
+as spare list for any
+.Em raid3
+geom except one, named
+.Em test .
+And
+.Em raid3
+geom
+.Em test
+will have no spare drives configured.
+.Pp
+Please note that
+.Nm
+doesn't distinguish source file of configuration variables. So, more specific
+variables could be placed in less specific config files and will be choosen by
+.Nm Ns .
+.Pp
+When variable name is constructed from geom or component name, all characters
+which could not be used in a variable names, are replaced with underscores.
+.Sh FILES
+.Pa /etc/geom-events/ Ns Ao Ar class Ac Ns Pa .conf
+.Pa /usr/local/etc/geom-events/ Ns Ao Ar class Ac Ns Pa .conf
+.Pa /etc/geom-events/ Ns Ao Ar class Ac Ns Pa / Ns Ao Ar geom Ac Ns Pa .conf
+.Pa /usr/local/etc/geom-events/ Ns Ao Ar class Ac Ns Pa / Ns Ao Ar geom Ac Ns Pa .conf
+.Sh SEE ALSO
+.Xr geom-events 8 ,
+.Xr devd 8 ,
+.Xr geom 8 ,
+.Xr geom 4
+.Sh HISTORY
+The
+.Nm
+utility and manual page first appeared in
+.Fx 10.0 .
+.Sh AUTHORS
+This utility and manual page was written by
+.An Lev Serebryakov Aq lev at FreeBSD.org .
Added: projects/geom-events/usr.sbin/geom-events/geom-events.conf.5
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/geom-events/usr.sbin/geom-events/geom-events.conf.5 Tue Oct 4 16:54:21 2011 (r225989)
@@ -0,0 +1,70 @@
+.\"
+.\" Copyright (c) 2011 Lev Serebryakov <lev at FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd September 12, 2011
+.Dt GEOM-EVENTS.CONF 5
+.Os
+.Sh NAME
+.Nm geom-events.conf
+.Nd
+.Xr geom-events 8
+configuration file
+.Sh DESCRIPTION
+The
+.Bl -item -compact
+.It
+.Pa /etc/geom-events.conf
+.It
+.Pa /etc/geom-events/ Ns Ao Ar class Ac Ns Pa .conf
+.It
+.Pa /usr/local/etc/geom-events/ Ns Ao Ar class Ac Ns Pa .conf
+.It
+.Pa /etc/geom-events/ Ns Ao Ar class Ac Ns Pa / Ns Ao Ar device Ac Ns Pa .conf
+.It
+.Pa /usr/local/etc/geom-events/ Ns Ao Ar class Ac Ns Pa / Ns Ao Ar device Ac Ns Pa .conf
+.El
+.Pp
+configuration files contains configuration for
+.Xr geom-events 8
+script. Exact description of how they are processed,
+please see in
+.Sx CONFIGURATION
+section of
+.Xr geom-events 8
+.Sh SEE ALSO
+.Xr geom-events 8 ,
+.Xr devd 8 ,
+.Xr geom 8 ,
+.Xr geom 4
+.Sh HISTORY
+The
+.Nm
+manual page first appeared in
+.Fx 10.0 .
+.Sh AUTHORS
+This manual page was written by
+.An Lev Serebryakov Aq lev at FreeBSD.org .
Added: projects/geom-events/usr.sbin/geom-events/geom-events.sh
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/geom-events/usr.sbin/geom-events/geom-events.sh Tue Oct 4 16:54:21 2011 (r225989)
@@ -0,0 +1,298 @@
+#!/bin/sh
+#
+# Copyright (c) 2011 Lev Serebryakov <lev at FreeBSD.org>. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+
+# usage: geom-events <event name> <geom class> <geom name> [...] - process
+# event.
+#
+
+usage () {
+ echo "usage: $0 <event name> <geom class> <geom name> $1" 1>&2
+ exit 1
+}
+
+event_DISCONNECT () {
+ local component state removecmd insertcmd repls repla replr replu replb remfm replfm msg _err _i _gm
+ if [ $# -ne 2 ] ; then
+ usage "<component name> <new state>"
+ fi
+ component=$1
+ state=$2
+ if [ "${state}" = 'F' ] ; then
+ # Get removal/forget command for class, no default
+ removecmd=`get_var geom_remove_cmd ${CLASS}`
+
+ # Get insert command for class, with resonable default
+ insertcmd=`get_var geom_insert_cmd ${CLASS}`
+ [ -z "${insertcmd}" ] && insertcmd='/sbin/g${class} insert ${geom} ${spare}'
+
+ # Search for ready-to-use spare providers
+ repla=`get_var geom_spares ${CLASS} ${GEOM} ${component}`
+ for _i in ${repla} ; do
+ _gm=`/usr/sbin/ggetmode ${_i} 2> /dev/null`
+ if [ $? -ne 0 ] ; then
+ replu="${replu} ${_i}"
+ elif [ "${_gm}" != "r0w0e0" ] ; then
+ replb="${replb} ${_i}"
+ else
+ replr="${replr} ${_i}"
+ fi
+ done
+
+ # Remove old component, if needed
+ if [ -n "${removecmd}" ] ; then
+ _err=`/usr/bin/env -i class=${CLASS} geom=${GEOM} provider=${PROVIDER} failed=${component} \
+ /bin/sh -c "${removecmd}"`
+ [ $? -ne 0 ] && remfm="${_err}"
+ fi
+ # Try insert command for any availiable pare till success
+ for _i in ${replr} ; do
+ _err=`/usr/bin/env -i class=${CLASS} geom=${GEOM} provider=${PROVIDER} spare=${_i} \
+ /bin/sh -c "${insertcmd}"`
+ if [ $? -eq 0 ] ; then
+ repls=${_i}
+ break
+ fi
+ replfm="${replfm}|${_i} - ${_err}"
+ done
+ fi
+ # Write line to log, if configured
+ if check_yesno geom_events_log ; then
+ msg="${CLASS} ${GEOM}:${PROVIDER} lost component ${component}"
+ case "${state}" in
+ 'D')
+ msg="${msg} (fatal)"
+ ;;
+ 'A')
+ msg="${msg} (not fatal)"
+ ;;
+ 'F')
+ msg="${msg} (fixable)"
+ ;;
+ '?')
+ msg="${msg} (unknown)"
+ ;;
+ *)
+ msg="${msg} (invalid status: ${fatal})"
+ ;;
+ esac
+ [ -n "${repls}" ] && msg="${msg}, replaced with ${repls}"
+ /usr/bin/logger -t GEOM "${msg}"
+
+ fi
+ # Send mail to user, if configured
+ if [ -n "${geom_events_notify}" ] ; then
+ (
+ echo "${CLASS} device ${GEOM}:${PROVIDER} lost component ${component}"
+ case "${state}" in
+ 'D')
+ echo "It is fatal for ${PROVIDER} and it died. No replacement of disconnected component was possible."
+ ;;
+ 'A')
+ echo "It is non-fatal for ${PROVIDER}, but replacement of disconnected component is not possible."
+ ;;
+ 'F')
+ echo "It is non-fatal for ${PROVIDER}. Replacement of disconnected component is possible."
+ if [ -n "${repla}" ] ; then
+ echo "Spare drives were configured for this device: ${repla}."
+ if [ -n "${repls}" ] ; then
+ echo "Disconnected component was replaced with ${repls}."
+ else
+ echo "Replacement of disconnected component failed."
+ fi
+ [ -n "${replu}" ] && echo "Spare drives with unknown status: ${replu}"
+ [ -n "${replb}" ] && echo "Busy spare drives: ${replb}"
+ [ -n "${remfm}" ] && echo "Removal of disconnected component failed: ${remfm}"
+ if [ -n "${replfm}" ] ; then
+ echo "Failed replacements trys:"
+ echo "${replfm}" | tr \| \\n
+ fi
+ else
+ echo "Spare drive was not configured for this device."
+ fi
+ ;;
+ '?')
+ echo "${PROVIDER} has unknown status, replacement of disconnected component is not possible."
+ ;;
+ *)
+ echo "${PROVIDER} has invalid status ${state}, replacement of disconnected component is not possible."
+ ;;
+ esac
+ ) | mail -s "${CLASS} ${GEOM}:${PROVIDER} lost component ${component}" ${geom_events_notify}
+ fi
+}
+
+event_SYNCSTART () {
+ if [ $# -ne 0 ] ; then
+ usage
+ fi
+ # Write line to log, if configured
+ if check_yesno geom_events_log ; then
+ /usr/bin/logger -t GEOM "${CLASS} ${GEOM}:${PROVIDER} starts rebuilding"
+ fi
+ # Send mail to user, if configured
+ if [ -n "${geom_events_notify}" ] ; then
+ (
+ echo "${CLASS} ${GEOM}:${PROVIDER} starts rebuilding or synchronization"
+ ) | mail -s "${CLASS} ${GEOM}:${PROVIDER} starts rebuilding" ${geom_events_notify}
+ fi
+}
+
+event_SYNCSTOP () {
+ local stopact
+ if [ $# -ne 1 ] ; then
+ usage "<complete flag>"
+ fi
+ if [ "$1" = 'Y' ] ; then
+ stopact="finished"
+ else
+ stopact="aborted"
+ fi
+ # Write line to log, if configured
+ if check_yesno geom_events_log ; then
+ /usr/bin/logger -t GEOM "Rebuilding of ${CLASS} ${GEOM}:${PROVIDER} ${stopact}"
+ fi
+ # Send mail to user, if configured
+ if [ -n "${geom_events_notify}" ] ; then
+ (
+ echo "Rebuilding or synchronization of ${CLASS} ${GEOM}:${PROVIDER} ${stopact}"
+ ) | mail -s "Rebuilding of ${CLASS} ${GEOM}:${PROVIDER} ${stopact}" ${geom_events_notify}
+ fi
+}
+
+event_DESTROYED () {
+ if [ $# -ne 0 ] ; then
+ usage
+ fi
+ # Write line to log, if configured
+ if check_yesno geom_events_log ; then
+ /usr/bin/logger -t GEOM "${CLASS} ${GEOM}:${PROVIDER} destroyed"
+ fi
+ # Send mail to user, if configured
+ if [ -n "${geom_events_notify}" ] ; then
+ (
+ echo "${CLASS} ${GEOM}:${PROVIDER} destroyed"
+ ) | mail -s "${CLASS} ${GEOM}:${PROVIDER} destroyed" ${geom_events_notify}
+ fi
+}
+
+event_UNKNOWN () {
+ local msg
+ msg="Unknown event ${EVENT} was sent by GEOM class ${CLASS}, device ${GEOM}:${PROVIDER}"
+ check_yesno geom_events_log && /usr/bin/logger -t GEOM "${msg}"
+ [ -n "${geom_events_notify}" ] && echo "${msg}" | \
+ mail -s "${CLASS} ${GEOM}:${PROVIDER} sent event ${EVENT}" ${geom_events_notify}
+}
+
+normalize_name () {
+ echo -n $1 | /usr/bin/tr -c "_a-zA-Z0-9" _
+}
+
+copy_var_if_unset_and_set () {
+ local to from _unset
+ to=$1
+ from=$2
+ eval _unset=\${${to}-__UNSET__}
+ [ "${_unset}" != "__UNSET__" ] && return
+ eval _unset=\${${from}-__UNSET__}
+ [ "${_unset}" != "__UNSET__" ] && eval $to=\${${from}}
+}
+
+get_var () {
+ local name class device component val _n _unset
+ name=`normalize_name $1`
+ class=`normalize_name $2`
+ geom=`normalize_name $3`
+ component=`normalize_name $4`
+ [ "${component}" = '_unknown_' ] && component=""
+ if [ -n "${class}" ] ; then
+ if [ -n "${geom}" ] ; then
+ if [ -n "${component}" ] ; then
+ copy_var_if_unset_and_set val "${name}_${class}_${geom}_${component}"
+ fi
+ copy_var_if_unset_and_set val "${name}_${class}_${geom}"
+ fi
+ copy_var_if_unset_and_set val "${name}_${class}"
+ fi
+ copy_var_if_unset_and_set val "${name}"
+ echo "${val}"
+}
+
+check_yesno()
+{
+ eval _value=\$${1}
+ case $_value in
+ [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
+ return 0
+ ;;
+ [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
+ return 1
+ ;;
+ *)
+ return 1
+ ;;
+ esac
+}
+
+if [ $# -lt 4 ] ; then
+ usage "[...]"
+fi
+
+# Set three variables, which should be set for any event
+EVENT=$1 ; shift
+CLASS=$1 ; shift
+GEOM=$1 ; shift
+PROVIDER=$1 ; shift
+
+# Include generic configuration
+[ -r /etc/geom-events.conf ] && . /etc/geom-events.conf
+
+# Include class-specific configuration
+[ -r /etc/geom-events.d/${CLASS}.conf ] && . /etc/geom-events.d/${CLASS}.conf
+[ -r /usr/local/etc/geom-events.d/${CLASS}.conf ] && . /usr/local/etc/geom-events.d/${CLASS}.conf
+
+# Include class- and geom-specific configuration
+[ -r /etc/geom-events.d/${CLASS}/${GEOM}.conf ] && . /etc/geom-events.d/${CLASS}/${GEOM}.conf
+[ -r /usr/local/etc/geom-events.d/${CLASS}/${GEOM}.conf ] && . /usr/local/etc/geom-events.d/${CLASS}/${GEOM}.conf
+
+# Ok, process events
+case ${EVENT} in
+ DISCONNECT)
+ event_DISCONNECT "$@"
+ ;;
+ SYNCSTART)
+ event_SYNCSTART "$@"
+ ;;
+ SYNCSTOP)
+ event_SYNCSTOP "$@"
+ ;;
+ DESTROYED)
+ event_DESTROYED "$@"
+ ;;
+ *)
+ event_UNKNOWN "$@"
+ ;;
+esac
More information about the svn-src-projects
mailing list