From 6d45a492191458f35235b95e8d1107abde610d1b Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Mon, 14 Nov 2011 17:30:52 +0100 Subject: [PATCH 1/8] new type: __nfs_export manage /etc/exports Signed-off-by: Steven Armstrong --- conf/type/__nfs_export/explorer/entry | 42 +++++++++++++++ conf/type/__nfs_export/explorer/exports.d | 25 +++++++++ conf/type/__nfs_export/gencode-remote | 62 +++++++++++++++++++++++ conf/type/__nfs_export/man.text | 55 ++++++++++++++++++++ conf/type/__nfs_export/manifest | 49 ++++++++++++++++++ conf/type/__nfs_export/parameter/optional | 3 ++ conf/type/__nfs_export/parameter/required | 1 + 7 files changed, 237 insertions(+) create mode 100755 conf/type/__nfs_export/explorer/entry create mode 100755 conf/type/__nfs_export/explorer/exports.d create mode 100755 conf/type/__nfs_export/gencode-remote create mode 100644 conf/type/__nfs_export/man.text create mode 100755 conf/type/__nfs_export/manifest create mode 100644 conf/type/__nfs_export/parameter/optional create mode 100644 conf/type/__nfs_export/parameter/required diff --git a/conf/type/__nfs_export/explorer/entry b/conf/type/__nfs_export/explorer/entry new file mode 100755 index 00000000..4cb10883 --- /dev/null +++ b/conf/type/__nfs_export/explorer/entry @@ -0,0 +1,42 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +export="$(cat "$__object/parameter/export" 2>/dev/null || echo "/$__object_id")" + +name="$(echo "${export#/}" | sed 's;/;-;g')" +prefix="#cdist:__cron/$export" +suffix="#/cdist:__cron/$export" + +if [ -f "/etc/exports.d/$name" ]; then + cat "/etc/exports.d/$name" +else + awk -v prefix="$prefix" -v suffix="$suffix" '{ + if (index($0,prefix)) { + triggered=1 + } + if (triggered) { + if (index($0,suffix)) { + triggered=0 + } + print + } +}' /etc/exports +fi + diff --git a/conf/type/__nfs_export/explorer/exports.d b/conf/type/__nfs_export/explorer/exports.d new file mode 100755 index 00000000..ce370573 --- /dev/null +++ b/conf/type/__nfs_export/explorer/exports.d @@ -0,0 +1,25 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +if [ -d /etc/exports.d ]; then + echo present +else + echo absent +fi diff --git a/conf/type/__nfs_export/gencode-remote b/conf/type/__nfs_export/gencode-remote new file mode 100755 index 00000000..d0e1e1a1 --- /dev/null +++ b/conf/type/__nfs_export/gencode-remote @@ -0,0 +1,62 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +exports_d="$(cat "$__object/explorer/exports.d")" +state_should="$(cat "$__object/parameter/state")" +state_is=$(diff -q "$__object/parameter/entry" "$__object/explorer/entry" \ + && echo present \ + || echo absent +) + +if [ "$exports_d" != "present" ]; then + if [ "$state_is" != "$state_should" ]; then + case "$state_should" in + present) + cat << DONE +cat >> /etc/exports << EOC +$(cat "$__object/parameter/entry")" +EOC +DONE + ;; + absent) + # defined in type manifest + prefix="$(cat "$__object/parameter/prefix")" + suffix="$(cat "$__object/parameter/suffix")" + cat << DONE +cat /etc/exports +awk -v prefix="$prefix" -v suffix="$suffix" ' +{ + if (index(\$0,prefix)) { + triggered=1 + } + if (triggered) { + if (index(\$0,suffix)) { + triggered=0 + } + } else { + print + } +}' /etc/exports > /etc/exports+ +mv -f /etc/exports+ /etc/exports +DONE + ;; + esac + fi +fi diff --git a/conf/type/__nfs_export/man.text b/conf/type/__nfs_export/man.text new file mode 100644 index 00000000..41ff64e8 --- /dev/null +++ b/conf/type/__nfs_export/man.text @@ -0,0 +1,55 @@ +cdist-type__nfs_export(7) +========================= +Steven Armstrong + + +NAME +---- +cdist-type__nfs_export - manage nfs exports + + +DESCRIPTION +----------- +This cdist type allows you to manage entries in /etc/exports.d. +For older distributions (currently ubuntu lucid) that don't support +/etc/exports.d the entries are merged into the /etc/exports file. + + +REQUIRED PARAMETERS +------------------- +client:: + space delimited list of client ip/networks for use in /etc/exports. See exports(5) + + +OPTIONAL PARAMETERS +------------------- +options:: + export options for use in /etc/exports. See exports(5) + +export:: + the directory to export. Defaults to object_id + +state:: + Either present or absent. Defaults to present. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__nfs_export /local/chroot/lucid-amd64 \ + --client "192.168.0.1/24 10.0.0.1/16" \ + --options "ro,async,no_all_squash,no_root_squash,subtree_check" +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- exports(5) + + +COPYING +------- +Copyright \(C) 2011 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__nfs_export/manifest b/conf/type/__nfs_export/manifest new file mode 100755 index 00000000..1a267412 --- /dev/null +++ b/conf/type/__nfs_export/manifest @@ -0,0 +1,49 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +# required +client="$(cat "$__object/parameter/client")" + +# optional +export="$(cat "$__object/parameter/export" 2>/dev/null \ + || echo "/$__object_id" | tee "$__object/parameter/export")" +options="$(cat "$__object/parameter/options" 2>/dev/null || true)" +state="$(cat "$__object/parameter/state" 2>/dev/null \ + || echo "present" | tee "$__object/parameter/state")" + +entry="$export" +[ -n "$options" ] && entry="$entry -${options}" +entry="$entry $client" + +# NOTE: if changed, also change in explorers +prefix="#cdist:__nfs_export/$export" +suffix="#/cdist:__nfs_export/$export" +echo "$prefix" | tee "$__object/parameter/prefix" > "$__object/parameter/entry" +echo "$entry" >> "$__object/parameter/entry" +echo "$suffix" | tee "$__object/parameter/suffix" >> "$__object/parameter/entry" + +exports_d="$(cat "$__object/explorer/exports.d")" +if [ "$exports_d" = "present" ]; then + name="$(echo "$export" | sed 's;/;-;g')" + __file "/etc/exports.d/$name" \ + --source "$__object/parameter/entry" \ + --owner root --group root --mode 644 +# --state "$state" +fi diff --git a/conf/type/__nfs_export/parameter/optional b/conf/type/__nfs_export/parameter/optional new file mode 100644 index 00000000..f6cd84ea --- /dev/null +++ b/conf/type/__nfs_export/parameter/optional @@ -0,0 +1,3 @@ +options +export +state diff --git a/conf/type/__nfs_export/parameter/required b/conf/type/__nfs_export/parameter/required new file mode 100644 index 00000000..b051c6c5 --- /dev/null +++ b/conf/type/__nfs_export/parameter/required @@ -0,0 +1 @@ +client From 71260c77825a224ad3c6160cd68272dc9984e1ef Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Mon, 14 Nov 2011 16:20:36 +0100 Subject: [PATCH 2/8] new type: __nfs_server Signed-off-by: Steven Armstrong --- conf/type/__nfs_server/man.text | 42 ++++++++++++++++++++++++++++++++ conf/type/__nfs_server/manifest | 28 +++++++++++++++++++++ conf/type/__nfs_server/singleton | 0 3 files changed, 70 insertions(+) create mode 100644 conf/type/__nfs_server/man.text create mode 100755 conf/type/__nfs_server/manifest create mode 100644 conf/type/__nfs_server/singleton diff --git a/conf/type/__nfs_server/man.text b/conf/type/__nfs_server/man.text new file mode 100644 index 00000000..41fc1d75 --- /dev/null +++ b/conf/type/__nfs_server/man.text @@ -0,0 +1,42 @@ +cdist-type__nfs_server(7) +========================= +Steven Armstrong + + +NAME +---- +cdist-type__nfs_server - nfs server + + +DESCRIPTION +----------- +Install, start, do whatever is necessary to have a working nfs server. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +None. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__nfs_server +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2011 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__nfs_server/manifest b/conf/type/__nfs_server/manifest new file mode 100755 index 00000000..d1946b4c --- /dev/null +++ b/conf/type/__nfs_server/manifest @@ -0,0 +1,28 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +__nfs_client + +__package nfs-kernel-server --state installed + +require="__package/nfs-kernel-server" \ + __process nfs-kernel-server --state running \ + --start "/etc/init.d/portmap start" \ + --name rpc.mountd diff --git a/conf/type/__nfs_server/singleton b/conf/type/__nfs_server/singleton new file mode 100644 index 00000000..e69de29b From d88a4ea55f4fbdc32566a5c3fe54f75257ad2203 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Mon, 14 Nov 2011 16:11:50 +0100 Subject: [PATCH 3/8] new type: __nfs_client Signed-off-by: Steven Armstrong --- conf/type/__nfs_client/man.text | 42 ++++++++++++++++++++++++++++++++ conf/type/__nfs_client/manifest | 29 ++++++++++++++++++++++ conf/type/__nfs_client/singleton | 0 3 files changed, 71 insertions(+) create mode 100644 conf/type/__nfs_client/man.text create mode 100755 conf/type/__nfs_client/manifest create mode 100644 conf/type/__nfs_client/singleton diff --git a/conf/type/__nfs_client/man.text b/conf/type/__nfs_client/man.text new file mode 100644 index 00000000..3f0808a7 --- /dev/null +++ b/conf/type/__nfs_client/man.text @@ -0,0 +1,42 @@ +cdist-type__nfs_client(7) +========================= +Steven Armstrong + + +NAME +---- +cdist-type__nfs_client - nfs client + + +DESCRIPTION +----------- +Install, start, do whatever is necessary to have a working nfs client. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +None. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__nfs_client +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2011 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__nfs_client/manifest b/conf/type/__nfs_client/manifest new file mode 100755 index 00000000..a22f487a --- /dev/null +++ b/conf/type/__nfs_client/manifest @@ -0,0 +1,29 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +__package nfs-common --state installed + +require="__package/nfs-common" \ + __process portmap --state running --start "/etc/init.d/portmap start" + +require="__package/nfs-common" \ + __process statd --state running \ + --start "/etc/init.d/statd start" \ + --name rpc.statd diff --git a/conf/type/__nfs_client/singleton b/conf/type/__nfs_client/singleton new file mode 100644 index 00000000..e69de29b From 77350b0a1d31572331610f130195d6511a98f8b1 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 6 Jan 2012 10:46:06 +0100 Subject: [PATCH 4/8] use pattern instead of string Signed-off-by: Steven Armstrong --- conf/type/__nfs_client/manifest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/type/__nfs_client/manifest b/conf/type/__nfs_client/manifest index a22f487a..1059141f 100755 --- a/conf/type/__nfs_client/manifest +++ b/conf/type/__nfs_client/manifest @@ -26,4 +26,4 @@ require="__package/nfs-common" \ require="__package/nfs-common" \ __process statd --state running \ --start "/etc/init.d/statd start" \ - --name rpc.statd + --name "rpc.statd.*" From 6fe66834fd3d5693ef92eefb74ed4ee7bf20efea Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 6 Jan 2012 10:46:32 +0100 Subject: [PATCH 5/8] use pattern instead of string Signed-off-by: Steven Armstrong --- conf/type/__nfs_server/manifest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/type/__nfs_server/manifest b/conf/type/__nfs_server/manifest index d1946b4c..780cf77a 100755 --- a/conf/type/__nfs_server/manifest +++ b/conf/type/__nfs_server/manifest @@ -25,4 +25,4 @@ __package nfs-kernel-server --state installed require="__package/nfs-kernel-server" \ __process nfs-kernel-server --state running \ --start "/etc/init.d/portmap start" \ - --name rpc.mountd + --name ".*rpc.mountd.*" From 4e4a1598b28ccee48eaa1d8dbdbfa95e0485f637 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 6 Jan 2012 10:47:51 +0100 Subject: [PATCH 6/8] run exportfs after changing /etc/exports, bugix: remove trailing quote Signed-off-by: Steven Armstrong --- conf/type/__nfs_export/gencode-remote | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/conf/type/__nfs_export/gencode-remote b/conf/type/__nfs_export/gencode-remote index d0e1e1a1..60b1c9a7 100755 --- a/conf/type/__nfs_export/gencode-remote +++ b/conf/type/__nfs_export/gencode-remote @@ -25,13 +25,13 @@ state_is=$(diff -q "$__object/parameter/entry" "$__object/explorer/entry" \ || echo absent ) -if [ "$exports_d" != "present" ]; then - if [ "$state_is" != "$state_should" ]; then +if [ "$state_is" != "$state_should" ]; then + if [ "$exports_d" != "present" ]; then case "$state_should" in present) - cat << DONE + cat << DONE cat >> /etc/exports << EOC -$(cat "$__object/parameter/entry")" +$(cat "$__object/parameter/entry") EOC DONE ;; @@ -59,4 +59,6 @@ DONE ;; esac fi + # re-export if we changed something + echo "exportfs -rf" fi From b67d785a24fb027e7b50daca6ad77aaf0049d958 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 6 Jan 2012 10:50:01 +0100 Subject: [PATCH 7/8] fix copy/paste error, use proper prefix and suffix Signed-off-by: Steven Armstrong --- conf/type/__nfs_export/explorer/entry | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/conf/type/__nfs_export/explorer/entry b/conf/type/__nfs_export/explorer/entry index 4cb10883..3922fbce 100755 --- a/conf/type/__nfs_export/explorer/entry +++ b/conf/type/__nfs_export/explorer/entry @@ -21,12 +21,11 @@ export="$(cat "$__object/parameter/export" 2>/dev/null || echo "/$__object_id")" name="$(echo "${export#/}" | sed 's;/;-;g')" -prefix="#cdist:__cron/$export" -suffix="#/cdist:__cron/$export" - if [ -f "/etc/exports.d/$name" ]; then cat "/etc/exports.d/$name" else + prefix="#cdist:__nfs_export${export}" + suffix="#/cdist:__nfs_export${export}" awk -v prefix="$prefix" -v suffix="$suffix" '{ if (index($0,prefix)) { triggered=1 From 865acf37714c12b1f93c40bd7c91729bfcc9add1 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 6 Jan 2012 10:50:34 +0100 Subject: [PATCH 8/8] strip duplicate / Signed-off-by: Steven Armstrong --- conf/type/__nfs_export/manifest | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/type/__nfs_export/manifest b/conf/type/__nfs_export/manifest index 1a267412..d7cbd4df 100755 --- a/conf/type/__nfs_export/manifest +++ b/conf/type/__nfs_export/manifest @@ -33,8 +33,8 @@ entry="$export" entry="$entry $client" # NOTE: if changed, also change in explorers -prefix="#cdist:__nfs_export/$export" -suffix="#/cdist:__nfs_export/$export" +prefix="#cdist:__nfs_export${export}" +suffix="#/cdist:__nfs_export${export}" echo "$prefix" | tee "$__object/parameter/prefix" > "$__object/parameter/entry" echo "$entry" >> "$__object/parameter/entry" echo "$suffix" | tee "$__object/parameter/suffix" >> "$__object/parameter/entry"