manifest 1.56 KB
Newer Older
Darko Poljak's avatar
Darko Poljak committed
1
#!/bin/sh -e
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#
# 2015 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 <http://www.gnu.org/licenses/>.
#

cdist_type="${__type##*/}"
watch_type="${cdist_type##*_}"
23
conf_dir=$(cat "$__object/explorer/conf-dir")
24 25 26 27 28 29 30 31
conf_file="watch_${watch_type}_${__object_id}.json"
state="$(cat "$__object/parameter/state")"

# Generate json config file
(
echo "{"
printf '   "watches": [{\n'
printf '      "type": "%s"\n' "$watch_type"
32 33
cd "$__object/parameter/"
for param in *; do
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
   case "$param" in
      state) continue ;;
      *)
         key="$(echo "$param" | tr '-' '_')"
         printf '      ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")"
      ;;
   esac
done
# end watches
echo "   }]"
# end json file
echo "}"
) | \
require="__directory${conf_dir}" \
   __config_file "${conf_dir}/${conf_file}" \
      --owner root --group consul --mode 640 \
      --state "$state" \
      --onchange 'service consul status >/dev/null && service consul reload || true' \
      --source -