Skip to content

Commit

Permalink
Merge branch 'behlendorf-centos7'
Browse files Browse the repository at this point in the history
  • Loading branch information
rouben committed May 14, 2017
2 parents 7cc3816 + d6d83fc commit fac8ba4
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 24 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ Some notes:
utility `ledctl` (part of ledmon package) is required for this
functionality.

- Logging to file `/var/log/zfswatcher.log` and local syslog daemon is enabled
by default.
- Logging to file `/var/log/zfswatcher/zfswatcher.log` and local syslog
daemon is enabled by default.

- E-mail notifications are disabled by default.

Expand Down
6 changes: 6 additions & 0 deletions etc/80-enclosure-zfswatcher.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# Correct /sys/class/enclosure permissions such that members of the
# zfswatcher group may control the enclosure.
#
SUBSYSTEM=="enclosure", PROGRAM="/bin/sh -c '/bin/chown -R root:zfswatcher /sys/%p'"
SUBSYSTEM=="enclosure", PROGRAM="/bin/sh -c '/bin/chmod -R ug+rw /sys/%p'"
2 changes: 1 addition & 1 deletion etc/logrotate.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/var/lib/zfswatcher.log
/var/log/zfswatcher/zfswatcher.log
{
rotate 6
monthly
Expand Down
103 changes: 103 additions & 0 deletions etc/zfswatcher-ledctl
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/bash
#
# This script is designed to emulate a subset of the functionality of
# the ledctl(8) utility. This includes accepting approximately the
# same command line option formatting which allows it to be used as a
# drop in replacement.
#
# Unlike ledctl(8) this script depends on the SES functionality provided
# through sysfs. This allows standard filesystem permissions to be used
# to control access. It is designed to be used in conjection with the
# 80-enclosure-zfswatcher.rules which ensures the 'fault' and 'locate'
# sysfs entries are writable by the zfswatcher group.
#
# Set the locate beacon:
# zfswatcher-ledctl locate=/dev/disk/by-vdev/A1
#
# Set the fault beacon:
# zfswatcher-ledctl failure=/dev/disk/by-vdev/A1
#

function check_file
{
local file="$1"

if [ -e "$file" ]; then
if [ ! -w "$file" ]; then
echo "Permission denied: '$file'"
return 1
fi
else
echo "Missing file: '$file'"
return 1
fi

return 0
}

function set_file
{
local file="$1"
local value="$2"

current=$(cat "$file")
if [ "$current" != "$value" ]; then
echo "$value" >"$file" 2>/dev/null

current=$(cat "$file")
if [ "$current" != "$value" ]; then
echo "Set '$file = $value' FAIL"
else
echo "Set '$file = $value' SUCCESS"
fi
fi
}

for arg in "$@"; do
key=$(echo "$arg" | cut -f1 -d'=')
value=$(echo "$arg" | cut -f2 -d'=')

# Determine the underlying device.
realdev=$(basename $(realpath $value))
if [[ "$realdev" == dm* ]]; then
basedev=$(ls -1U /sys/block/$realdev/slaves | head -1)
else
basedev="$realdev"
fi

# Determine the attached enclosure.
encdev=$(ls -1U /sys/block/$basedev/device/ | grep -m1 enclosure_device)
if [ -z "$encdev" ]; then
echo "Missing enclosure link for device: $basedev"
continue
fi

slotpath="/sys/block/$basedev/device/$encdev"
faultfile="$slotpath/fault"
locatefile="$slotpath/locate"

case "$key" in
"normal")
check_file "$faultfile" && set_file "$faultfile" 0
check_file "$locatefile" && set_file "$locatefile" 0
;;
"failure")
check_file "$faultfile" && set_file "$faultfile" 1
;;
"failure_off")
check_file "$faultfile" && set_file "$faultfile" 0
;;
"locate")
check_file "$locatefile" && set_file "$locatefile" 1
;;
"locate_off")
check_file "$locatefile" && set_file "$locatefile" 0
;;
*)
echo "Unknown pattern name: $key=$value"
continue
;;
esac
done

exit 0
8 changes: 5 additions & 3 deletions etc/zfswatcher.conf
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ usedspace = 80%:info 85%:notice 90%:err 95%:crit
; Whether the enclosure LED management should be enabled or not:
enable = false
;
; The external "ledctl" command (distributed as a part of "ledmon" package):
ledctlcmd = /usr/sbin/ledctl
; Custom script which controls enclosure LEDs through sysfs. The udev rule
; 80-enclosure-zfswatcher.rules sets read/write permission for members of
; the zfswatcher group to modify entries in /sys/class/enclosure/.
ledctlcmd = /usr/sbin/zfswatcher-ledctl
;
; The following maps device states to IBPI blinking patterns.
; Possible pattern names are: normal, locate, fail, rebuild, rebuild_p,
Expand All @@ -145,7 +147,7 @@ enable = true
level = debug
;
; The path name of the log file:
file = /var/log/zfswatcher.log
file = /var/log/zfswatcher/zfswatcher.log

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; The "syslog" section(s) define syslog(3) based logging destinations.
Expand Down
4 changes: 4 additions & 0 deletions etc/zfswatcher.service
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
[Unit]
Description=ZFS monitoring daemon
Documentation=man:zfswatcher(8) http://zfswatcher.damicon.fi/
After=zfs-import-cache.service
After=zfs-import-scan.service

[Service]
Type=simple
ExecStart=/usr/sbin/zfswatcher
User=zfswatcher
Restart=on-failure

[Install]
WantedBy=multi-user.target
54 changes: 36 additions & 18 deletions zfswatcher.spec
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,22 @@ Source0: %{name}-%{version}.tar.gz
ExclusiveArch: x86_64
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

%define _udevdir /usr/lib/udev/rules.d/
%define debug_package %{nil}

%define unit %{name}.service
%define rule 80-enclosure-%{name}.rules
%define ledctl %{name}-ledctl
%define user %{name}
%define group %{name}

#BuildRequires: # Go 1.0.3
Requires: zfs
Requires(post): chkconfig
Requires(preun): chkconfig
Requires(preun): initscripts
Requires(postun): initscripts
Requires(pre): /usr/sbin/useradd, /usr/sbin/groupadd, /usr/bin/getent
Requires(postun): /usr/sbin/userdel, /usr/sbin/groupdel
Requires(post): systemd
Requires(preun): systemd
Requires(postun): systemd

%description
Zfswatcher is ZFS pool monitoring and notification daemon
Expand All @@ -39,12 +49,19 @@ make
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT

%__mkdir_p ${RPM_BUILD_ROOT}%{_initddir}
%__install -p -m 755 etc/redhat-startup.sh ${RPM_BUILD_ROOT}%{_initddir}/%{name}
%__install -p -m 755 etc/%{ledctl} ${RPM_BUILD_ROOT}%{_sbindir}/%{ledctl}

%__mkdir_p ${RPM_BUILD_ROOT}%{_unitdir}
%__install -p -m 755 etc/%{unit} ${RPM_BUILD_ROOT}%{_unitdir}/%{unit}

%__mkdir_p ${RPM_BUILD_ROOT}%{_udevdir}
%__install -p -m 644 etc/%{rule} ${RPM_BUILD_ROOT}%{_udevdir}/%{rule}

%__mkdir_p -m 755 ${RPM_BUILD_ROOT}%{_sysconfdir}/logrotate.d
%__install -p -m 644 etc/logrotate.conf ${RPM_BUILD_ROOT}%{_sysconfdir}/logrotate.d/%{name}

%__mkdir_p -m 755 ${RPM_BUILD_ROOT}%{_var}/log/%{name}


%clean
rm -rf $RPM_BUILD_ROOT
Expand All @@ -56,26 +73,27 @@ rm -rf $RPM_BUILD_ROOT
%{_sbindir}/*
%{_mandir}/man8/*
%{_datadir}/%{name}/
%{_initddir}/%{name}
%config(noreplace) %{_unitdir}/%{unit}
%config(noreplace) %{_udevdir}/%{rule}
%config(noreplace) %{_sysconfdir}/zfs/*.conf
%config(noreplace) %{_sysconfdir}/logrotate.d/*
%dir %attr(0755, %{name}, %{name}) %{_var}/log/%{name}


%pre
/usr/bin/getent group %{group} || /usr/sbin/groupadd -r %{group}
/usr/bin/getent passwd %{user} || /usr/sbin/useradd -r -d %{_sbindir} -s /sbin/nologin -g %{group} %{user}


%post
# This adds the proper /etc/rc*.d links for the script
/sbin/chkconfig --add zfswatcher
%systemd_post %{unit}


%preun
if [ $1 -eq 0 ] ; then
/sbin/service zfswatcher stop >/dev/null 2>&1
/sbin/chkconfig --del zfswatcher
fi
%systemd_preun %{unit}


%postun
if [ "$1" -ge "1" ] ; then
/sbin/service zfswatcher condrestart >/dev/null 2>&1 || :
fi


%systemd_postun %{unit}
/usr/sbin/userdel %{name}
/usr/sbin/groupdel %{name}

0 comments on commit fac8ba4

Please sign in to comment.