diff --git a/bin/cdist-code-run b/bin/cdist-code-run index a6a9137f..e969d942 100755 --- a/bin/cdist-code-run +++ b/bin/cdist-code-run @@ -32,31 +32,16 @@ if [ ! -d "$(__cdist_object_dir "$object")" ]; then __cdist_exit_err "Object $object is missing." fi -finished="$(__cdist_object_code_finished "$object")" -require="$(__cdist_object_require "$object")" - code="$(__cdist_object_code "$object")-${__cdist_gencode_type}" -# Do nothing if our work has been done -if [ -f "$finished" ]; then - exit 0 -fi - echo "Checking code-${__cdist_gencode_type} for $object ..." -if [ -f "$require" ]; then - while read requirement; do - echo "Requiring dependency $requirement for $object ..." - cdist-code-run "$requirement" "$__cdist_gencode_type" - done < "$require" -fi if [ -e "$code" ]; then if [ -f "$code" ]; then if [ -x "$code" ]; then echo "Executing code-${__cdist_gencode_type} for $object ..." "$code" - touch "$finished" else __cdist_exit_err "$code exists, but is not executable." fi diff --git a/bin/cdist-config b/bin/cdist-config index 26139819..1b172ddb 100755 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -42,7 +42,6 @@ __cdist_abs_myname="$__cdist_abs_mydir/$__cdist_myname" : ${__cdist_name_bin:=bin} : ${__cdist_name_code:=code} -: ${__cdist_name_code_finished:=codedone} : ${__cdist_name_conf_dir:=conf} : ${__cdist_name_dot_cdist:=.cdist} : ${__cdist_name_explorer:=explorer} @@ -68,6 +67,7 @@ __cdist_abs_myname="$__cdist_abs_mydir/$__cdist_myname" : ${__cdist_name_type:=type} : ${__cdist_name_type_bin:=type_bin} : ${__cdist_name_type_explorer:=type_explorer} +: ${__cdist_name_objects_created:=objects_created} # Used for IDs: Allow everything not starting with - and . : ${__cdist_sane_regexp:=[^-\.].*} @@ -107,6 +107,7 @@ __cdist_tmp_file=$(mktemp "$__cdist_tmp_dir/cdist.XXXXXXXXXXXX") : ${__cdist_manifest_dir:=$__cdist_conf_dir/$__cdist_name_manifest} : ${__cdist_manifest_init:=$__cdist_manifest_dir/$__cdist_name_init} : ${__cdist_type_dir:=$__cdist_conf_dir/$__cdist_name_type} +: ${__cdist_new_objects_created:=$__cdist_local_base_dir/$__cdist_name_objects_created} ################################################################################ # Local output @@ -176,6 +177,14 @@ __cdist_init_deploy() ln -sf "$__cdist_conf_dir" "$__cdist_local_base_dir/$__cdist_name_conf_dir" } +__cdist_new_objects_created() { + touch "$__cdist_tmp_dir/object_created" +} + +__cdist_has_new_objects() { + touch "$__cdist_tmp_dir/object_created" +} + ################################################################################ # Object # @@ -185,9 +194,9 @@ __cdist_object_code() echo "$(__cdist_object_dir "$1")/${__cdist_name_code}" } -__cdist_object_code_finished() +__cdist_object_finished() { - echo "$(__cdist_object_dir "$1")/${__cdist_name_code_finished}" + echo "$(__cdist_object_dir "$1")/${__cdist_name_object_finished}" } __cdist_object_dir() @@ -250,6 +259,7 @@ __cdist_object_type_explorer_dir() echo "$(__cdist_object_dir "$1")/${__cdist_name_explorer}" } + ################################################################################ # Remote # diff --git a/bin/cdist-object-manifest-run b/bin/cdist-object-manifest-run index e20848cd..4f8111f6 100755 --- a/bin/cdist-object-manifest-run +++ b/bin/cdist-object-manifest-run @@ -35,30 +35,27 @@ __cdist_cur_object_dir="$(__cdist_object_dir "$__cdist_object")" # Only the id __cdist_object_id="$(__cdist_object_id_from_object "$__cdist_object")" -if [ ! -f "${__cdist_cur_object_dir}/$__cdist_name_object_finished" ]; then - echo "Checking manifest for $__cdist_object ..." +echo "Checking manifest for $__cdist_object ..." - __cdist_type="$(__cdist_type_from_object "$__cdist_object")" - __cdist_manifest="$(__cdist_type_manifest "$__cdist_type")" +__cdist_type="$(__cdist_type_from_object "$__cdist_object")" +__cdist_manifest="$(__cdist_type_manifest "$__cdist_type")" - if [ -f "$__cdist_manifest" ]; then - if [ -x "$__cdist_manifest" ]; then - # Make __cdist_manifest available for cdist-type-emulator - export __cdist_manifest +if [ -f "$__cdist_manifest" ]; then + if [ -x "$__cdist_manifest" ]; then + # Make __cdist_manifest available for cdist-type-emulator + export __cdist_manifest - echo "Executing manifest ${__cdist_manifest} ..." - # Make variables available to non-core - FIXME: beatify - export $__cdist_name_var_object="$__cdist_cur_object_dir" - export $__cdist_name_var_object_id="$__cdist_object_id" - export $__cdist_name_var_type="$(__cdist_type_dir "$__cdist_type")" + echo "Executing manifest ${__cdist_manifest} ..." + # Make variables available to non-core - FIXME: beatify + export $__cdist_name_var_object="$__cdist_cur_object_dir" + export $__cdist_name_var_object_id="$__cdist_object_id" + export $__cdist_name_var_type="$(__cdist_type_dir "$__cdist_type")" - cdist-manifest-run "$__cdist_target_host" "$__cdist_manifest" - else - __cdist_exit_err "${__cdist_manifest} needs to be executable." - fi + cdist-manifest-run "$__cdist_target_host" "$__cdist_manifest" + # Tell cdist that there may be new objects + touch "$__cdist_new_objects_created" + else + __cdist_exit_err "${__cdist_manifest} needs to be executable." fi fi -# done with this object -touch "$__cdist_cur_object_dir/$__cdist_name_object_finished" - diff --git a/bin/cdist-object-run b/bin/cdist-object-run index e123c7a4..6ad95656 100755 --- a/bin/cdist-object-run +++ b/bin/cdist-object-run @@ -21,6 +21,7 @@ # # For the given object: # - run type explorers +# - run type manifest # - generate code # - copy object to target # - execute code on target @@ -35,24 +36,41 @@ __cdist_object="$1"; shift __cdist_type="$(__cdist_type_from_object "$__cdist_object")" +__cdist_types_pushed="$__cdist_tmp_dir/types_pushed" +touch "$__cdist_types_pushed" -# Check if type of object has >= 1 explorer -__cdist_has_explorer="$(__cdist_type_has_explorer "$__cdist_type")" +__cdist_object_finished="$(__cdist_object_finished "$__cdist_object")" +if [ ! -f "$__cdist_object_finished" ]; then + + echo + echo "Running object $__cdist_object" + + # Check if type of object has >= 1 explorer + __cdist_has_explorer="$(__cdist_type_has_explorer "$__cdist_type")" + + # Run the type explorers for the current object if any + if [ "$__cdist_has_explorer" ]; then + if ! grep -q "$__cdist_type" "$__cdist_types_pushed"; then + cdist-type-explorer-push "$__cdist_target_host" "$__cdist_type" + echo "$__cdist_type" >> "$__cdist_types_pushed" + fi + + cdist-object-explorer-run "$__cdist_target_host" "$__cdist_object" + fi + + # Run the manifest for the current object + cdist-object-manifest-run "$__cdist_target_host" "$__cdist_object" + + # Run the gencode scripts for the current object + cdist-object-gencode-run "$__cdist_target_host" "$__cdist_object" + + # Transfer the current object to the target + cdist-object-push "$__cdist_target_host" "$__cdist_object" + + # Run the code for the current object + cdist-object-code-run "$__cdist_target_host" "$__cdist_object" + + # Mark this object as done + touch "$__cdist_object_finished" -# Run the type explorers for the current object if any -if [ "$__cdist_has_explorer" ]; then - cdist-object-explorer-run "$__cdist_target_host" "$__cdist_object" fi - -# Run the manifest for the current object -cdist-object-manifest-run "$__cdist_target_host" "$__cdist_object" - -# Run the gencode scripts for the current object -cdist-object-gencode-run "$__cdist_target_host" "$__cdist_object" - -# Transfer the current object to the target -cdist-object-push "$__cdist_target_host" "$__cdist_object" - -# Run the code for the current object -cdist-object-code-run "$__cdist_target_host" "$__cdist_object" - diff --git a/bin/cdist-object-run-all b/bin/cdist-object-run-all index 45a1ae2a..582ff163 100755 --- a/bin/cdist-object-run-all +++ b/bin/cdist-object-run-all @@ -29,39 +29,38 @@ set -eu __cdist_target_host="$1"; shift __cdist_objects="$__cdist_tmp_dir/objects" -__cdist_types_pushed="$__cdist_tmp_dir/types_pushed" -touch "$__cdist_types_pushed" + +# Loop until we do not create new objects anymore +# which is equal to all objects have been run +touch "$__cdist_new_objects_created" +while [ -f "$__cdist_new_objects_created" ]; do + # Assume we're done after this run + rm "$__cdist_new_objects_created" + + # Get listing of objects + __cdist_object_list "$__cdist_out_object_dir" > "$__cdist_objects" -# Get listing of objects -__cdist_object_list "$__cdist_out_object_dir" > "$__cdist_objects" + # NEED TO CREATE ARRAY, SSH DESTROYS WHILE READ LOOP + while read __cdist_object; do + set -- "$@" "$__cdist_object" + done < "$__cdist_objects" + while [ $# -gt 0 ]; do + __cdist_object="$1"; shift -# NEED TO CREATE ARRAY, SSH DESTROYS WHILE READ LOOP -while read __cdist_object; do - set -- "$@" "$__cdist_object" -done < "$__cdist_objects" + __cdist_object_require="$(__cdist_object_require "$__cdist_object")" + if [ -f "$__cdist_object_require" ]; then + echo + while read __cdist_requirement; do + echo "Resolving dependency $__cdist_object -> $__cdist_requirement ..." + cdist-object-run "$__cdist_target_host" "$__cdist_requirement" + done < "$__cdist_object_require" + fi -while [ $# -gt 0 ]; do - __cdist_object="$1"; shift - echo - echo "Running object $__cdist_object" - - __cdist_type="$(__cdist_type_from_object "$__cdist_object")" - - # Check if type of object has >= 1 explorer - __cdist_has_explorer="$(__cdist_type_has_explorer "$__cdist_type")" - - # Transfer the type explorers if any - if [ "$__cdist_has_explorer" ]; then - if ! grep -q "$__cdist_type" "$__cdist_types_pushed"; then - cdist-type-explorer-push "$__cdist_target_host" "$__cdist_type" - echo "$__cdist_type" >> "$__cdist_types_pushed" - fi - fi - - # Process the given object - cdist-object-run "$__cdist_target_host" "$__cdist_object" + # Process the object + cdist-object-run "$__cdist_target_host" "$__cdist_object" + done done