1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
#
# === Parameters:
#
# [*device*]
# (optional) Path to the device.
# Defaults to "/dev/${name}"
#
# [*mnt_base_dir*]
# (optional) The directory where the flat files that store the file system
# to be loop back mounted are actually mounted at.
# Defaults to '/srv/node', base directory where disks are mounted to
#
# [*loopback*]
# (optional) Define if the device must be mounted as a loopback or not
# Defaults to false.
#
# [*fstype*]
# (optional) The filesystem type.
# Defaults to 'xfs'.
#
define swift::storage::mount(
Swift::MountDevice $device = "/dev/${name}",
Stdlib::Absolutepath $mnt_base_dir = '/srv/node',
Boolean $loopback = false,
String[1] $fstype = 'xfs'
) {
include swift::deps
include swift::params
if($loopback){
$options = 'noatime,nodiratime,nofail,loop'
} else {
$options = 'noatime,nodiratime,nofail'
}
if($fstype == 'xfs'){
$fsoptions = 'logbufs=8'
} else {
$fsoptions = 'user_xattr'
}
$user = $::swift::params::user
$group = $::swift::params::group
if $facts['swift_commented_fstab_entries'][$name] {
if $facts['swift_commented_fstab_entries'][$name] == 'active'{
# double checks to make sure that things are mounted
exec { "mount_${name}":
command => "mount ${mnt_base_dir}/${name}",
path => ['/usr/bin', '/usr/sbin', '/bin', '/sbin',],
unless => "cat /proc/mounts | grep -E '^/dev/.* ${mnt_base_dir}/${name}'",
require => Anchor['swift::config::begin'],
}->
exec { "fix_mount_permissions_${name}":
command => "chown swift:swift ${mnt_base_dir}/${name}",
path => ['/usr/bin', '/usr/sbin', '/bin', '/sbin',],
onlyif => "[ `stat -c '%U' ${mnt_base_dir}/${name}` != 'swift' ] || [ `stat -c '%G' ${mnt_base_dir}/${name}` != 'swift' ]",
before => Anchor['swift::config::end'],
}
}else{
# double checks to make sure that the folder is unmounted
exec { "unmount_fstab_commented_${name}":
command => "umount ${mnt_base_dir}/${name}",
path => ['/usr/bin', '/usr/sbin', '/bin', '/sbin',],
onlyif => "cat /proc/mounts | grep -q -E '^/dev/.* ${mnt_base_dir}/${name}'",
}
# If the drive was unmounted by swift disk auditor
# make sure that /srv/node/NAME is owned by root,
# so swift cannot fill-up the system partition.
-> exec { "fix_unmounted_drive_permissions_${name}":
command => "chown root:root ${mnt_base_dir}/${name}",
path => ['/usr/bin', '/usr/sbin', '/bin', '/sbin',],
unless => "cat /proc/mounts | grep -q -E '^/dev/.* ${mnt_base_dir}/${name}'",
onlyif => "[ `stat -c '%U' ${mnt_base_dir}/${name}` != 'root' ] || [ `stat -c '%G' ${mnt_base_dir}/${name}` != 'root' ]",
}
# If it's really unmounted, but not empty, then it
# means the folder contains files on the root filesystem:
# Chown its top folders.
-> exec { "chown_folder_${mnt_base_dir}/${name}/objects":
command => "chown root:root ${mnt_base_dir}/${name}/objects",
path => ['/usr/bin', '/usr/sbin', '/bin', '/sbin',],
onlyif => "ls -A1q ${mnt_base_dir}/${name}/ | grep -q . && test -d ${mnt_base_dir}/${name}/objects"
}
-> exec { "chown_folder_${mnt_base_dir}/${name}/accounts":
command => "chown root:root ${mnt_base_dir}/${name}/accounts",
path => ['/usr/bin', '/usr/sbin', '/bin', '/sbin',],
onlyif => "ls -A1q ${mnt_base_dir}/${name}/ | grep -q . && test -d ${mnt_base_dir}/${name}/accounts"
}
-> exec { "chown_folder_${mnt_base_dir}/${name}/containers":
command => "chown root:root ${mnt_base_dir}/${name}/containers",
path => ['/usr/bin', '/usr/sbin', '/bin', '/sbin',],
onlyif => "ls -A1q ${mnt_base_dir}/${name}/ | grep -q . && test -d ${mnt_base_dir}/${name}/containers"
}
-> notify{"${name}: The device already exist in fsttab, but is commented out": }
-> notify{"${name}: This may happen if swift has detected a problem on the device":}
-> notify{"${name}: and the swift drive-audit umounted the drive.":}
-> notify{"${name}: THIS NEEDS MANUAL UNCOMMENT AND MOUNT IF THE DRIVE IS FIXED/REPLACED.":
before => Anchor['swift::config::end'],}
}
}else{
# The directory must be owned by root before the mount,
# otherwise, when the drive breaks, swift fills-up the
# system partition.
file { "${mnt_base_dir}/${name}":
ensure => directory,
owner => 'root',
group => 'root',
require => Anchor['swift::config::begin'],
}->
mount { "${mnt_base_dir}/${name}":
ensure => mounted,
device => $device,
fstype => $fstype,
options => "${options},${fsoptions}",
}->
# Fixup rights *only* once mounted
exec { "fix_mount_permissions_${name}":
command => "chown swift:swift ${mnt_base_dir}/${name}",
path => ['/usr/bin', '/usr/sbin', '/bin', '/sbin',],
before => Anchor['swift::config::end'],
refreshonly => true,
}
}
}
|