|
@ -165,7 +165,7 @@ ssh:run() { |
|
|
-o ControlMaster=auto -o ControlPersist=900 \ |
|
|
-o ControlMaster=auto -o ControlPersist=900 \ |
|
|
-o "StrictHostKeyChecking=no" \ |
|
|
-o "StrictHostKeyChecking=no" \ |
|
|
"$hostname" "${ssh_options[@]}" -- "${cmd[@]}" |
|
|
"$hostname" "${ssh_options[@]}" -- "${cmd[@]}" |
|
|
} 3>&1 1>&2 2>&3 | sed -r "s/^/$DARKCYAN$hostname$NORMAL $DARKRED\!$NORMAL /g" |
|
|
|
|
|
|
|
|
} 3>&1 1>&2 2>&3 ## | sed -r "s/^/$DARKCYAN$hostname$NORMAL $DARKRED\!$NORMAL /g" |
|
|
set_errlvl "${PIPESTATUS[0]}" |
|
|
set_errlvl "${PIPESTATUS[0]}" |
|
|
} 3>&1 1>&2 2>&3 |
|
|
} 3>&1 1>&2 2>&3 |
|
|
} |
|
|
} |
|
@ -195,25 +195,86 @@ is_ovh_hostname() { |
|
|
return 1 |
|
|
return 1 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
vps_check() { |
|
|
|
|
|
|
|
|
vps_connection_check() { |
|
|
local vps="$1" |
|
|
local vps="$1" |
|
|
ip=$(resolve "$vps") || |
|
|
ip=$(resolve "$vps") || |
|
|
{ echo "no-resolve"; return; } |
|
|
|
|
|
|
|
|
{ echo "${DARKRED}no-resolve${NORMAL}"; return 1; } |
|
|
|
|
|
|
|
|
ping -c 1 -w 1 "$ip" >/dev/null 2>&1 || |
|
|
|
|
|
{ echo "no-ping"; } |
|
|
|
|
|
is-port-open "$ip" "22" || |
|
|
|
|
|
{ echo "no-port-22-open"; return; } |
|
|
|
|
|
|
|
|
is-port-open "$ip" "22" </dev/null || |
|
|
|
|
|
{ echo "${DARKRED}no-port-22-open${NORMAL}"; return 1; } |
|
|
|
|
|
|
|
|
ssh:open -o ConnectTimeout=2 -o PreferredAuthentications=publickey \ |
|
|
ssh:open -o ConnectTimeout=2 -o PreferredAuthentications=publickey \ |
|
|
"root@$vps" >/dev/null 2>&1 || |
|
|
"root@$vps" >/dev/null 2>&1 || |
|
|
{ echo "no-ssh-root-access"; return; } |
|
|
|
|
|
|
|
|
{ echo "${DARKRED}no-ssh-root-access${NORMAL}"; return 1; } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
vps_check() { |
|
|
|
|
|
local vps="$1" |
|
|
|
|
|
vps_connection_check "$vps" </dev/null || return 1 |
|
|
|
|
|
if size=$( |
|
|
|
|
|
echo "df /srv -h | tail -n +2 | sed -r 's/ +/ /g' | cut -f 5 -d ' ' | cut -f 1 -d %" | |
|
|
|
|
|
ssh:run "root@$vps" -- bash); then |
|
|
|
|
|
if [ "$size" -gt "90" ]; then |
|
|
|
|
|
echo "${DARKRED}above-90%-disk-usage${NORMAL}" |
|
|
|
|
|
elif [ "$size" -gt "75" ]; then |
|
|
|
|
|
echo "${DARKYELLOW}above-75%-disk-usage${NORMAL}" |
|
|
|
|
|
fi |
|
|
|
|
|
else |
|
|
|
|
|
echo "${DARKRED}no-size${NORMAL}" |
|
|
|
|
|
fi </dev/null |
|
|
compose_content=$(ssh:run "root@$vps" -- cat /opt/apps/myc-deploy/compose.yml </dev/null) || |
|
|
compose_content=$(ssh:run "root@$vps" -- cat /opt/apps/myc-deploy/compose.yml </dev/null) || |
|
|
{ echo "no-compose"; return; } |
|
|
|
|
|
|
|
|
{ echo "${DARKRED}no-compose${NORMAL}"; return; } |
|
|
echo "$compose_content" | grep backup >/dev/null 2>&1 || |
|
|
echo "$compose_content" | grep backup >/dev/null 2>&1 || |
|
|
{ echo "no-backup"; return; } |
|
|
|
|
|
|
|
|
{ echo "${DARKRED}no-backup${NORMAL}"; return; } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vps_udpate() { |
|
|
|
|
|
local vps="$1" |
|
|
|
|
|
vps_connection_check "$vps" || return 1 |
|
|
|
|
|
ssh:run "root@$vps" -- myc-update </dev/null |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vps_bash() { |
|
|
|
|
|
local vps="$1" |
|
|
|
|
|
vps_connection_check "$vps" </dev/null || return 1 |
|
|
|
|
|
ssh:run "root@$vps" -- bash |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
vps_mux() { |
|
|
|
|
|
local fn="$1" vps_done VPS max_size vps |
|
|
|
|
|
shift |
|
|
|
|
|
VPS=($(printf "%s\n" "$@" | sort)) |
|
|
|
|
|
max_size=0 |
|
|
|
|
|
declare -A vps_done; |
|
|
|
|
|
new_vps=() |
|
|
|
|
|
for name in "${VPS[@]}"; do |
|
|
|
|
|
[ -n "${vps_done[$name]}" ] && { |
|
|
|
|
|
warn "duplicate vps '$name' provided. Ignoring." |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
vps_done["$name"]=1 |
|
|
|
|
|
new_vps+=("$name") |
|
|
|
|
|
size_name="${#name}" |
|
|
|
|
|
[ "$max_size" -lt "${size_name}" ] && |
|
|
|
|
|
max_size="$size_name" |
|
|
|
|
|
done |
|
|
|
|
|
code=$(cat) |
|
|
|
|
|
for vps in "${new_vps[@]}"; do |
|
|
|
|
|
label=$(printf "%-${max_size}s" "$vps") |
|
|
|
|
|
( |
|
|
|
|
|
{ |
|
|
|
|
|
{ |
|
|
|
|
|
echo "$code" | "$fn" "$vps" |
|
|
|
|
|
} 3>&1 1>&2 2>&3 | sed -r "s/^/$DARKCYAN$label$NORMAL $DARKRED\!$NORMAL /g" |
|
|
|
|
|
set_errlvl "${PIPESTATUS[0]}" |
|
|
|
|
|
} 3>&1 1>&2 2>&3 | sed -r "s/^/$DARKCYAN$label$NORMAL $DARKGRAY\|$NORMAL /g" |
|
|
|
|
|
set_errlvl "${PIPESTATUS[0]}" |
|
|
|
|
|
) & |
|
|
|
|
|
done |
|
|
|
|
|
wait |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ "$SOURCED" ] && return 0 |
|
|
[ "$SOURCED" ] && return 0 |
|
@ -367,21 +428,42 @@ cmdline.spec::cmd:vps-check:run() { |
|
|
|
|
|
|
|
|
: :posarg: [VPS...] 'Target host to check' |
|
|
: :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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "" | |
|
|
|
|
|
vps_mux vps_check "${VPS[@]}" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmdline.spec.gnu vps-update |
|
|
|
|
|
|
|
|
|
|
|
cmdline.spec::cmd:vps-update:run() { |
|
|
|
|
|
|
|
|
|
|
|
: :posarg: [VPS...] 'Target host to check' |
|
|
|
|
|
|
|
|
|
|
|
echo "" | |
|
|
|
|
|
vps_mux vps_update "${VPS[@]}" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmdline.spec.gnu vps-mux |
|
|
|
|
|
cmdline.spec::cmd:vps-mux:run() { |
|
|
|
|
|
|
|
|
|
|
|
: :posarg: [VPS...] 'Target host to check' |
|
|
|
|
|
|
|
|
|
|
|
cat | vps_mux vps_bash "${VPS[@]}" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmdline.spec.gnu vps-space |
|
|
|
|
|
cmdline.spec::cmd:vps-space:run() { |
|
|
|
|
|
|
|
|
|
|
|
: :posarg: [VPS...] 'Target host to check' |
|
|
|
|
|
|
|
|
|
|
|
echo "df /srv -h | tail -n +2 | sed -r 's/ +/ /g' | cut -f 2-5 -d ' '" | |
|
|
|
|
|
vps_mux vps_bash "${VPS[@]}" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmdline::parse "$@" |
|
|
cmdline::parse "$@" |