!69 fix 数据目录不为空,也安装成功了

From: @hengliue 
Reviewed-by: @dillon_chen 
Signed-off-by: @dillon_chen
This commit is contained in:
openeuler-ci-bot 2024-12-11 07:21:41 +00:00 committed by Gitee
commit fa47869315
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 61 additions and 34 deletions

View File

@ -13,7 +13,7 @@
Name: opengauss
Version: 6.0.0
Release: 18
Release: 19
Summary: openGauss is an open source relational database management system
License: MulanPSL-2.0 and MIT and BSD and zlib and TCL and Apache-2.0 and BSL-1.0
URL: https://gitee.com/opengauss/openGauss-server
@ -275,37 +275,49 @@ install -m 644 %{SOURCE28} %{buildroot}%{tmppath}/upgrade.sh
popd
%pre
# add opengauss user
/usr/sbin/groupadd -r opengauss >/dev/null 2>&1 || :
/usr/sbin/useradd -M -N -g opengauss -r -d %{datapath} -s /bin/bash -c "openGauss Server" opengauss >/dev/null 2>&1 || :
# for install step
# 1:install 2:upgrade
if [ $1 -gt 1 ]; then
echo "upgrade pre"
else
if [ $1 -eq 1 ]; then
echo "Preparing for install"
portinfo=$(lsof -i:%{port})
if [ "${portinfo}" != "" ]; then
echo "The port[%{port}] is occupied. Please use command 'lsof -i:%{port} to check it.'"
exit 1
fi
fi
if [ -d /var/lib/opengauss/data ]; then
if [ "`ls -A /var/lib/opengauss/data`" != "" ]; then
echo "Datanode dir(/var/lib/opengauss/data) is not empty."
echo "Please delete dir and reinstall opengauss."
exit 1
fi
process_id=$(ps -ef | grep /var/lib/opengauss/data | grep -v grep | awk '{print $2}')
if [ "$process_id" != "" ]; then
echo "A process of opengauss already exists. Use command (ps -ef | grep /var/lib/opengauss/data) to confirm."
echo "Please kill the process and reinstall opengauss."
exit 1
fi
fi
elif [ $1 -eq 2 ]; then
echo "Preparing for upgrade"
old_version=$(rpm -qi opengauss | grep -i version | awk -F':' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//')
if [ "$(printf '%s\n' "%{version}" "$old_version" | sort -V | head -n1)" == "$old_version" ]; then
echo "Error: New version (${version}) must be greater than the old version ($old_version)."
exit 1
fi
if [[ "${old_version}" == "2.1.0" && %{version} == "6.0.0" ]]; then
echo "The opengauss do not support upgrade from 2.1.0 to 6.0.0."
exit 1
fi
fi
%post
start_opengauss(){
process_id=$(ps -ef | grep /var/lib/opengauss/data | grep -v grep | awk '{print $2}')
if [ "$process_id" != "" ]; then
echo "A process of opengauss already exists. Use command (ps -ef | grep /var/lib/opengauss/data) to confirm."
echo "Please kill the process and reinstall opengauss."
exit 1
fi
if [ "`ls -A /var/lib/opengauss/data`" != "" ]; then
echo "Datanode dir(/var/lib/opengauss/data) is not empty."
echo "Please delete dir and reinstall opengauss."
exit 1
fi
result=$(su - opengauss -c "source ~/.bash_profile; gs_initdb -D /var/lib/opengauss/data -U opengauss --nodename=single_node")
if [ $? -ne 0 ]; then
echo "Init openGauss database failed."
@ -426,12 +438,18 @@ else
rm -rf /usr/local/opengauss
fi
mkdir -p /usr/local/opengauss
cp -rf /var/lib/opengauss/opengauss_upgrade/pkg_%{version}/* /usr/local/opengauss
upgrade_result=$(cat /var/lib/opengauss/opengauss_upgrade/tmp/upgrade_result.txt)
if [ $upgrade_result == "success" ]; then
echo "opengauss upgrade successfully"
cp -rf /var/lib/opengauss/opengauss_upgrade/pkg_%{version}/* /usr/local/opengauss
else:
echo "opengauss upgrade failed, rollback in progress"
cp -rf /var/lib/opengauss/opengauss_upgrade/bak/* /usr/local/opengauss
fi
chown -R opengauss:opengauss /usr/local/opengauss
chmod -R 755 /usr/local/opengauss
chmod -R 700 /var/lib/opengauss/data
systemctl restart opengauss.service
echo "opengauss upgrade successfully"
fi
@ -445,6 +463,9 @@ fi
%changelog
* Tue Dec 10 2024 liuheng <liuheng76@huawei.com> - 6.0.0-19
- Fix bugs: #IBAAVY
* Thu Dec 5 2024 xiaofan <xiaofan@iscas.ac.cn> - 6.0.0-18
- Support riscv64

View File

@ -17,10 +17,11 @@ version=6.0.0
GAUSS_BASE_PATH="/usr/local/opengauss"
GAUSS_UPGRADE_BASE_PATH="/var/lib/opengauss/opengauss_upgrade/pkg_${version}"
GAUSS_BACKUP_BASE_PATH="/var/lib/opengauss/opengauss_upgrade/bak"
GAUSS_TMP_PATH="${GAUSS_UPGRADE_BASE_PATH}/tmp"
GAUSS_LOG_FILE="${GAUSS_UPGRADE_BASE_PATH}/opengauss_upgrade.log"
GAUSS_TMP_PATH="/var/lib/opengauss/opengauss_upgrade/tmp"
GAUSS_LOG_FILE="/var/lib/opengauss/opengauss_upgrade/opengauss_upgrade.log"
new_opengauss_dir=/var/lib/opengauss/pkg_${version}
GAUSS_LISTEN_PORT=7654
GAUSS_UPGRADE_RESULT_FILE=${GAUSS_TMP_PATH}/upgrade_result.txt
function create_dir() {
rm -rf ${GAUSS_BACKUP_BASE_PATH}
@ -318,6 +319,7 @@ function prepare_sql_all() {
function pre_exec_sql() {
if exec_sql "$GAUSS_TMP_PATH"/temp_sql/temp_upgrade_maindb.sql maindb && exec_sql "$GAUSS_TMP_PATH"/temp_sql/temp_upgrade_otherdb.sql otherdb; then
debug "exec pre sql successfully"
return 0
else
log "exec pre sql failed"
return 1
@ -535,20 +537,21 @@ function delete_tmp_files() {
}
function add_pg_proc_index() {
add_index="start transaction; set isinplaceupgrade=on;
version=$(gaussdb -V)
if [[ ! $version =~ "V500R002C00" && ! $version =~ "2.1.0" ]]; then
return 0
fi
add_index_cmd="start transaction; set isinplaceupgrade=on;
ALTER INDEX pg_proc_proname_args_nsp_index unusable;
SET LOCAL inplace_upgrade_next_system_object_oids = IUO_CATALOG, false, true, 0, 0, 0, 9666;
CREATE INDEX pg_catalog.pg_proc_proname_all_args_nsp_index on pg_catalog.pg_proc USING BTREE(proname name_ops, pronamespace oid_ops, propackageid oid_ops);
SET LOCAL inplace_upgrade_next_system_object_oids = IUO_CATALOG, false, true, 0, 0, 0, 0;
commit;"
version=$(gaussdb -V)
if [[ $version =~ "V500R002C00" || $version =~ "2.1.0" ]]; then
sqlbegin="gsql -p $GAUSS_LISTEN_PORT -X -t -A "
result=$(${sqlbegin} -d postgres -c "${add_index}")
if [ $? -ne 0 ]; then
log "Exec sql to get databases failed."
return 1
fi
sqlbegin="gsql -p $GAUSS_LISTEN_PORT -X -t -A "
result=$(${sqlbegin} -d postgres -c "${add_index_cmd}")
if [ $? -ne 0 ]; then
log "Exec sql to get databases failed."
return 1
fi
}
@ -569,6 +572,7 @@ function upgrade_pre() {
pre_exec_sql
if [ $? -ne 0 ]; then
rollback_pre_sql
exit 1
fi
}
@ -607,7 +611,8 @@ function upgrade_post() {
debug "upgrade post sql successfully"
else
log "upgrade post sql failed"
return 1
rollback_post
exit 1
fi
}
@ -617,12 +622,12 @@ function upgrade_commit() {
die "set upgrade_mode to 0 failed" ${err_upgrade_commit}
fi
# 2.删除临时文件
delete_tmp_files
# delete_tmp_files
}
function cp_bak() {
cp -rf ${GAUSS_BASE_PATH}/* ${GAUSS_BACKUP_BASE_PATH}
rm -rf ${GAUSS_BASE_PATH}/*
# rm -rf ${GAUSS_BASE_PATH}/*
}
function cp_new() {
@ -635,6 +640,7 @@ function main() {
upgrade_post
upgrade_commit
stop_dbnode
echo "success" > $GAUSS_UPGRADE_RESULT_FILE
# cp_bak
# cp_new
# remove_path ${GAUSS_UPGRADE_BASE_PATH}/bin