diff options
| author | James Shubin <james@shubin.ca> | 2013-09-18 17:53:13 -0400 |
|---|---|---|
| committer | James Shubin <james@shubin.ca> | 2013-09-18 17:53:13 -0400 |
| commit | fa3fd2eb4bab499031274e0918a40e7a99fe0086 (patch) | |
| tree | 21aaca08d5cc77d041bcf8e2c8c2eee8c1f8a20f | |
| parent | d1a2fb7f7a2bc1df529d32127880ca0f35c201b1 (diff) | |
Added fancy volume creation.
This moves the command into a separate file. This also adds temporary
saving of stdout and stderr to /tmp for easy debugging of command
output.
| -rw-r--r-- | manifests/volume.pp | 21 | ||||
| -rw-r--r-- | manifests/volume/base.pp | 32 |
2 files changed, 52 insertions, 1 deletions
diff --git a/manifests/volume.pp b/manifests/volume.pp index 8aab709..60feb83 100644 --- a/manifests/volume.pp +++ b/manifests/volume.pp @@ -26,6 +26,7 @@ define gluster::volume( ) { include gluster::xml include gluster::vardir + include gluster::volume::base if $ping { include gluster::volume::ping } @@ -78,6 +79,8 @@ define gluster::volume( # will error if they see that volume directory already present, so when # we error we should rmdir any empty volume dirs to keep it pristine... # TODO: this should be a gluster bug... we must hope it doesn't happen! + # maybe related to: https://bugzilla.redhat.com/show_bug.cgi?id=835494 + $rmdir_volume_dirs = sprintf("/bin/rmdir '%s'", inline_template("<%= bricks.find_all{|x| x.split(':')[0] == '${fqdn}' }.collect {|y| y.split(':')[1].chomp('/')+'/${name}/' }.join('\' \'') %>")) # get the list of bricks fqdn's that don't have our fqdn $others = inline_template("<%= bricks.find_all{|x| x.split(':')[0] != '${fqdn}' }.collect {|y| y.split(':')[0] }.join(' ') %>") @@ -96,11 +99,13 @@ define gluster::volume( $require = $ping ? { false => [ Service['glusterd'], + File["${vardir}/volume/create-${name}.sh"], File["${vardir}/xml.py"], # status check Gluster::Brick[$bricks], ], default => [ Service['glusterd'], + File["${vardir}/volume/create-${name}.sh"], Package['fping'], File["${vardir}/xml.py"], # status check Gluster::Brick[$bricks], @@ -109,6 +114,17 @@ define gluster::volume( # run if vip not defined (bypass mode) or if vip exists on this machine if ($vip == '' or $vipif != '') { + + # store command in a separate file to run as bash... + file { "${vardir}/volume/create-${name}.sh": + content => inline_template("#!/bin/bash\n/usr/sbin/gluster volume create ${name} ${valid_replica}${valid_stripe}transport ${valid_transport} ${brick_spec} > >(/usr/bin/tee '/tmp/gluster-volume-${name}.stdout') 2> >(/usr/bin/tee '/tmp/gluster-volume-${name}.stderr' >&2) || (${rmdir_volume_dirs} && /bin/false)\nexit \$?\n"), + owner => root, + group => root, + mode => 755, + ensure => present, + require => File["${vardir}/volume/"], + } + # NOTE: This should only happen on one host! # NOTE: There's maybe a theoretical race condition if this runs # at exactly the same time on more than one host. That's why it @@ -119,8 +135,11 @@ define gluster::volume( # which per node will happen right before this runs. # fping all the other nodes to ensure they're up for creation # TODO: consider piping in a /usr/bin/yes to avoid warnings... + # NOTE: in this command, we save the std{out,err} and pass them + # on too for puppet to consume. we save in /tmp for fast access # EXAMPLE: gluster volume create test replica 2 transport tcp annex1.example.com:/storage1a/test annex2.example.com:/storage2a/test annex3.example.com:/storage3b/test annex4.example.com:/storage4b/test annex1.example.com:/storage1c/test annex2.example.com:/storage2c/test annex3.example.com:/storage3d/test annex4.example.com:/storage4d/test - exec { "/usr/sbin/gluster volume create ${name} ${valid_replica}${valid_stripe}transport ${valid_transport} ${brick_spec}": + exec { "gluster-volume-create-${name}": + command => "${vardir}/volume/create-${name}.sh", logoutput => on_failure, unless => "/usr/sbin/gluster volume list | /bin/grep -qxF '${name}' -", # add volume if it doesn't exist onlyif => $onlyif, diff --git a/manifests/volume/base.pp b/manifests/volume/base.pp new file mode 100644 index 0000000..180db01 --- /dev/null +++ b/manifests/volume/base.pp @@ -0,0 +1,32 @@ +# Simple? gluster module by James +# Copyright (C) 2010-2013+ James Shubin +# Written by James Shubin <james@shubin.ca> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +class gluster::volume::base { + + include gluster::vardir + #$vardir = $::gluster::vardir::module_vardir # with trailing slash + $vardir = regsubst($::gluster::vardir::module_vardir, '\/$', '') + + file { "${vardir}/volume/": + ensure => directory, # make sure this is a directory + recurse => true, # don't recurse into directory + purge => true, # don't purge unmanaged files + force => true, # don't purge subdirs and links + require => File["${vardir}/"], + } +} +# vim: ts=8 |
