Browse Source

new: [vps] add ``mongo upgrade`` action

pull/4/head
Valentin Lab 1 year ago
parent
commit
807f060d1a
  1. 19
      README.org
  2. 139
      bin/vps

19
README.org

@ -957,6 +957,25 @@ un bon moyen de voir cela).
#+begin_src sh #+begin_src sh
vps nextcloud upgrade vps nextcloud upgrade
#+end_src #+end_src
*** mongo
**** Mise à jour en dernière version
Cette commande permet d'appliquer successivement les version de
mongo, elle modifie le =compose.yml=. Et installe la dernière
version disponible donnée par =docker-tags-fetch docker.0k.io/mongo=.
Étant donné que la commande est un peu nouvelle et la tâche assez
fastidieuse et risquée, ne pas hésiter à la lancer dans un =tmux= pour
être prêt à demander de l'aide. Également, lancer un =myc-update= avant.
Aussi, il est toujours bon de vérifier que le backup fonctionne et que
la version sur le serveur de backup est à jour (lancer =vps backup= est
un bon moyen de voir cela).
#+begin_src sh
vps mongo upgrade
#+end_src
*** onlyoffice *** onlyoffice
**** Troubleshooting **** Troubleshooting

139
bin/vps

@ -38,6 +38,41 @@ help=""
version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; } version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; }
read-0a-err() {
local ret="$1" eof="" idx=0 last=
read -r -- "${ret?}" <<<"0"
shift
while [ "$1" ]; do
last=$idx
read -r -- "$1" || {
## Put this last value in ${!ret}
eof="$1"
read -r -- "$ret" <<<"${!eof}"
break
}
((idx++))
shift
done
[ -z "$eof" ] || {
if [ "$last" != 0 ]; then
echo "Error: read-0a-err couldn't fill all value" >&2
read -r -- "$ret" <<<"127"
else
if [ -z "${!ret}" ]; then
echo "Error: last value is not a number, did you finish with an errorlevel ?" >&2
read -r -- "$ret" <<<"126"
fi
fi
false
}
}
p-0a-err() {
"$@"
echo -n "$?"
}
docker:running-container-projects() { docker:running-container-projects() {
:cache: scope=session :cache: scope=session
@ -2238,4 +2273,108 @@ host:sys:load_avg() {
printf "%s " "" "$(date +%s)" "$uptime" printf "%s " "" "$(date +%s)" "$uptime"
} }
cmdline.spec.gnu mongo
cmdline.spec::cmd:mongo:run() {
:
}
cmdline.spec.gnu upgrade
cmdline.spec:mongo:cmd:upgrade:run() {
: :posarg: [TARGET_VERSION] "Target version to migrate to"
: :optval: --service,-s "The mongo service name (defaults to 'mongo')"
: :optfla: --debug,-d "Display debugging information"
local URL
mongo_service="${opt_service:-mongo}"
available_actions=$(compose --get-available-actions) || exit 1
available_actionable_services=($(e "$available_actions" | yq 'keys().[]'))
if [[ " ${available_actionable_services[*]} " != *" $mongo_service "* ]]; then
err "Service '$mongo_service' was not found in current 'compose.yml'."
exit 1
fi
opts_compose=()
if [ -n "$opt_debug" ]; then
opts_compose+=("--debug")
else
opts_compose+=("-q")
fi
project_name=$(compose:project_name) || exit 1
containers="$(compose:service:containers "${project_name}" "${mongo_service}")" || exit 1
## XXXvlab: quick hack, to make more beautiful later
cron_container=$(compose:service:containers "${project_name}" "cron")
containers="$containers $cron_container"
docker stop "$cron_container" >/dev/null 2>&1 || true
before_version=
uptodate=
upgraded=
msgerr=()
while read-0a-err errlvl line; do
echo "$line"
rline=$(printf "%s" "$line" | sed_compat "s/$__color_sequence_regex//g")
case "$rline" in
"II Current mongo version: "*)
before_version="${rline#II Current mongo version: }"
;;
"II ${mongo_service} is already up-to-date.")
if [ -z "$before_version" ]; then
msgerr+=("expected a 'current version' line before the 'up-to-date' one.")
continue
fi
after_version="$before_version"
uptodate=1
;;
"II Successfully upgraded from ${before_version} to "*)
after_version="${rline#II Successfully upgraded from ${before_version} to }"
upgraded=1
;;
*)
:
;;
esac
done < <(
## -q to remove the display of ``compose`` related information
## like relation resolution.
## -c on the upgrade action to force color
ansi_color=yes p-0a-err compose -c "${opts_compose[@]}" upgrade "$mongo_service" --no-hint -c "$TARGET_VERSION"
)
if [ "$errlvl" != 0 ]; then
exit "$errlvl"
fi
if [ -n "$uptodate" ]; then
for container in "${containers[@]}"; do
[ -n "$container" ] || continue
Wrap -d "start ${DARKYELLOW}${mongo_service}${NORMAL}'s container" -- \
docker start "$container" || {
err "Failed to start container '$container'."
exit 1
}
done
exit 0
fi
if [ -z "$upgraded" ]; then
err "Unexpected output of 'upgrade' action with errorlevel 0 and without success"
exit 1
fi
desc="update \`compose.yml\` to set ${DARKYELLOW}$mongo_service${NORMAL}'s "
desc+="docker image to actual code version ${WHITE}${after_version}${NORMAL}"
Wrap -d "$desc" -- \
compose:file:value-change \
"${mongo_service}.docker-compose.image" \
"docker.0k.io/mongo:${after_version}-myc" || exit 1
echo "${WHITE}Launching final compose${NORMAL}"
compose up || exit 1
}
cmdline::parse "$@" cmdline::parse "$@"
Loading…
Cancel
Save