From cd70c2ecee69f6e5f48ca9aacddd2f79174f7258 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 25 Feb 2011 01:42:13 +0100 Subject: [PATCH] cleanups + finish: we're able to run code remotely Signed-off-by: Nico Schottelius --- bin/{cdist-code-run => cdist-code-run-all} | 10 ++- bin/cdist-deploy-to | 6 +- bin/cdist-object-codegen | 1 - bin/cdist-remote-code-run | 74 ---------------------- bin/cdist-remote-code-run-all | 54 ++++++++++++++++ 5 files changed, 60 insertions(+), 85 deletions(-) rename bin/{cdist-code-run => cdist-code-run-all} (75%) delete mode 100755 bin/cdist-remote-code-run create mode 100755 bin/cdist-remote-code-run-all diff --git a/bin/cdist-code-run b/bin/cdist-code-run-all similarity index 75% rename from bin/cdist-code-run rename to bin/cdist-code-run-all index 598b3c5d..27935ee3 100755 --- a/bin/cdist-code-run +++ b/bin/cdist-code-run-all @@ -18,16 +18,14 @@ # along with cdist. If not, see . # # -# Exec executables on the remote side +# Exec code on the remote side # . cdist-config [ $# -eq 1 ] || __cdist_usage "" set -e -export __cdist_target_host="$1"; shift +__cdist_target_host="$1"; shift - -# Run executables - no order, no dependencies yet -ssh "root@${__cdist_target_host}" \ - "find \"${__cdist_remote_cache_exec}\" -type f -name \"${__cdist_name_exec}\" -exec {} \\;" +cdist-run-remote "$__cdist_target_host" \ + "cdist-remote-code-run-all" "${__cdist_remote_out_object_base_dir}" diff --git a/bin/cdist-deploy-to b/bin/cdist-deploy-to index 71f6ef0c..2cb9d303 100755 --- a/bin/cdist-deploy-to +++ b/bin/cdist-deploy-to @@ -62,7 +62,5 @@ cdist-object-codegen-all "$__cdist_target_host" "$__cdist_out_object_dir" cdist-dir push "$__cdist_target_host" "$__cdist_out_object_dir" \ "${__cdist_remote_out_object_base_dir}" -exit 2 - - -cdist-exec-run "$__cdist_target_host" +# And finally - execute the code +cdist-code-run-all "$__cdist_target_host" diff --git a/bin/cdist-object-codegen b/bin/cdist-object-codegen index 9b5405e7..b9bdae72 100755 --- a/bin/cdist-object-codegen +++ b/bin/cdist-object-codegen @@ -43,7 +43,6 @@ export __object="$__cdist_object_dir" cd "$__cdist_local_base_dir" -echo "Generating code for $__cdist_object ..." cat << eof # # The following code is imported from output of $gencode diff --git a/bin/cdist-remote-code-run b/bin/cdist-remote-code-run deleted file mode 100755 index 7064a323..00000000 --- a/bin/cdist-remote-code-run +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/sh -# -# 2011 Nico Schottelius (nico-cdist at schottelius.org) -# -# 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 . -# -# -# This binary is executed on the remote side to execute explorers -# -# It supports different variables names to be used, so __explorers -# and __type_explorers can be submitted :-) -# - -. cdist-config -if [ $# -ne 3 ]; then - __cdist_usage " " -fi -set -ue - -# Variable that defines the home of the explorers -__cdist_variable_name="$1"; shift - -# Find explorers here -__cdist_explorer_dir="$1"; shift - -# Write output here -__cdist_my_out_dir="$1"; shift - -# cd to this dir -__cdist_work_dir="$__cdist_remote_base_dir" - -# Setup environment -export $__cdist_variable_name="$__cdist_explorer_dir" -cd "${__cdist_work_dir}" -mkdir -p "$__cdist_my_out_dir" - -# Ensure there is at least one explorer -num="$(ls -1 "$__cdist_explorer_dir" | wc -l)" -if [ "$num" -lt 1 ]; then - __cdist_exit_err "${__cdist_explorer_dir}: Contains no explorers" -fi - -# Execute all explorers -for explorer in "$__cdist_explorer_dir/"*; do - explorer_name="${explorer##*/}" - - if [ -f "$explorer" ]; then - if [ ! -x "$explorer" ]; then - echo "Explorer \"$explorer\" exists, but is not executable." - continue - fi - - # Execute explorers and save results in remote destination directory - "$explorer" "$@" > "${__cdist_my_out_dir}/$explorer_name" - else - if [ -e "$explorer" ]; then - echo "Explorer \"$explorer\" exists, but is not a file." - continue - fi - fi -done diff --git a/bin/cdist-remote-code-run-all b/bin/cdist-remote-code-run-all new file mode 100755 index 00000000..6f21a99d --- /dev/null +++ b/bin/cdist-remote-code-run-all @@ -0,0 +1,54 @@ +#!/bin/sh +# +# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# +# 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 . +# +# +# This binary is executed on the remote side to execute explorers +# +# It supports different variables names to be used, so __explorers +# and __type_explorers can be submitted :-) +# + +. cdist-config +if [ $# -ne 1 ]; then + __cdist_usage "" +fi +set -ue + +__cdist_object_base_dir="$1"; shift + +__cdist_object_list "$__cdist_object_base_dir" > "$__cdist_tmp_file" + +# FIXME post 1.0: add dependencies +while read object; do + code="$(__cdist_object_code "$object")" + echo "Running code for $object ..." + if [ -e "$code" ]; then + if [ -f "$code" ]; then + if [ -x "$code" ]; then + "$code" + else + __cdist_exit_err "$code exists, but is not executable." + fi + else + __cdist_exit_err "$code exists, but is not a file." + fi + else + __cdist_exit_err "Missing code for ${object}." + fi +done < "$__cdist_tmp_file"