chore: initial commit
This commit is contained in:
55
installer/shells/init-directories.sh
Normal file
55
installer/shells/init-directories.sh
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# 日志函数
|
||||
log() {
|
||||
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
|
||||
}
|
||||
|
||||
# 需要确保存在的目录
|
||||
DIRS=(
|
||||
"/opt/cordys/data/mysql"
|
||||
"/opt/cordys/conf/mysql"
|
||||
"/opt/cordys/logs/cordys-crm"
|
||||
"/opt/cordys/logs/mcp-server"
|
||||
"/opt/cordys/data/files"
|
||||
"/opt/cordys/data/redis"
|
||||
"/opt/cordys/conf/redis"
|
||||
)
|
||||
|
||||
log "开始检查并创建必要目录..."
|
||||
for d in "${DIRS[@]}"; do
|
||||
if [ ! -d "$d" ]; then
|
||||
log "创建目录: $d"
|
||||
mkdir -p "$d"
|
||||
else
|
||||
log "目录已存在: $d"
|
||||
fi
|
||||
done
|
||||
|
||||
# 通用配置文件复制函数
|
||||
copy_conf() {
|
||||
local source="$1"
|
||||
local target="$2"
|
||||
local name="$3"
|
||||
|
||||
if [ ! -f "$target" ]; then
|
||||
log "$name 配置文件不存在,复制默认配置: $source -> $target"
|
||||
cp "$source" "$target"
|
||||
else
|
||||
log "$name 配置文件已存在: $target"
|
||||
fi
|
||||
}
|
||||
|
||||
# 应用配置文件
|
||||
copy_conf "/installer/conf/cordys-crm.properties" "/opt/cordys/conf/cordys-crm.properties" "Cordys CRM"
|
||||
copy_conf "/installer/conf/mysql/my.cnf" "/opt/cordys/conf/mysql/my.cnf" "MySQL"
|
||||
copy_conf "/installer/conf/redis/redis.conf" "/opt/cordys/conf/redis/redis.conf" "Redis"
|
||||
|
||||
# 仅在目录存在时再设置权限
|
||||
if [ -d "/opt/cordys" ]; then
|
||||
log "设置目录权限: /opt/cordys"
|
||||
chmod -R 777 /opt/cordys
|
||||
fi
|
||||
|
||||
log "目录初始化完成。"
|
||||
107
installer/shells/start-all.sh
Normal file
107
installer/shells/start-all.sh
Normal file
@@ -0,0 +1,107 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# ------------------------------
|
||||
# 日志函数
|
||||
# ------------------------------
|
||||
log_info() {
|
||||
echo "[INFO] $(date '+%Y-%m-%d %H:%M:%S') - $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo "[ERROR] $(date '+%Y-%m-%d %H:%M:%S') - $1" >&2
|
||||
}
|
||||
|
||||
# ------------------------------
|
||||
# 启动内置服务函数
|
||||
# ------------------------------
|
||||
start_mysql() {
|
||||
log_info "启动 MySQL 服务..."
|
||||
/shells/start-mysql.sh &
|
||||
|
||||
if /shells/wait-for-it.sh 127.0.0.1:3306 --timeout=120 --strict; then
|
||||
log_info "MySQL 服务已就绪"
|
||||
return 0
|
||||
else
|
||||
log_error "MySQL 服务启动失败或超时"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
start_redis() {
|
||||
log_info "启动 Redis 服务..."
|
||||
/shells/start-redis.sh &
|
||||
|
||||
if /shells/wait-for-it.sh 127.0.0.1:6379 --timeout=120 --strict; then
|
||||
log_info "Redis 服务已就绪"
|
||||
return 0
|
||||
else
|
||||
log_error "Redis 服务启动失败或超时"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
start_mcp_after_cordys() {
|
||||
mcpEmbeddedEnabled=$(get_property "mcp.embedded.enabled")
|
||||
if [[ "${mcpEmbeddedEnabled}" == "true" ]]; then
|
||||
log_info "启动内置 MCP 服务 ..."
|
||||
/shells/wait-for-it.sh 127.0.0.1:8081 --timeout=120 --strict
|
||||
|
||||
log_info "Cordys CRM 已就绪,启动 MCP..."
|
||||
sh /shells/start-mcp.sh &
|
||||
/shells/wait-for-it.sh 127.0.0.1:8082 --timeout=120 --strict
|
||||
log_info "MCP 已就绪"
|
||||
else
|
||||
log_info "使用外部 MCP 服务"
|
||||
fi
|
||||
}
|
||||
|
||||
# ------------------------------
|
||||
# 获取配置函数
|
||||
# ------------------------------
|
||||
get_property() {
|
||||
local key=$1
|
||||
grep "^${key}=" /opt/cordys/conf/cordys-crm.properties | cut -d'=' -f2 | tr -d '[:space:]'
|
||||
}
|
||||
|
||||
# ------------------------------
|
||||
# 主函数
|
||||
# ------------------------------
|
||||
main() {
|
||||
log_info "开始启动 Cordys CRM 环境..."
|
||||
|
||||
# 初始化目录
|
||||
bash /shells/init-directories.sh
|
||||
|
||||
# ------------------------------
|
||||
# MySQL
|
||||
# ------------------------------
|
||||
mysqlEmbeddedEnabled=$(get_property "mysql.embedded.enabled")
|
||||
if [[ "${mysqlEmbeddedEnabled}" == "true" ]]; then
|
||||
log_info "启动内置 MySQL ..."
|
||||
start_mysql
|
||||
else
|
||||
log_info "使用外部 MySQL 服务"
|
||||
fi
|
||||
|
||||
# ------------------------------
|
||||
# Redis
|
||||
# ------------------------------
|
||||
redisEmbeddedEnabled=$(get_property "redis.embedded.enabled")
|
||||
if [[ "${redisEmbeddedEnabled}" == "true" ]]; then
|
||||
log_info "启动内置 Redis ..."
|
||||
start_redis
|
||||
else
|
||||
log_info "使用外部 Redis 服务"
|
||||
fi
|
||||
|
||||
start_mcp_after_cordys &
|
||||
sh /shells/start-cordys.sh
|
||||
|
||||
log_info "Cordys CRM 环境启动完成!"
|
||||
}
|
||||
|
||||
# ------------------------------
|
||||
# 执行主函数
|
||||
# ------------------------------
|
||||
main
|
||||
9
installer/shells/start-cordys.sh
Normal file
9
installer/shells/start-cordys.sh
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
bash /shells/init-directories.sh
|
||||
|
||||
export JAVA_CLASSPATH=/app:/app/lib/*
|
||||
export JAVA_MAIN_CLASS=cn.cordys.Application
|
||||
export CRM_VERSION=`cat /tmp/CRM_VERSION`
|
||||
|
||||
sh /deployments/run-java.sh
|
||||
14
installer/shells/start-mcp.sh
Executable file
14
installer/shells/start-mcp.sh
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
bash /shells/init-directories.sh
|
||||
|
||||
JAR_PATH="/app/mcp/cordys-crm-mcp-server.jar"
|
||||
|
||||
if [ ! -f "$JAR_PATH" ]; then
|
||||
echo "MCP JAR not found at $JAR_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Starting MCP Server..."
|
||||
exec java -jar $JAVA_OPTIONS "$JAR_PATH"
|
||||
55
installer/shells/start-mysql.sh
Executable file
55
installer/shells/start-mysql.sh
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/bin/sh
|
||||
bash /shells/init-directories.sh
|
||||
|
||||
cp -rf /opt/cordys/conf/mysql/my.cnf /etc/my.cnf.d/mariadb-server.cnf
|
||||
|
||||
chmod 644 /etc/mysql/conf.d/my.cnf
|
||||
|
||||
if [ ! -d "/run/mysqld" ]; then
|
||||
mkdir -p /run/mysqld
|
||||
fi
|
||||
|
||||
if [ -d /app/mysql ]; then
|
||||
echo "[i] MySQL directory already present, skipping creation"
|
||||
else
|
||||
echo "[i] MySQL data directory not found, creating initial DBs"
|
||||
|
||||
mysql_install_db --user=root > /dev/null
|
||||
|
||||
if [ "$MYSQL_ROOT_PASSWORD" = "" ]; then
|
||||
MYSQL_ROOT_PASSWORD=CordysCRM@mysql
|
||||
echo "[i] MySQL root Password: $MYSQL_ROOT_PASSWORD"
|
||||
fi
|
||||
|
||||
MYSQL_DATABASE=${MYSQL_DATABASE:-"cordys-crm"}
|
||||
MYSQL_USER=${MYSQL_USER:-""}
|
||||
MYSQL_PASSWORD=${MYSQL_PASSWORD:-""}
|
||||
|
||||
tfile=`mktemp`
|
||||
if [ ! -f "$tfile" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
cat << EOF > $tfile
|
||||
USE mysql;
|
||||
FLUSH PRIVILEGES;
|
||||
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY "$MYSQL_ROOT_PASSWORD" WITH GRANT OPTION;
|
||||
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY "$MYSQL_ROOT_PASSWORD" WITH GRANT OPTION;
|
||||
EOF
|
||||
|
||||
if [ "$MYSQL_DATABASE" != "" ]; then
|
||||
echo "[i] Creating database: $MYSQL_DATABASE"
|
||||
echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;" >> $tfile
|
||||
|
||||
if [ "$MYSQL_USER" != "" ]; then
|
||||
echo "[i] Creating user: $MYSQL_USER with password $MYSQL_PASSWORD"
|
||||
echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* to '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD';" >> $tfile
|
||||
fi
|
||||
fi
|
||||
|
||||
/usr/bin/mysqld --user=root --bootstrap --verbose=0 < $tfile
|
||||
rm -f $tfile
|
||||
fi
|
||||
|
||||
|
||||
exec /usr/bin/mysqld --user=root --console
|
||||
19
installer/shells/start-redis.sh
Executable file
19
installer/shells/start-redis.sh
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
set -e # 遇到错误立即退出
|
||||
|
||||
# 日志函数
|
||||
log() {
|
||||
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
|
||||
}
|
||||
|
||||
bash /shells/init-directories.sh
|
||||
|
||||
# 检查 Redis 密码
|
||||
if [ -z "${REDIS_PASSWORD}" ]; then
|
||||
log "警告:REDIS_PASSWORD 环境变量未设置,使用默认密码 CordysCRM@redis"
|
||||
REDIS_PASSWORD="CordysCRM@redis"
|
||||
fi
|
||||
|
||||
# 启动 Redis 服务器
|
||||
log "启动 Redis 服务器..."
|
||||
redis-server /opt/cordys/conf/redis/redis.conf --requirepass "${REDIS_PASSWORD}"
|
||||
182
installer/shells/wait-for-it.sh
Executable file
182
installer/shells/wait-for-it.sh
Executable file
@@ -0,0 +1,182 @@
|
||||
#!/usr/bin/env bash
|
||||
# Use this script to test if a given TCP host/port are available
|
||||
|
||||
WAITFORIT_cmdname=${0##*/}
|
||||
|
||||
echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
|
||||
|
||||
usage()
|
||||
{
|
||||
cat << USAGE >&2
|
||||
Usage:
|
||||
$WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args]
|
||||
-h HOST | --host=HOST Host or IP under test
|
||||
-p PORT | --port=PORT TCP port under test
|
||||
Alternatively, you specify the host and port as host:port
|
||||
-s | --strict Only execute subcommand if the test succeeds
|
||||
-q | --quiet Don't output any status messages
|
||||
-t TIMEOUT | --timeout=TIMEOUT
|
||||
Timeout in seconds, zero for no timeout
|
||||
-- COMMAND ARGS Execute command with args after the test finishes
|
||||
USAGE
|
||||
exit 1
|
||||
}
|
||||
|
||||
wait_for()
|
||||
{
|
||||
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
|
||||
echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
|
||||
else
|
||||
echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout"
|
||||
fi
|
||||
WAITFORIT_start_ts=$(date +%s)
|
||||
while :
|
||||
do
|
||||
if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
|
||||
nc -z $WAITFORIT_HOST $WAITFORIT_PORT
|
||||
WAITFORIT_result=$?
|
||||
else
|
||||
(echo -n > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
|
||||
WAITFORIT_result=$?
|
||||
fi
|
||||
if [[ $WAITFORIT_result -eq 0 ]]; then
|
||||
WAITFORIT_end_ts=$(date +%s)
|
||||
echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
return $WAITFORIT_result
|
||||
}
|
||||
|
||||
wait_for_wrapper()
|
||||
{
|
||||
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
|
||||
if [[ $WAITFORIT_QUIET -eq 1 ]]; then
|
||||
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
|
||||
else
|
||||
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
|
||||
fi
|
||||
WAITFORIT_PID=$!
|
||||
trap "kill -INT -$WAITFORIT_PID" INT
|
||||
wait $WAITFORIT_PID
|
||||
WAITFORIT_RESULT=$?
|
||||
if [[ $WAITFORIT_RESULT -ne 0 ]]; then
|
||||
echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
|
||||
fi
|
||||
return $WAITFORIT_RESULT
|
||||
}
|
||||
|
||||
# process arguments
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
case "$1" in
|
||||
*:* )
|
||||
WAITFORIT_hostport=(${1//:/ })
|
||||
WAITFORIT_HOST=${WAITFORIT_hostport[0]}
|
||||
WAITFORIT_PORT=${WAITFORIT_hostport[1]}
|
||||
shift 1
|
||||
;;
|
||||
--child)
|
||||
WAITFORIT_CHILD=1
|
||||
shift 1
|
||||
;;
|
||||
-q | --quiet)
|
||||
WAITFORIT_QUIET=1
|
||||
shift 1
|
||||
;;
|
||||
-s | --strict)
|
||||
WAITFORIT_STRICT=1
|
||||
shift 1
|
||||
;;
|
||||
-h)
|
||||
WAITFORIT_HOST="$2"
|
||||
if [[ $WAITFORIT_HOST == "" ]]; then break; fi
|
||||
shift 2
|
||||
;;
|
||||
--host=*)
|
||||
WAITFORIT_HOST="${1#*=}"
|
||||
shift 1
|
||||
;;
|
||||
-p)
|
||||
WAITFORIT_PORT="$2"
|
||||
if [[ $WAITFORIT_PORT == "" ]]; then break; fi
|
||||
shift 2
|
||||
;;
|
||||
--port=*)
|
||||
WAITFORIT_PORT="${1#*=}"
|
||||
shift 1
|
||||
;;
|
||||
-t)
|
||||
WAITFORIT_TIMEOUT="$2"
|
||||
if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi
|
||||
shift 2
|
||||
;;
|
||||
--timeout=*)
|
||||
WAITFORIT_TIMEOUT="${1#*=}"
|
||||
shift 1
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
WAITFORIT_CLI=("$@")
|
||||
break
|
||||
;;
|
||||
--help)
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
echoerr "Unknown argument: $1"
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then
|
||||
echoerr "Error: you need to provide a host and port to test."
|
||||
usage
|
||||
fi
|
||||
|
||||
WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
|
||||
WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
|
||||
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
|
||||
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
|
||||
|
||||
# Check to see if timeout is from busybox?
|
||||
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
|
||||
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
|
||||
|
||||
WAITFORIT_BUSYTIMEFLAG=""
|
||||
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
|
||||
WAITFORIT_ISBUSY=1
|
||||
# Check if busybox timeout uses -t flag
|
||||
# (recent Alpine versions don't support -t anymore)
|
||||
if timeout &>/dev/stdout | grep -q -e '-t '; then
|
||||
WAITFORIT_BUSYTIMEFLAG="-t"
|
||||
fi
|
||||
else
|
||||
WAITFORIT_ISBUSY=0
|
||||
fi
|
||||
|
||||
if [[ $WAITFORIT_CHILD -gt 0 ]]; then
|
||||
wait_for
|
||||
WAITFORIT_RESULT=$?
|
||||
exit $WAITFORIT_RESULT
|
||||
else
|
||||
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
|
||||
wait_for_wrapper
|
||||
WAITFORIT_RESULT=$?
|
||||
else
|
||||
wait_for
|
||||
WAITFORIT_RESULT=$?
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $WAITFORIT_CLI != "" ]]; then
|
||||
if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then
|
||||
echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
|
||||
exit $WAITFORIT_RESULT
|
||||
fi
|
||||
exec "${WAITFORIT_CLI[@]}"
|
||||
else
|
||||
exit $WAITFORIT_RESULT
|
||||
fi
|
||||
Reference in New Issue
Block a user