|
|
@ -841,4 +841,164 @@ cmdline.spec::cmd:recover-target:run() { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cmdline.spec.gnu odoo |
|
|
|
|
|
|
|
cmdline.spec::cmd:odoo:run() { |
|
|
|
: |
|
|
|
} |
|
|
|
|
|
|
|
cmdline.spec.gnu restart |
|
|
|
cmdline.spec:odoo:cmd:restart:run() { |
|
|
|
|
|
|
|
: :optval: --service,-s "The service (defaults to 'odoo')" |
|
|
|
|
|
|
|
local out odoo_service |
|
|
|
|
|
|
|
odoo_service="${opt_service:-odoo}" |
|
|
|
|
|
|
|
if ! out=$(docker restart "myc_${odoo_service}_1" 2>&1); then |
|
|
|
if [[ "$out" == *"no matching entries in passwd file" ]]; then |
|
|
|
warn "Catched docker bug. Restarting once more." |
|
|
|
if ! out=$(docker restart "myc_${odoo_service}_1"); then |
|
|
|
err "Can't restart container myc_${odoo_service}_1 (restarted twice)." |
|
|
|
echo " output:" >&2 |
|
|
|
echo "$out" | prefix " ${GRAY}|${NORMAL} " >&2 |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
else |
|
|
|
err "Couldn't restart container myc_${odoo_service}_1 (and no restart bug detected)." |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
fi |
|
|
|
info "Container myc_${odoo_service}_1 was ${DARKGREEN}successfully${NORMAL} restarted." |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cmdline.spec.gnu restore |
|
|
|
cmdline.spec:odoo:cmd:restore:run() { |
|
|
|
|
|
|
|
: :posarg: ZIP_DUMP_LOCATION 'Source odoo dump file to restore |
|
|
|
(can be a local file or an url)' |
|
|
|
|
|
|
|
: :optval: --service,-s "The service (defaults to 'odoo')" |
|
|
|
: :optval: --database,-d 'Target database (default if not specified)' |
|
|
|
|
|
|
|
local out |
|
|
|
|
|
|
|
odoo_service="${opt_service:-odoo}" |
|
|
|
|
|
|
|
if [[ "$ZIP_DUMP_LOCATION" == "http://"* ]]; then |
|
|
|
settmpdir ZIP_TMP_LOCATION |
|
|
|
tmp_location="$ZIP_TMP_LOCATION/dump.zip" |
|
|
|
curl -k -s -L "$ZIP_DUMP_LOCATION" > "$tmp_location" || { |
|
|
|
err "Couldn't get '$ZIP_DUMP_LOCATION'." |
|
|
|
exit 1 |
|
|
|
} |
|
|
|
if [[ "$(dd if="$tmp_location" count=2 bs=1 2>/dev/null)" != "PK" ]]; then |
|
|
|
err "Download doesn't seem to be a zip file." |
|
|
|
dd if="$tmp_location" count=1 bs=256 | hd | prefix " ${GRAY}|${NORMAL} " >&2 |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
info "Successfully downloaded '$ZIP_DUMP_LOCATION'" |
|
|
|
echo " in '$tmp_location'." >&2 |
|
|
|
ZIP_DUMP_LOCATION="$tmp_location" |
|
|
|
fi |
|
|
|
|
|
|
|
[ -e "$ZIP_DUMP_LOCATION" ] || { |
|
|
|
err "No file '$ZIP_DUMP_LOCATION' found." >&2 |
|
|
|
exit 1 |
|
|
|
} |
|
|
|
|
|
|
|
#cmdline.spec:odoo:cmd:restart:run --service "$odoo_service" || exit 1 |
|
|
|
|
|
|
|
msg_dbname=default |
|
|
|
[ -n "$opt_database" ] && msg_dbname="'$opt_database'" |
|
|
|
compose --no-hooks drop "$odoo_service" $opt_database || { |
|
|
|
err "Error dropping $msg_dbname database of service ${DARKYELLOW}$odoo_service${NORMAL}." |
|
|
|
exit 1 |
|
|
|
} |
|
|
|
compose --no-hooks load "$odoo_service" $opt_database < "$ZIP_DUMP_LOCATION" || { |
|
|
|
err "Error restoring service ${DARKYELLOW}$odoo_service${NORMAL} to $msg_dbname database." |
|
|
|
exit 1 |
|
|
|
} |
|
|
|
|
|
|
|
info "Successfully restored ${DARKYELLOW}$odoo_service${NORMAL} to $msg_dbname database." |
|
|
|
|
|
|
|
## Restart odoo, ensure there is no bugs lingering on it. |
|
|
|
cmdline.spec:odoo:cmd:restart:run --service "$odoo_service" || exit 1 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cmdline.spec.gnu dump |
|
|
|
cmdline.spec:odoo:cmd:dump:run() { |
|
|
|
|
|
|
|
: :posarg: DUMP_ZIPFILE 'Target path to store odoo dump zip file.' |
|
|
|
: :optval: --database,-d 'Target database (default if not specified)' |
|
|
|
: :optval: --service,-s "The service (defaults to 'odoo')" |
|
|
|
|
|
|
|
odoo_service="${opt_service:-odoo}" |
|
|
|
|
|
|
|
|
|
|
|
msg_dbname=default |
|
|
|
[ -n "$opt_database" ] && msg_dbname="'$opt_database'" |
|
|
|
compose --no-hooks save "$odoo_service" $opt_database > "$DUMP_ZIPFILE" || { |
|
|
|
err "Error dumping ${DARKYELLOW}$odoo_service${NORMAL}'s $msg_dbname database to '$DUMP_ZIPFILE'." |
|
|
|
exit 1 |
|
|
|
} |
|
|
|
|
|
|
|
info "Successfully dumped ${DARKYELLOW}$odoo_service${NORMAL}'s $msg_dbname database to '$DUMP_ZIPFILE'." |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cmdline.spec.gnu drop |
|
|
|
cmdline.spec:odoo:cmd:drop:run() { |
|
|
|
|
|
|
|
: :optval: --database,-d 'Target database (default if not specified)' |
|
|
|
: :optval: --service,-s "The service (defaults to 'odoo')" |
|
|
|
|
|
|
|
odoo_service="${opt_service:-odoo}" |
|
|
|
|
|
|
|
msg_dbname=default |
|
|
|
[ -n "$opt_database" ] && msg_dbname="'$opt_database'" |
|
|
|
compose --no-hooks drop "$odoo_service" $opt_database || { |
|
|
|
err "Error dropping ${DARKYELLOW}$odoo_service${NORMAL}'s $msg_dbname database." |
|
|
|
exit 1 |
|
|
|
} |
|
|
|
|
|
|
|
info "Successfully dropped ${DARKYELLOW}$odoo_service${NORMAL}'s $msg_dbname database." |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cmdline.spec.gnu set-cyclos-url |
|
|
|
cmdline.spec:odoo:cmd:set-cyclos-url:run() { |
|
|
|
|
|
|
|
: :optval: --database,-d "Target database ('odoo' if not specified)" |
|
|
|
: :optval: --service,-s "The cyclos service name (defaults to 'cyclos')" |
|
|
|
|
|
|
|
local URL |
|
|
|
|
|
|
|
dbname=${opt_database:-odoo} |
|
|
|
cyclos_service="${opt_service:-cyclos}" |
|
|
|
|
|
|
|
URL=$( |
|
|
|
set -o pipefail |
|
|
|
cat /var/lib/compose/relations/myc/${cyclos_service}-frontend/web-proxy/data | |
|
|
|
shyaml get-value url |
|
|
|
) || { |
|
|
|
err "Failed querying ${cyclos_service} to frontend relation to get url." |
|
|
|
exit 1 |
|
|
|
} |
|
|
|
|
|
|
|
echo "UPDATE res_company SET cyclos_server_url = '$URL' WHERE id=1;" | |
|
|
|
docker exec -i myc_postgres_1 psql -U postgres "$dbname" || { |
|
|
|
err "Failed to set cyclos url value in '$dbname' database." |
|
|
|
exit 1 |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cmdline::parse "$@" |