diff --git a/bacula/files/tapealert b/bacula/files/tapealert new file mode 100755 index 0000000..b7f79b1 --- /dev/null +++ b/bacula/files/tapealert @@ -0,0 +1,23 @@ +#!/bin/sh + +if [ $# -ne 1 ]; then + echo "Usage: `basename $0` " 1>&2 + exit 1 +fi + +PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin + +DEVICE=$1 +GENERIC=`readlink /sys/class/scsi_tape/\`basename ${DEVICE}\`/device/generic` +if [ $? -ne 0 ]; then + echo "ERR: Cannot find tape drive ${DEVICE}" 1>&2 + exit 1 +fi +GENERIC=/dev/`basename ${GENERIC}` + +tapeinfo -f ${GENERIC} | fgrep TapeAlert +if [ $? -eq 1 ]; then + exit 0 +fi + +smartctl -H -l error ${GENERIC} diff --git a/bacula/manifests/init.pp b/bacula/manifests/init.pp index 9e1b7f7..f4d8ea4 100644 --- a/bacula/manifests/init.pp +++ b/bacula/manifests/init.pp @@ -358,6 +358,23 @@ class bacula::storage($password = undef) { before => Class["bacula::certificates"], } + file { "/etc/sysconfig/bacula-sd": + ensure => present, + content => "SD_USER=bacula\nSD_GROUP=bacula\n", + mode => "0644", + owner => "root", + group => "root", + require => Package["bacula-storage"], + notify => Service["bacula-sd"], + } + exec { "usermod-bacula": + path => "/bin:/usr/bin:/sbin:/usr/sbin", + command => "usermod -a -G tape bacula", + unless => "id -n -G bacula | grep '\\btape\\b'", + require => Package["bacula-storage"], + before => Service["bacula-sd"], + } + file { "/etc/bacula/bacula-sd.conf": ensure => present, content => template("bacula/bacula-sd.conf.erb"), @@ -408,10 +425,7 @@ class bacula::storage($password = undef) { define bacula::device($device, $media) { include bacula::storage - require smart - package { "mtx": - ensure => installed, - } + require bacula::device::common file { "/etc/bacula/bacula-sd.d/${name}.conf": ensure => present, @@ -435,6 +449,24 @@ define bacula::device($device, $media) { } +class bacula::device::common { + + require smart + package { "mtx": + ensure => installed, + } + + file { "/usr/local/sbin/tapealert": + ensure => present, + source => "puppet:///modules/bacula/tapealert", + mode => "0755", + owner => "root", + group => "root", + } + +} + + # Install Bacula web interface # # === Parameters diff --git a/bacula/templates/device.conf.erb b/bacula/templates/device.conf.erb index 32ee365..b98dbf9 100644 --- a/bacula/templates/device.conf.erb +++ b/bacula/templates/device.conf.erb @@ -8,6 +8,5 @@ Device { RemovableMedia = yes; RandomAccess = no; Maximum Network Buffer Size = 65536 - Alert Command = "sh -c 'tapeinfo -f <%= @device %> | grep TapeAlert | cat'" - Alert Command = "sh -c 'smartctl -H -l error <%= @device %> | cat'" + Alert Command = "sh -c '/usr/local/sbin/tapealert %a'" }