MT#2231 status option: check for pull/push + check state of remote host(s)

mr3.4.1
Michael Prokop 12 years ago
parent fc5af3bbb2
commit def862dd8a

@ -289,10 +289,13 @@ _--dry-run_ option is present the services won't be executed but you'll be
noticed which service files would be executed if being invoked without the
_--dry-run__ option.
**status**::
**status** [--local-only]::
Display the current state of the configuration system, like modified
configuration files and pending actions.
Note: The _--local-only_ option is available in the High Availability setup
only and disables checking any remote systems (useful when the remote
system isn't available).
Usage examples

@ -130,7 +130,7 @@ case ${1:-} in
push) shift ; push "$*" ;;
pull) shift ; pull "$*" ;;
services) shift ; services "$*" ;;
status) status;;
status) shift ; status "$*" ;;
apply) shift ; build && services && commit "$*" && etckeeper ;;
encrypt) shift ; encrypt "$*" ;;
decrypt) shift ; decrypt "$*" ;;

@ -19,6 +19,62 @@ if ! [ -d "${NGCPCTL_MAIN:-}" ] ; then
exit 1
fi
usage() {
printf "ngcpcfg status -- supported command line options:
--local-only - do not check state on any remote host(s) (HA/PRO only)\n\n"
}
CHECK_REMOTE=true
REMOTE_INVOKED=false
while [ -n "${1:-}" ] ; do
case "$1" in
*--local-only*) CHECK_REMOTE=false ; shift ;;
*--remote*) REMOTE_INVOKED=true ; shift ;; # used when invoking ngcpcfg status remotely
*--help*) usage ; exit 0 ;;
*) break ;;
esac
done
remote_check() {
if ! "$CHECK_REMOTE" ; then
log_info "Skipping remote checks as requested via --local-only option."
return 0
fi
if "$REMOTE_INVOKED" ; then
log_debug "REMOTE_INVOKED is enabled, skipping remote_check"
return 0
fi
if ! [ -r "$NGCPCTL_MAIN/systems.cfg" ] ; then
log_error "File $NGCPCTL_MAIN/systems.cfg could not be read, can not check foreign servers."
log_error "Either execute 'ngcpcfg status' without --remote option or configure $NGCPCTL_MAIN/systems.cfg."
exit 1
fi
hostlist="$(cat $NGCPCTL_MAIN/systems.cfg)"
log_debug "hostlist = $hostlist"
for host in $hostlist ; do
log_debug "check $host == $HNAME"
if [[ "$host" == "$HNAME" ]] ; then
continue
fi
log_info "-----------------------------------------------------------------"
log_info "Checking state on remote system ${host}:"
log_debug "timeout 30 ssh $host ngcpcfg status --remote"
if timeout 30 ssh $host ngcpcfg status --remote ; then
log_debug "ssh $host ngcpcfg status returned without error"
else
log_error "Error while checking state on remote host ${host}."
exit 1
fi
log_info "End of state check on ${host}."
done
}
log_debug "cd $NGCPCTL_MAIN"
cd "$NGCPCTL_MAIN"
@ -28,12 +84,12 @@ if ! [ -r /etc/ngcp-config/.git/HEAD ] ; then
exit 0
fi
log_info "OK: has been initialised already "
log_info "OK: has been initialised already"
log_info "Checking state of configuration files:"
log_debug "git status | grep -q 'working directory clean'"
if git status | grep -q 'working directory clean' ; then
log_info "OK: nothing to commit."
log_info "OK: nothing to commit"
else
if git diff-index --name-only HEAD | grep -q . ; then
log_info "ACTION_NEEDED: configuration files have been modified:"
@ -58,12 +114,35 @@ fi
log_debug "cd /etc"
cd /etc
log_info "Checking state of /etc files"
log_info "Checking state of /etc files:"
log_debug "git status | grep -q 'working directory clean'"
if git status | grep -q 'working directory clean' ; then
log_info "OK: nothing to commit."
log_info "OK: nothing to commit"
else
log_info "ACTION_NEEDED: configuration files changed (execute 'etckeeper commit [message]')."
log_info "ACTION_NEEDED: configuration files changed (execute 'etckeeper commit [message]')"
fi
log_debug "cd $NGCPCTL_MAIN"
cd "$NGCPCTL_MAIN"
if [ -r /usr/share/ngcp-ngcpcfg/functions/ha_features ] ; then
log_info "Checking state of shared storage:"
log_debug "git push --dry 2>&1 | grep -q 'Everything up-to-date'"
if git push --dry 2>&1 | grep -q 'Everything up-to-date' ; then
log_info "OK: nothing to push"
else
log_info "ACTION_NEEDED: outstanding changes to push (execute 'ngcpcfg push')"
fi
log_debug "git fetch --dry-run 2>&1 | grep -q From"
if ! git fetch --dry-run 2>&1 | grep -q From ; then
log_info "OK: nothing to pull"
else
log_info "ACTION_NEEDED: outstanding changes to pull (execute 'ngcpcfg pull')"
fi
log_debug "remote_check"
remote_check
fi
## END OF FILE #################################################################

Loading…
Cancel
Save