diff --git a/etc/ngcp-config/ngcpcfg.cfg b/etc/ngcp-config/ngcpcfg.cfg index 15abe48b..ae8350d6 100644 --- a/etc/ngcp-config/ngcpcfg.cfg +++ b/etc/ngcp-config/ngcpcfg.cfg @@ -29,6 +29,9 @@ SERVICES_POOL="${SERVICES_POOL_BASE}/etc" # timestamp format for console output TIME_FORMAT="+%F %T" +# directory holding files for internal state of ngcpcfg +TIMESTAMP_DIR='/var/lib/ngcpcfg/timestamps/' + # validate configs using kwalify schema VALIDATE_SCHEMA="false" ## END OF FILE ################################################################# diff --git a/functions/main b/functions/main index 81c33764..ff3fbc02 100644 --- a/functions/main +++ b/functions/main @@ -125,6 +125,11 @@ if ! [ -d "$TEMPLATE_POOL_BASE" ] ; then exit 1 fi +if [ -z "${TIMESTAMP_DIR:-}" ] ; then + log_error "No timestamp directory setting [TIMESTAMP_DIR] found - exiting." + exit 1 +fi + if [ -d "${EXTRA_CONFIG_DIR:-}" ] && ls ${EXTRA_CONFIG_DIR}/*.yml &>/dev/null ; then log_debug "EXTRA_CONFIG_DIR is configured and *.yml files are present, setting EXTRA_CONFIG_FILES" EXTRA_CONFIG_FILES=${EXTRA_CONFIG_DIR}/*.yml @@ -245,6 +250,11 @@ generate_template_list() { unset filelist_prepared filelist_final } + +timestamp_action() { + mkdir -p "${TIMESTAMP_DIR}" + touch "${TIMESTAMP_DIR}/${1}" +} ## }}} ## END OF FILE ################################################################# diff --git a/sbin/ngcpcfg b/sbin/ngcpcfg index 6c74ae15..d6cb5e4e 100755 --- a/sbin/ngcpcfg +++ b/sbin/ngcpcfg @@ -36,66 +36,79 @@ fi initialise() { log_debug "${SCRIPTS}/initialise $*" "${SCRIPTS}"/initialise $* + timestamp_action "initialise" } build() { log_debug "${SCRIPTS}/build $*" "${SCRIPTS}"/build $* + timestamp_action "build" } services() { log_debug "${SCRIPTS}/services $*" "${SCRIPTS}"/services $* + timestamp_action "services" } encrypt() { log_debug "${SCRIPTS}/encrypt $*" "${SCRIPTS}"/encrypt $* + timestamp_action "encrypt" } decrypt() { log_debug "${SCRIPTS}/decrypt $*" "${SCRIPTS}"/decrypt $* + timestamp_action "decrypt" } diff() { log_debug "${SCRIPTS}/diff $*" "${SCRIPTS}"/diff $* + timestamp_action "diff" } etckeeper() { log_debug "${SCRIPTS}/etckeeper $*" "${SCRIPTS}"/etckeeper $* + timestamp_action "etckeeper" } commit() { log_debug "${SCRIPTS}/commit $*" "${SCRIPTS}"/commit $* + timestamp_action "commit" } status() { log_debug "${SCRIPTS}/status $*" "${SCRIPTS}"/status $* + timestamp_action "status" } check() { log_debug "${SCRIPTS}/check $*" "${SCRIPTS}"/check $* + timestamp_action "check" } values() { log_debug "${SCRIPTS}/values $*" "${SCRIPTS}"/values $* + timestamp_action "values" } log() { log_debug "${SCRIPTS}/log $*" "${SCRIPTS}"/log $* + timestamp_action "log" } show() { log_debug "${SCRIPTS}/show $*" "${SCRIPTS}"/show $* + timestamp_action "show" } apply() { diff --git a/scripts/apply b/scripts/apply index aa1b986e..a865b9ae 100755 --- a/scripts/apply +++ b/scripts/apply @@ -38,6 +38,19 @@ if check_for_outstanding_commits && [ -z "${1:-}" ] ; then exit 1 fi -"${SCRIPTS}"/check && "${SCRIPTS}"/build && "${SCRIPTS}"/services && "${SCRIPTS}"/commit "$*" && "${SCRIPTS}"/etckeeper +"${SCRIPTS}"/check +timestamp_action "check" + +"${SCRIPTS}"/build +timestamp_action "build" + +"${SCRIPTS}"/services +timestamp_action "services" + +"${SCRIPTS}"/commit "$*" +timestamp_action "commit" + +"${SCRIPTS}"/etckeeper +timestamp_action "etckeeper" ## END OF FILE ################################################################# diff --git a/scripts/status b/scripts/status index 08d83116..bdf51d34 100755 --- a/scripts/status +++ b/scripts/status @@ -116,11 +116,42 @@ check_remote() { fi } +check_pending_actions() { + log_debug "check_pending_actions" + + log_debug "cd $NGCPCTL_MAIN" + cd "$NGCPCTL_MAIN" + + log_info "Checking state of pending builds:" + + local timestamp_commit=$(git log --format='%ct' -1) + log_debug "timestamp_commit = $timestamp_commit" + if ! [ -f "${TIMESTAMP_DIR}/build" ] ; then + log_debug "File ${TIMESTAMP_DIR}/build doesn't exist." + log_info "OK: no build/apply executed yet, nothing to do" + return 0 + fi + + local timestamp_build=$(stat --format='%Y' "${TIMESTAMP_DIR}/build") + log_debug "timestamp_build = $timestamp_build" + + if [ -n "$timestamp_commit" ] && [ -n "$timestamp_build" ] ; then + local timediff=$(( timestamp_commit - timestamp_build )) + log_debug "timediff = $timediff" + if [ -n "$timediff" ] && [ "$timediff" -le 0 ] ; then + log_info "OK: nothing to build" + else + log_info "ACTION_NEEDED: commits without according build identified" + log_info "-> execute either 'ngcpcfg build' or 'ngcpcfg apply'" + fi + fi +} if [ -z "${1:-}" ] ; then check_local_state check_push check_etc_state + check_pending_actions check_shared_storage "$@" fi