From f2c708cff295ebaba2c0c4c7873269fd9812b2f0 Mon Sep 17 00:00:00 2001 From: Roman Demidov Date: Wed, 14 Apr 2021 17:10:38 +0300 Subject: [PATCH] Reset database tables on update (#351) * Reset database tables on update * Add changes * Add changes * Add changes * Add changes * Add changes * Add changes --- run-document-server.sh | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/run-document-server.sh b/run-document-server.sh index ff05fd4..2457304 100755 --- a/run-document-server.sh +++ b/run-document-server.sh @@ -11,16 +11,32 @@ shopt -s globstar APP_DIR="/var/www/${COMPANY_NAME}/documentserver" DATA_DIR="/var/www/${COMPANY_NAME}/Data" +PRIVATE_DATA_DIR="${DATA_DIR}/.private" +DS_RELEASE_DATE="${PRIVATE_DATA_DIR}/ds_release_date" LOG_DIR="/var/log/${COMPANY_NAME}" DS_LOG_DIR="${LOG_DIR}/documentserver" LIB_DIR="/var/lib/${COMPANY_NAME}" DS_LIB_DIR="${LIB_DIR}/documentserver" CONF_DIR="/etc/${COMPANY_NAME}/documentserver" +IS_UPGRADE="false" ONLYOFFICE_DATA_CONTAINER=${ONLYOFFICE_DATA_CONTAINER:-false} ONLYOFFICE_DATA_CONTAINER_HOST=${ONLYOFFICE_DATA_CONTAINER_HOST:-localhost} ONLYOFFICE_DATA_CONTAINER_PORT=80 +RELEASE_DATE="$(stat -c="%y" ${APP_DIR}/server/DocService/docservice | sed -r 's/=([0-9]+)-([0-9]+)-([0-9]+) ([0-9:.+ ]+)/\1-\2-\3/')"; +if [ -f ${DS_RELEASE_DATE} ]; then + PREV_RELEASE_DATE=$(head -n 1 ${DS_RELEASE_DATE}) +else + PREV_RELEASE_DATE="0" +fi + +if [ "${RELEASE_DATE}" != "${PREV_RELEASE_DATE}" ]; then + if [ ${ONLYOFFICE_DATA_CONTAINER} != "true" ]; then + IS_UPGRADE="true"; + fi +fi + SSL_CERTIFICATES_DIR="${DATA_DIR}/certs" if [[ -z $SSL_CERTIFICATE_PATH ]] && [[ -f ${SSL_CERTIFICATES_DIR}/onlyoffice.crt ]]; then SSL_CERTIFICATE_PATH=${SSL_CERTIFICATES_DIR}/onlyoffice.crt @@ -327,6 +343,36 @@ create_db_tbl() { esac } +upgrade_db_tbl() { + case $DB_TYPE in + "postgres") + upgrade_postgresql_tbl + ;; + "mariadb"|"mysql") + upgrade_mysql_tbl + ;; + esac +} + +upgrade_postgresql_tbl() { + if [ -n "$DB_PWD" ]; then + export PGPASSWORD=$DB_PWD + fi + + PSQL="psql -q -h$DB_HOST -p$DB_PORT -d$DB_NAME -U$DB_USER -w" + + $PSQL -f "$APP_DIR/server/schema/postgresql/removetbl.sql" + $PSQL -f "$APP_DIR/server/schema/postgresql/createdb.sql" +} + +upgrade_mysql_tbl() { + CONNECTION_PARAMS="-h$DB_HOST -P$DB_PORT -u$DB_USER -p$DB_PWD -w" + MYSQL="mysql -q $CONNECTION_PARAMS" + + $MYSQL $DB_NAME < "$APP_DIR/server/schema/mysql/removetbl.sql" >/dev/null 2>&1 + $MYSQL $DB_NAME < "$APP_DIR/server/schema/mysql/createdb.sql" >/dev/null 2>&1 +} + create_postgresql_tbl() { if [ -n "$DB_PWD" ]; then export PGPASSWORD=$DB_PWD @@ -423,6 +469,11 @@ update_logrotate_settings(){ sed 's|\(^su\b\).*|\1 root root|' -i /etc/logrotate.conf } +update_release_date(){ + mkdir -p ${PRIVATE_DATA_DIR} + echo ${RELEASE_DATE} > ${DS_RELEASE_DATE} +} + # create base folders for i in converter docservice spellchecker metrics; do mkdir -p "${DS_LOG_DIR}/$i" @@ -527,6 +578,11 @@ if [ ${ONLYOFFICE_DATA_CONTAINER} != "true" ]; then waiting_for_redis fi + if [ "${IS_UPGRADE}" = "true" ]; then + upgrade_db_tbl + update_release_date + fi + update_nginx_settings update_supervisor_settings