Browse Source

new: [0km] ``vps-check`` action added

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
rc1
Valentin Lab 4 years ago
parent
commit
5a3c30586e
  1. 46
      bin/0km

46
bin/0km

@ -161,7 +161,7 @@ ssh:run() {
done
{
{
ssh -o ControlPath=/tmp/ssh-control-master-${master_pid} \
ssh -o ControlPath=/tmp/ssh-control-master-${master_pid}-$hostname \
-o ControlMaster=auto -o ControlPersist=900 \
-o "StrictHostKeyChecking=no" \
"$hostname" "${ssh_options[@]}" -- "${cmd[@]}"
@ -195,6 +195,26 @@ is_ovh_hostname() {
return 1
}
vps_check() {
local vps="$1"
ip=$(resolve "$vps") ||
{ echo "no-resolve"; return; }
ping -c 1 -w 1 "$ip" >/dev/null 2>&1 ||
{ echo "no-ping"; }
is-port-open "$ip" "22" ||
{ echo "no-port-22-open"; return; }
ssh:open -o ConnectTimeout=2 -o PreferredAuthentications=publickey \
"root@$vps" >/dev/null 2>&1 ||
{ echo "no-ssh-root-access"; return; }
compose_content=$(ssh:run "root@$vps" -- cat /opt/apps/myc-deploy/compose.yml </dev/null) ||
{ echo "no-compose"; return; }
echo "$compose_content" | grep backup >/dev/null 2>&1 ||
{ echo "no-backup"; return; }
}
[ "$SOURCED" ] && return 0
@ -340,4 +360,28 @@ cmdline.spec::cmd:vps-setup:run() {
}
cmdline.spec.gnu vps-check
cmdline.spec::cmd:vps-check:run() {
: :posarg: [VPS...] 'Target host to check'
VPS=($(printf "%s\n" "${VPS[@]}" | sort))
declare -A vps_done;
for vps in "${VPS[@]}"; do
[ "${vps_done[$vps]}" ] && {
warn "duplicate vps '$vps' provided. Ignoring."
continue
}
vps_done[$vps]=1
(
vps_check "$vps" 2>&1 | sed "s/^/$vps: /g"
[ "${PIPESTATUS[0]}" == 0 ]
) &
done
wait
}
cmdline::parse "$@"
Loading…
Cancel
Save