#!/bin/bash #stop server if [ $(id -u) -ne 0 ]; then echo "ERROR:当前用户没有管理员权限,非管理员请用 sudo ./installer_linux.sh 命令执行" exit fi #加载宏定义,用来判断平台 for file in "/etc/profile.d/iscs6000.sh" \ "/etc/profile.d/iscs6000env.sh" \ "/etc/profile.d/rqeh6000.sh" \ "/etc/profile.d/rqeh6000env.sh"; do [ -f "$file" ] && source "$file" done #安装平台 centos 、openeuler OS_DEFINE="${RQEH6000_OS:-$ISCS6000_OS}" if [ -n "$OS_DEFINE" ]; then echo "INFO:安装操作系统平台:$OS_DEFINE" fi #当前的安装包运行目录 initfile=$(dirname "$(dirname "$(readlink -f "$0")")") #安装目录 INSTALL_DIR="/opt/EnergyHub" #debug or release SETUP_DEBUG_RELEASE=debug #开启服务 function start_service() { local service_name=$1 if sudo systemctl is-active --quiet "$service_name"; then echo "INFO:$service_name 服务已开启。" else if [ "kingbase" = "$service_name" ]; then chmod +x /opt/Kingbase/ES/V8/Scripts/root.sh /opt/Kingbase/ES/V8/Scripts/root.sh else sudo systemctl enable "$service_name" sudo systemctl start "$service_name" fi echo "INFO:$service_name 服务已开启。" fi } #关闭服务 function stop_service() { local service_name=$1 if sudo systemctl is-active --quiet "$service_name"; then sudo systemctl stop "$service_name" sudo systemctl disable "$service_name" echo "INFO:$service_name 服务已关闭。" else echo "INFO:$service_name 服务已关闭。" fi } #开启配置数据库服务 if [ "kylin10d" = "$OS_DEFINE" ]; then echo "INFO:kylin need to select db-service" valid_input=false while [ "$valid_input" = false ]; do echo "请选择切换的数据库服务名:" echo "1) kingbase" echo "2) mariadb" echo "3) 两者都开启" read -p "请输入数字选择(默认: 1): " choice case "$choice" in 1 | "") # 输入 1 或直接回车 DB_SERVICE_NAME="kingbase" valid_input=true ;; 2) DB_SERVICE_NAME="mariadb" valid_input=true ;; 3) DB_SERVICE_NAME="Both" valid_input=true ;; *) echo "无效选择,请重新输入!" ;; esac done echo "INFO: 选择的数据库服务为 ${DB_SERVICE_NAME}" case "$DB_SERVICE_NAME" in "kingbase") start_service "kingbase" stop_service "mariadb" ;; "mariadb") start_service "mariadb" stop_service "kingbase" ;; "Both") start_service "mariadb" start_service "kingbase" ;; esac fi #variable #script_path="$(cd "$(dirname "$0")" && pwd)" script_path="${INSTALL_DIR}/installer" echo "INFO:当前脚本执行目录: $script_path" if [ -d "$(dirname "$script_path")/product/${OS_DEFINE}_debug/" ]; then SETUP_DEBUG_RELEASE=debug else SETUP_DEBUG_RELEASE=release fi echo "INFO:安装版本:" $SETUP_DEBUG_RELEASE export BIN_DIR_VER=${OS_DEFINE}_${SETUP_DEBUG_RELEASE} #进行配置数据库初始化操作 $(dirname "$script_path")/product/$BIN_DIR_VER/db_installer echo "INFO: 切换完成。"