mirror of
https://github.com/wekan/wekan.git
synced 2025-12-16 23:40:13 +01:00
Use only MongoDB 7 at Snap.
Thanks to xet7 !
This commit is contained in:
parent
aa402d652d
commit
79e83e33ec
6 changed files with 54 additions and 1014 deletions
|
|
@ -1,8 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# MongoDB Control Script
|
# MongoDB Control Script
|
||||||
# Handles MongoDB server startup with automatic version detection and switching
|
# Starts MongoDB 7.x server only
|
||||||
# Supports MongoDB versions 3-8 with automatic binary selection
|
|
||||||
|
|
||||||
# get wekan/mongo settings
|
# get wekan/mongo settings
|
||||||
echo "Reading snap settings..."
|
echo "Reading snap settings..."
|
||||||
|
|
@ -26,189 +25,13 @@ if [ "true" == "${DISABLE_MONGODB}" ]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# MongoDB Version Detection and Auto-Switching System
|
|
||||||
# Detects MongoDB server version from connection attempts and switches to correct binary
|
|
||||||
|
|
||||||
# MongoDB binary paths for different versions
|
|
||||||
# Note: Currently only versions 3 and 7 are available in the snap package
|
|
||||||
# Versions 4, 5, 6, 8 would need to be added to the snap package
|
|
||||||
MONGO3_BIN="/snap/${SNAP_NAME}/current/migratemongo/bin"
|
|
||||||
MONGO7_BIN="/snap/${SNAP_NAME}/current/bin"
|
|
||||||
MONGO3_LIB="/snap/${SNAP_NAME}/current/migratemongo/lib"
|
|
||||||
MONGO7_LIB="/snap/${SNAP_NAME}/current/usr/lib"
|
|
||||||
|
|
||||||
# Future paths for additional versions (when added to snap package)
|
|
||||||
MONGO4_BIN="/snap/${SNAP_NAME}/current/mongodb4/bin"
|
|
||||||
MONGO5_BIN="/snap/${SNAP_NAME}/current/mongodb5/bin"
|
|
||||||
MONGO6_BIN="/snap/${SNAP_NAME}/current/mongodb6/bin"
|
|
||||||
MONGO8_BIN="/snap/${SNAP_NAME}/current/mongodb8/bin"
|
|
||||||
|
|
||||||
# Version detection log
|
|
||||||
VERSION_DETECTION_LOG="${SNAP_COMMON}/mongodb-version-detection.log"
|
|
||||||
|
|
||||||
# Log version detection events
|
|
||||||
log_version_detection() {
|
|
||||||
echo "$(date): $1" >> "$VERSION_DETECTION_LOG"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Detect MongoDB server version by attempting connection
|
|
||||||
detect_mongodb_version() {
|
|
||||||
local mongo_url="${MONGO_URL:-mongodb://127.0.0.1:27017/wekan}"
|
|
||||||
local detected_version=""
|
|
||||||
|
|
||||||
log_version_detection "Starting MongoDB version detection for: $mongo_url"
|
|
||||||
|
|
||||||
# Try to connect with MongoDB 7 first (latest available)
|
|
||||||
log_version_detection "Attempting connection with MongoDB 7 binary"
|
|
||||||
if timeout 10s /snap/${SNAP_NAME}/current/bin/mongosh --quiet --eval "db.runCommand({buildInfo: 1}).version" "$mongo_url" 2>/dev/null | grep -q "7\."; then
|
|
||||||
detected_version="7"
|
|
||||||
log_version_detection "Detected MongoDB 7.x server"
|
|
||||||
elif timeout 10s /snap/${SNAP_NAME}/current/bin/mongosh --quiet --eval "db.runCommand({buildInfo: 1}).version" "$mongo_url" 2>&1 | grep -q "protocol version\|wire protocol"; then
|
|
||||||
# Check for wire protocol errors that indicate older version
|
|
||||||
local error_output=$(timeout 10s /snap/${SNAP_NAME}/current/bin/mongosh --quiet --eval "db.runCommand({buildInfo: 1}).version" "$mongo_url" 2>&1)
|
|
||||||
if echo "$error_output" | grep -q "protocol version 0\|wire protocol version 0"; then
|
|
||||||
detected_version="3"
|
|
||||||
log_version_detection "Detected MongoDB 3.x server (wire protocol 0)"
|
|
||||||
elif echo "$error_output" | grep -q "protocol version 1\|wire protocol version 1"; then
|
|
||||||
detected_version="3"
|
|
||||||
log_version_detection "Detected MongoDB 3.x server (wire protocol 1)"
|
|
||||||
elif echo "$error_output" | grep -q "protocol version 2\|wire protocol version 2"; then
|
|
||||||
detected_version="3"
|
|
||||||
log_version_detection "Detected MongoDB 3.x server (wire protocol 2)"
|
|
||||||
elif echo "$error_output" | grep -q "protocol version 3\|wire protocol version 3"; then
|
|
||||||
detected_version="3"
|
|
||||||
log_version_detection "Detected MongoDB 3.x server (wire protocol 3)"
|
|
||||||
elif echo "$error_output" | grep -q "protocol version 4\|wire protocol version 4"; then
|
|
||||||
detected_version="4"
|
|
||||||
log_version_detection "Detected MongoDB 4.x server (wire protocol 4)"
|
|
||||||
elif echo "$error_output" | grep -q "protocol version 5\|wire protocol version 5"; then
|
|
||||||
detected_version="5"
|
|
||||||
log_version_detection "Detected MongoDB 5.x server (wire protocol 5)"
|
|
||||||
elif echo "$error_output" | grep -q "protocol version 6\|wire protocol version 6"; then
|
|
||||||
detected_version="6"
|
|
||||||
log_version_detection "Detected MongoDB 6.x server (wire protocol 6)"
|
|
||||||
elif echo "$error_output" | grep -q "protocol version 7\|wire protocol version 7"; then
|
|
||||||
detected_version="7"
|
|
||||||
log_version_detection "Detected MongoDB 7.x server (wire protocol 7)"
|
|
||||||
elif echo "$error_output" | grep -q "protocol version 8\|wire protocol version 8"; then
|
|
||||||
detected_version="8"
|
|
||||||
log_version_detection "Detected MongoDB 8.x server (wire protocol 8)"
|
|
||||||
else
|
|
||||||
log_version_detection "Unknown wire protocol error: $error_output"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
log_version_detection "No MongoDB server running or connection failed"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$detected_version"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Switch to appropriate MongoDB binary based on detected version
|
|
||||||
switch_mongodb_binary() {
|
|
||||||
local version="$1"
|
|
||||||
|
|
||||||
case "$version" in
|
|
||||||
"3")
|
|
||||||
if [ -f "/snap/${SNAP_NAME}/current/migratemongo/bin/mongod" ]; then
|
|
||||||
log_version_detection "Switching to MongoDB 3.x binary"
|
|
||||||
export PATH="${MONGO3_BIN}:${PATH}"
|
|
||||||
export LD_LIBRARY_PATH="${MONGO3_LIB}:${MONGO3_LIB}/x86_64-linux-gnu:${LD_LIBRARY_PATH}"
|
|
||||||
echo "3" > "${SNAP_COMMON}/mongodb-active-version"
|
|
||||||
else
|
|
||||||
log_version_detection "MongoDB 3.x binary not found, using default MongoDB 7.x"
|
|
||||||
switch_mongodb_binary "7"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
"4")
|
|
||||||
if [ -f "/snap/${SNAP_NAME}/current/mongodb4/bin/mongod" ]; then
|
|
||||||
log_version_detection "Switching to MongoDB 4.x binary"
|
|
||||||
export PATH="${MONGO4_BIN}:${PATH}"
|
|
||||||
echo "4" > "${SNAP_COMMON}/mongodb-active-version"
|
|
||||||
else
|
|
||||||
log_version_detection "MongoDB 4.x binary not found, using default MongoDB 7.x"
|
|
||||||
switch_mongodb_binary "7"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
"5")
|
|
||||||
if [ -f "/snap/${SNAP_NAME}/current/mongodb5/bin/mongod" ]; then
|
|
||||||
log_version_detection "Switching to MongoDB 5.x binary"
|
|
||||||
export PATH="${MONGO5_BIN}:${PATH}"
|
|
||||||
echo "5" > "${SNAP_COMMON}/mongodb-active-version"
|
|
||||||
else
|
|
||||||
log_version_detection "MongoDB 5.x binary not found, using default MongoDB 7.x"
|
|
||||||
switch_mongodb_binary "7"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
"6")
|
|
||||||
if [ -f "/snap/${SNAP_NAME}/current/mongodb6/bin/mongod" ]; then
|
|
||||||
log_version_detection "Switching to MongoDB 6.x binary"
|
|
||||||
export PATH="${MONGO6_BIN}:${PATH}"
|
|
||||||
echo "6" > "${SNAP_COMMON}/mongodb-active-version"
|
|
||||||
else
|
|
||||||
log_version_detection "MongoDB 6.x binary not found, using default MongoDB 7.x"
|
|
||||||
switch_mongodb_binary "7"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
"7"|"")
|
|
||||||
log_version_detection "Using MongoDB 7.x binary (default)"
|
|
||||||
export PATH="${MONGO7_BIN}:${PATH}"
|
|
||||||
export LD_LIBRARY_PATH="${MONGO7_LIB}:${LD_LIBRARY_PATH}"
|
|
||||||
echo "7" > "${SNAP_COMMON}/mongodb-active-version"
|
|
||||||
;;
|
|
||||||
"8")
|
|
||||||
if [ -f "/snap/${SNAP_NAME}/current/mongodb8/bin/mongod" ]; then
|
|
||||||
log_version_detection "Switching to MongoDB 8.x binary"
|
|
||||||
export PATH="${MONGO8_BIN}:${PATH}"
|
|
||||||
echo "8" > "${SNAP_COMMON}/mongodb-active-version"
|
|
||||||
else
|
|
||||||
log_version_detection "MongoDB 8.x binary not found, using default MongoDB 7.x"
|
|
||||||
switch_mongodb_binary "7"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
log_version_detection "Unknown version $version, using default MongoDB 7.x"
|
|
||||||
export PATH="${MONGO7_BIN}:${PATH}"
|
|
||||||
export LD_LIBRARY_PATH="${MONGO7_LIB}:${LD_LIBRARY_PATH}"
|
|
||||||
echo "7" > "${SNAP_COMMON}/mongodb-active-version"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
# Main version detection and switching logic
|
|
||||||
setup_mongodb_version() {
|
|
||||||
# Check if we have a cached version
|
|
||||||
if [ -f "${SNAP_COMMON}/mongodb-active-version" ]; then
|
|
||||||
local cached_version=$(cat "${SNAP_COMMON}/mongodb-active-version")
|
|
||||||
log_version_detection "Using cached MongoDB version: $cached_version"
|
|
||||||
switch_mongodb_binary "$cached_version"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Detect version and switch
|
|
||||||
local detected_version=$(detect_mongodb_version)
|
|
||||||
if [ -n "$detected_version" ]; then
|
|
||||||
switch_mongodb_binary "$detected_version"
|
|
||||||
else
|
|
||||||
# Default to MongoDB 7 if detection fails
|
|
||||||
log_version_detection "Version detection failed, using default MongoDB 7.x"
|
|
||||||
switch_mongodb_binary "7"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Run version detection and setup
|
|
||||||
setup_mongodb_version
|
|
||||||
|
|
||||||
# make sure we have set minimum env variables for locale
|
# make sure we have set minimum env variables for locale
|
||||||
if [ -z "${LANG}" ]; then
|
if [ -z "${LANG}" ]; then
|
||||||
export LANG=en_US.UTF-8
|
export LANG=en_US.UTF-8
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export LC_ALL=C
|
export LC_ALL=C
|
||||||
# If CPU does not support AVX, use Qemu that supports AVX.
|
export PATH=/snap/${SNAP_NAME}/current/usr/bin:/snap/${SNAP_NAME}/current/bin:${PATH}
|
||||||
# Migratemongo is at https://github.com/wekan/migratemongo
|
|
||||||
# and at directory /snap/${SNAP_NAME}/current/migratemongo/avx
|
|
||||||
# is bash scripts like mongod, mongosh check avx support and use Qemu if needed.
|
|
||||||
export PATH=/snap/${SNAP_NAME}/current/migratemongo/avx:/snap/${SNAP_NAME}/current/usr/bin:/snap/${SNAP_NAME}/current/bin:${PATH}
|
|
||||||
export LD_LIBRARY_PATH=/snap/${SNAP_NAME}/current/lib:/snap/${SNAP_NAME}/current/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}
|
export LD_LIBRARY_PATH=/snap/${SNAP_NAME}/current/lib:/snap/${SNAP_NAME}/current/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}
|
||||||
|
|
||||||
# If temporary settings log exists, delete it
|
# If temporary settings log exists, delete it
|
||||||
|
|
@ -254,60 +77,57 @@ echo " MONGODB_PORT: ${MONGODB_PORT:-27017}"
|
||||||
echo " MONGODB_BIND_UNIX_SOCKET: ${MONGODB_BIND_UNIX_SOCKET:-not set}"
|
echo " MONGODB_BIND_UNIX_SOCKET: ${MONGODB_BIND_UNIX_SOCKET:-not set}"
|
||||||
echo " BIND_OPTIONS: ${BIND_OPTIONS}"
|
echo " BIND_OPTIONS: ${BIND_OPTIONS}"
|
||||||
|
|
||||||
# Start MongoDB with appropriate version
|
# Check if MongoDB is already running
|
||||||
echo "Starting MongoDB with detected version..."
|
check_mongodb_running() {
|
||||||
log_version_detection "Starting MongoDB server"
|
local port="${MONGODB_PORT:-27017}"
|
||||||
|
local bind_ip="${MONGODB_BIND_IP:-127.0.0.1}"
|
||||||
|
|
||||||
|
# Check if MongoDB is already running on the configured port
|
||||||
|
if netstat -tuln 2>/dev/null | grep -q ":${port} "; then
|
||||||
|
echo "MongoDB is already running on port ${port}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Alternative check using lsof if netstat is not available
|
||||||
|
if command -v lsof >/dev/null 2>&1; then
|
||||||
|
if lsof -i ":${port}" >/dev/null 2>&1; then
|
||||||
|
echo "MongoDB is already running on port ${port} (detected via lsof)"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if there's a PID file and the process is still running
|
||||||
|
if [ -f "${SNAP_COMMON}/mongodb.pid" ]; then
|
||||||
|
local pid=$(cat "${SNAP_COMMON}/mongodb.pid" 2>/dev/null)
|
||||||
|
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
|
||||||
|
echo "MongoDB is already running (PID: $pid)"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
# Remove stale PID file
|
||||||
|
rm -f "${SNAP_COMMON}/mongodb.pid"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
# Get the active version
|
# Cleanup function to remove PID file on exit
|
||||||
ACTIVE_VERSION=$(cat "${SNAP_COMMON}/mongodb-active-version" 2>/dev/null || echo "7")
|
cleanup() {
|
||||||
|
rm -f "${SNAP_COMMON}/mongodb.pid"
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
case "$ACTIVE_VERSION" in
|
# Check if MongoDB is already running
|
||||||
"3")
|
if check_mongodb_running; then
|
||||||
echo "Starting MongoDB 3.x server..."
|
echo "MongoDB is already running. Exiting to prevent multiple instances."
|
||||||
log_version_detection "Starting MongoDB 3.x server"
|
exit 0
|
||||||
exec /snap/${SNAP_NAME}/current/migratemongo/bin/mongod \
|
fi
|
||||||
--dbpath="$MONGO_DATA_DIR" \
|
|
||||||
--logpath="$MONGO_LOG_FILE" \
|
# Start MongoDB 7.x server
|
||||||
--logappend $BIND_OPTIONS
|
echo "Starting MongoDB 7.x server..."
|
||||||
;;
|
# Create PID file
|
||||||
"4")
|
echo $$ > "${SNAP_COMMON}/mongodb.pid"
|
||||||
echo "Starting MongoDB 4.x server..."
|
exec /snap/${SNAP_NAME}/current/bin/mongod \
|
||||||
log_version_detection "Starting MongoDB 4.x server"
|
--dbpath="$MONGO_DATA_DIR" \
|
||||||
exec /snap/${SNAP_NAME}/current/mongodb4/bin/mongod \
|
--logpath="$MONGO_LOG_FILE" \
|
||||||
--dbpath="$MONGO_DATA_DIR" \
|
--logappend $BIND_OPTIONS
|
||||||
--logpath="$MONGO_LOG_FILE" \
|
|
||||||
--logappend $BIND_OPTIONS
|
|
||||||
;;
|
|
||||||
"5")
|
|
||||||
echo "Starting MongoDB 5.x server..."
|
|
||||||
log_version_detection "Starting MongoDB 5.x server"
|
|
||||||
exec /snap/${SNAP_NAME}/current/mongodb5/bin/mongod \
|
|
||||||
--dbpath="$MONGO_DATA_DIR" \
|
|
||||||
--logpath="$MONGO_LOG_FILE" \
|
|
||||||
--logappend $BIND_OPTIONS
|
|
||||||
;;
|
|
||||||
"6")
|
|
||||||
echo "Starting MongoDB 6.x server..."
|
|
||||||
log_version_detection "Starting MongoDB 6.x server"
|
|
||||||
exec /snap/${SNAP_NAME}/current/mongodb6/bin/mongod \
|
|
||||||
--dbpath="$MONGO_DATA_DIR" \
|
|
||||||
--logpath="$MONGO_LOG_FILE" \
|
|
||||||
--logappend $BIND_OPTIONS
|
|
||||||
;;
|
|
||||||
"7"|*)
|
|
||||||
echo "Starting MongoDB 7.x server..."
|
|
||||||
log_version_detection "Starting MongoDB 7.x server"
|
|
||||||
exec /snap/${SNAP_NAME}/current/bin/mongod \
|
|
||||||
--dbpath="$MONGO_DATA_DIR" \
|
|
||||||
--logpath="$MONGO_LOG_FILE" \
|
|
||||||
--logappend $BIND_OPTIONS
|
|
||||||
;;
|
|
||||||
"8")
|
|
||||||
echo "Starting MongoDB 8.x server..."
|
|
||||||
log_version_detection "Starting MongoDB 8.x server"
|
|
||||||
exec /snap/${SNAP_NAME}/current/mongodb8/bin/mongod \
|
|
||||||
--dbpath="$MONGO_DATA_DIR" \
|
|
||||||
--logpath="$MONGO_LOG_FILE" \
|
|
||||||
--logappend $BIND_OPTIONS
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
@ -1,177 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# MongoDB Control Script
|
|
||||||
# Handles MongoDB server startup with automatic version detection and switching
|
|
||||||
|
|
||||||
# get wekan/mongo settings
|
|
||||||
source $SNAP/bin/wekan-read-settings
|
|
||||||
|
|
||||||
if [ "true" == "${DISABLE_MONGODB}" ]; then
|
|
||||||
echo "mongodb is disabled. Stop service"
|
|
||||||
snapctl stop --disable ${SNAP_NAME}.mongodb
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# MongoDB Version Detection and Auto-Switching System
|
|
||||||
# Detects MongoDB server version from connection attempts and switches to correct binary
|
|
||||||
|
|
||||||
# MongoDB binary paths for different versions
|
|
||||||
MONGO3_BIN="/snap/${SNAP_NAME}/current/migratemongo/bin"
|
|
||||||
MONGO7_BIN="/snap/${SNAP_NAME}/current/bin"
|
|
||||||
MONGO3_LIB="/snap/${SNAP_NAME}/current/migratemongo/lib"
|
|
||||||
MONGO7_LIB="/snap/${SNAP_NAME}/current/usr/lib"
|
|
||||||
|
|
||||||
# Version detection log
|
|
||||||
VERSION_DETECTION_LOG="${SNAP_COMMON}/mongodb-version-detection.log"
|
|
||||||
|
|
||||||
# Log version detection events
|
|
||||||
log_version_detection() {
|
|
||||||
echo "$(date): $1" >> "$VERSION_DETECTION_LOG"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Detect MongoDB server version by attempting connection
|
|
||||||
detect_mongodb_version() {
|
|
||||||
local mongo_url="${MONGO_URL:-mongodb://127.0.0.1:27017/wekan}"
|
|
||||||
local detected_version=""
|
|
||||||
|
|
||||||
log_version_detection "Starting MongoDB version detection for: $mongo_url"
|
|
||||||
|
|
||||||
# Try to connect with MongoDB 7 first (latest)
|
|
||||||
log_version_detection "Attempting connection with MongoDB 7 binary"
|
|
||||||
if timeout 10s /snap/${SNAP_NAME}/current/bin/mongosh --quiet --eval "db.runCommand({buildInfo: 1}).version" "$mongo_url" 2>/dev/null | grep -q "7\."; then
|
|
||||||
detected_version="7"
|
|
||||||
log_version_detection "Detected MongoDB 7.x server"
|
|
||||||
elif timeout 10s /snap/${SNAP_NAME}/current/bin/mongosh --quiet --eval "db.runCommand({buildInfo: 1}).version" "$mongo_url" 2>&1 | grep -q "protocol version\|wire protocol"; then
|
|
||||||
# Check for wire protocol errors that indicate older version
|
|
||||||
local error_output=$(timeout 10s /snap/${SNAP_NAME}/current/bin/mongosh --quiet --eval "db.runCommand({buildInfo: 1}).version" "$mongo_url" 2>&1)
|
|
||||||
if echo "$error_output" | grep -q "protocol version 0\|wire protocol version 0"; then
|
|
||||||
detected_version="3"
|
|
||||||
log_version_detection "Detected MongoDB 3.x server (wire protocol 0)"
|
|
||||||
elif echo "$error_output" | grep -q "protocol version 1\|wire protocol version 1"; then
|
|
||||||
detected_version="3"
|
|
||||||
log_version_detection "Detected MongoDB 3.x server (wire protocol 1)"
|
|
||||||
elif echo "$error_output" | grep -q "protocol version 2\|wire protocol version 2"; then
|
|
||||||
detected_version="3"
|
|
||||||
log_version_detection "Detected MongoDB 3.x server (wire protocol 2)"
|
|
||||||
elif echo "$error_output" | grep -q "protocol version 3\|wire protocol version 3"; then
|
|
||||||
detected_version="3"
|
|
||||||
log_version_detection "Detected MongoDB 3.x server (wire protocol 3)"
|
|
||||||
else
|
|
||||||
log_version_detection "Unknown wire protocol error: $error_output"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
log_version_detection "No MongoDB server running or connection failed"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$detected_version"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Switch to appropriate MongoDB binary based on detected version
|
|
||||||
switch_mongodb_binary() {
|
|
||||||
local version="$1"
|
|
||||||
|
|
||||||
case "$version" in
|
|
||||||
"3")
|
|
||||||
log_version_detection "Switching to MongoDB 3.x binary"
|
|
||||||
export PATH="${MONGO3_BIN}:${PATH}"
|
|
||||||
export LD_LIBRARY_PATH="${MONGO3_LIB}:${MONGO3_LIB}/x86_64-linux-gnu:${LD_LIBRARY_PATH}"
|
|
||||||
echo "3" > "${SNAP_COMMON}/mongodb-active-version"
|
|
||||||
;;
|
|
||||||
"7"|"")
|
|
||||||
log_version_detection "Using MongoDB 7.x binary (default)"
|
|
||||||
export PATH="${MONGO7_BIN}:${PATH}"
|
|
||||||
export LD_LIBRARY_PATH="${MONGO7_LIB}:${LD_LIBRARY_PATH}"
|
|
||||||
echo "7" > "${SNAP_COMMON}/mongodb-active-version"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
log_version_detection "Unknown version $version, using default MongoDB 7.x"
|
|
||||||
export PATH="${MONGO7_BIN}:${PATH}"
|
|
||||||
export LD_LIBRARY_PATH="${MONGO7_LIB}:${LD_LIBRARY_PATH}"
|
|
||||||
echo "7" > "${SNAP_COMMON}/mongodb-active-version"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
# Main version detection and switching logic
|
|
||||||
setup_mongodb_version() {
|
|
||||||
# Check if we have a cached version
|
|
||||||
if [ -f "${SNAP_COMMON}/mongodb-active-version" ]; then
|
|
||||||
local cached_version=$(cat "${SNAP_COMMON}/mongodb-active-version")
|
|
||||||
log_version_detection "Using cached MongoDB version: $cached_version"
|
|
||||||
switch_mongodb_binary "$cached_version"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Detect version and switch
|
|
||||||
local detected_version=$(detect_mongodb_version)
|
|
||||||
if [ -n "$detected_version" ]; then
|
|
||||||
switch_mongodb_binary "$detected_version"
|
|
||||||
else
|
|
||||||
# Default to MongoDB 7 if detection fails
|
|
||||||
log_version_detection "Version detection failed, using default MongoDB 7.x"
|
|
||||||
switch_mongodb_binary "7"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Run version detection and setup
|
|
||||||
setup_mongodb_version
|
|
||||||
|
|
||||||
# make sure we have set minimum env variables for locale
|
|
||||||
if [ -z "${LANG}" ]; then
|
|
||||||
export LANG=en_US.UTF-8
|
|
||||||
fi
|
|
||||||
|
|
||||||
export LC_ALL=C
|
|
||||||
# If CPU does not support AVX, use Qemu that supports AVX.
|
|
||||||
# Migratemongo is at https://github.com/wekan/migratemongo
|
|
||||||
# and at directory /snap/${SNAP_NAME}/current/migratemongo/avx
|
|
||||||
# is bash scripts like mongod, mongosh check avx support and use Qemu if needed.
|
|
||||||
export PATH=/snap/${SNAP_NAME}/current/migratemongo/avx:/snap/${SNAP_NAME}/current/usr/bin:/snap/${SNAP_NAME}/current/bin:${PATH}
|
|
||||||
export LD_LIBRARY_PATH=/snap/${SNAP_NAME}/current/lib:/snap/${SNAP_NAME}/current/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}
|
|
||||||
|
|
||||||
# If temporary settings log exists, delete it
|
|
||||||
if [ -f ${SNAP_COMMON}/settings.log ]; then
|
|
||||||
rm ${SNAP_COMMON}/settings.log
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Set MongoDB log destination to snapcommon for log file detection
|
|
||||||
export MONGO_LOG_DESTINATION="snapcommon"
|
|
||||||
|
|
||||||
# Set MongoDB data directory
|
|
||||||
export MONGO_DATA_DIR="${SNAP_COMMON}/wekan"
|
|
||||||
|
|
||||||
# Create MongoDB data directory if it doesn't exist
|
|
||||||
if [ ! -d "$MONGO_DATA_DIR" ]; then
|
|
||||||
mkdir -p "$MONGO_DATA_DIR"
|
|
||||||
chmod 755 "$MONGO_DATA_DIR"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Set MongoDB log file path
|
|
||||||
export MONGO_LOG_FILE="${SNAP_COMMON}/mongodb.log"
|
|
||||||
|
|
||||||
# Start MongoDB with appropriate version
|
|
||||||
echo "Starting MongoDB with detected version..."
|
|
||||||
log_version_detection "Starting MongoDB server"
|
|
||||||
|
|
||||||
# Get the active version
|
|
||||||
ACTIVE_VERSION=$(cat "${SNAP_COMMON}/mongodb-active-version" 2>/dev/null || echo "7")
|
|
||||||
|
|
||||||
if [ "$ACTIVE_VERSION" = "3" ]; then
|
|
||||||
echo "Starting MongoDB 3.x server..."
|
|
||||||
log_version_detection "Starting MongoDB 3.x server"
|
|
||||||
exec /snap/${SNAP_NAME}/current/migratemongo/bin/mongod \
|
|
||||||
--dbpath="$MONGO_DATA_DIR" \
|
|
||||||
--logpath="$MONGO_LOG_FILE" \
|
|
||||||
--logappend \
|
|
||||||
--bind_ip=127.0.0.1 \
|
|
||||||
--port=27017
|
|
||||||
else
|
|
||||||
echo "Starting MongoDB 7.x server..."
|
|
||||||
log_version_detection "Starting MongoDB 7.x server"
|
|
||||||
exec /snap/${SNAP_NAME}/current/bin/mongod \
|
|
||||||
--dbpath="$MONGO_DATA_DIR" \
|
|
||||||
--logpath="$MONGO_LOG_FILE" \
|
|
||||||
--logappend \
|
|
||||||
--bind_ip=127.0.0.1 \
|
|
||||||
--port=27017
|
|
||||||
fi
|
|
||||||
|
|
@ -1,281 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# MongoDB Control Script
|
|
||||||
# Handles MongoDB server startup with automatic version detection and switching
|
|
||||||
|
|
||||||
# get wekan/mongo settings
|
|
||||||
source $SNAP/bin/wekan-read-settings
|
|
||||||
|
|
||||||
if [ "true" == "${DISABLE_MONGODB}" ]; then
|
|
||||||
echo "mongodb is disabled. Stop service"
|
|
||||||
snapctl stop --disable ${SNAP_NAME}.mongodb
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if migration is needed
|
|
||||||
check_migration_needed() {
|
|
||||||
if [ -f "$MIGRATION_STATUS" ]; then
|
|
||||||
local status=$(jq -r '.status' "$MIGRATION_STATUS" 2>/dev/null || echo "unknown")
|
|
||||||
if [ "$status" = "completed" ]; then
|
|
||||||
return 1
|
|
||||||
elif [ "$status" = "running" ]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if we have MongoDB 3 data
|
|
||||||
if [ -d "${SNAP_COMMON}/wekan" ] && [ ! -f "${SNAP_COMMON}/mongodb-version-7" ]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Handle migration - only if MIGRATE_MONGODB=true
|
|
||||||
handle_migration() {
|
|
||||||
echo "MongoDB migration needed, starting migration process..."
|
|
||||||
|
|
||||||
# Stop Wekan (meteor) process before migration
|
|
||||||
echo "Stopping Wekan (meteor) process for migration..."
|
|
||||||
snapctl stop --disable ${SNAP_NAME}.wekan || true
|
|
||||||
snapctl stop --disable ${SNAP_NAME} || true
|
|
||||||
|
|
||||||
# Wait a moment for processes to stop
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# Kill any remaining meteor/node processes
|
|
||||||
pkill -f "node.*main.js" || true
|
|
||||||
pkill -f "meteor" || true
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
# Start migration web interface in background
|
|
||||||
$SNAP/bin/mongodb-migration-web &
|
|
||||||
local web_pid=$!
|
|
||||||
echo "$web_pid" > "${SNAP_COMMON}/migration-web.pid"
|
|
||||||
|
|
||||||
# Run migration
|
|
||||||
if $SNAP/bin/mongodb-migrate; then
|
|
||||||
echo "MongoDB migration completed successfully"
|
|
||||||
# Kill migration web interface
|
|
||||||
if [ -f "${SNAP_COMMON}/migration-web.pid" ]; then
|
|
||||||
local web_pid=$(cat "${SNAP_COMMON}/migration-web.pid")
|
|
||||||
kill "$web_pid" 2>/dev/null || true
|
|
||||||
rm -f "${SNAP_COMMON}/migration-web.pid"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Clean up temporary Node.js server file
|
|
||||||
rm -f "${SNAP_COMMON}/migration-web-server.js"
|
|
||||||
|
|
||||||
echo "Migration completed. Wekan will be restarted automatically."
|
|
||||||
else
|
|
||||||
echo "MongoDB migration failed"
|
|
||||||
# Kill migration web interface
|
|
||||||
if [ -f "${SNAP_COMMON}/migration-web.pid" ]; then
|
|
||||||
local web_pid=$(cat "${SNAP_COMMON}/migration-web.pid")
|
|
||||||
kill "$web_pid" 2>/dev/null || true
|
|
||||||
rm -f "${SNAP_COMMON}/migration-web.pid"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Clean up temporary Node.js server file
|
|
||||||
rm -f "${SNAP_COMMON}/migration-web-server.js"
|
|
||||||
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check if revert is requested
|
|
||||||
if [ -f "$REVERT_FILE" ]; then
|
|
||||||
echo "Revert requested, stopping Wekan and MongoDB, then reverting migration..."
|
|
||||||
|
|
||||||
# Stop Wekan (meteor) process before revert
|
|
||||||
echo "Stopping Wekan (meteor) process for revert..."
|
|
||||||
snapctl stop --disable ${SNAP_NAME}.wekan || true
|
|
||||||
snapctl stop --disable ${SNAP_NAME} || true
|
|
||||||
|
|
||||||
# Wait a moment for processes to stop
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# Kill any remaining meteor/node processes
|
|
||||||
pkill -f "node.*main.js" || true
|
|
||||||
pkill -f "meteor" || true
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
# Stop MongoDB
|
|
||||||
snapctl stop --disable ${SNAP_NAME}.mongodb
|
|
||||||
|
|
||||||
# Run migration (which will handle revert)
|
|
||||||
$SNAP/bin/mongodb-migrate
|
|
||||||
exit $?
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if migration is needed - only if MIGRATE_MONGODB=true
|
|
||||||
if [ "$MIGRATE_MONGODB" = "true" ]; then
|
|
||||||
if check_migration_needed; then
|
|
||||||
handle_migration
|
|
||||||
else
|
|
||||||
echo "MIGRATE_MONGODB=true but no migration needed"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "MIGRATE_MONGODB not set to 'true' - skipping migration check"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# make sure we have set minimum env variables for locale
|
|
||||||
if [ -z "${LANG}" ]; then
|
|
||||||
export LANG=en_US.UTF-8
|
|
||||||
fi
|
|
||||||
|
|
||||||
export LC_ALL=C
|
|
||||||
# If CPU does not support AVX, use Qemu that supports AVX.
|
|
||||||
# Migratemongo is at https://github.com/wekan/migratemongo
|
|
||||||
# and at directory /snap/${SNAP_NAME}/current/migratemongo/avx
|
|
||||||
# is bash scripts like mongod, mongosh check avx support and use Qemu if needed.
|
|
||||||
export PATH=/snap/${SNAP_NAME}/current/migratemongo/avx:/snap/${SNAP_NAME}/current/usr/bin:/snap/${SNAP_NAME}/current/bin:${PATH}
|
|
||||||
export LD_LIBRARY_PATH=/snap/${SNAP_NAME}/current/lib:/snap/${SNAP_NAME}/current/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}
|
|
||||||
|
|
||||||
# If temporary settings log exists, delete it
|
|
||||||
if [ -f ${SNAP_COMMON}/settings.log ]; then
|
|
||||||
rm ${SNAP_COMMON}/settings.log
|
|
||||||
fi
|
|
||||||
|
|
||||||
#if test -f "$SNAP_COMMON/01-migrate-mongo3-to-mongo5.txt"; then
|
|
||||||
# touch "$SNAP_COMMON/01-migrate-mongo3-to-mongo5.txt"
|
|
||||||
# # Stop MongoDB
|
|
||||||
# touch "$SNAP_COMMON/02-disable-mongo.txt"
|
|
||||||
# snapctl stop --disable ${SNAP_NAME}.mongodb
|
|
||||||
# touch "$SNAP_COMMON/03-eval-stop-mongo.txt"
|
|
||||||
# mongo wekan --eval "db.getSiblingDB('admin').shutdownServer()" $BIND_OPTIONS
|
|
||||||
# # Start MongoDB 4.4
|
|
||||||
# touch "$SNAP_COMMON/04-start-mongo44.txt"
|
|
||||||
# $SNAP/mongo44bin/mongod --dbpath $SNAP_COMMON --logpath $SNAP_COMMON/02_mongodb_log_while_migrate.txt --logappend --journal $MONGO_URL --quiet
|
|
||||||
# # Wait MongoDB 4.4 to start
|
|
||||||
# touch "$SNAP_COMMON/05-wait-2s-mongo44-start.txt"
|
|
||||||
# sleep 2s
|
|
||||||
# # Dump Old MongoDB 3.x database
|
|
||||||
# touch "$SNAP_COMMON/06-dump-database.txt"
|
|
||||||
# (cd $SNAP_COMMON && mongodump --port ${MONGODB_PORT})
|
|
||||||
# # Stop MongoDB 4.4
|
|
||||||
# touch "$SNAP_COMMON/07-stop-mongo44.txt"
|
|
||||||
# $SNAP/mongo44bin/mongo wekan --eval "db.getSiblingDB('admin').shutdownServer()" $BIND_OPTIONS
|
|
||||||
# # Wait MongoDB 4.4 to stop
|
|
||||||
# touch "$SNAP_COMMON/08-wait-2s-mongo44-stop.txt"
|
|
||||||
# sleep 2s
|
|
||||||
# # Start MongoDB 5
|
|
||||||
# touch "$SNAP_COMMON/09-start-mongo5.txt"
|
|
||||||
# mongod --dbpath $SNAP_COMMON --logpath $SNAP_COMMON/10_mongodb_log_while_migrate.txt --logappend --journal $MONGO_URL --quiet
|
|
||||||
# # Restore database
|
|
||||||
# touch "$SNAP_COMMON/11-mongorestore-to-mongo5.txt"
|
|
||||||
# (cd $SNAP_COMMON && mongorestore --port ${MONGODB_PORT})
|
|
||||||
# # Wait 5s
|
|
||||||
# touch "$SNAP_COMMON/12-wait-5s-after-restore.txt"
|
|
||||||
# sleep 5s
|
|
||||||
# # Shutdown mongodb
|
|
||||||
# touch "$SNAP_COMMON/13-shutdown-mongodb.txt"
|
|
||||||
# mongo wekan --eval "db.getSiblingDB('admin').shutdownServer()" $BIND_OPTIONS
|
|
||||||
# touch "$SNAP_COMMON/14-wait-5s-after-mongo5-shutdown.txt"
|
|
||||||
# sleep 5s
|
|
||||||
# # Enable MongoDB 5
|
|
||||||
# touch "$SNAP_COMMON/15-enable-mongo-5.txt"
|
|
||||||
# snapctl start --enable ${SNAP_NAME}.mongodb
|
|
||||||
#fi
|
|
||||||
# When starting MongoDB, if logfile exist, delete it, because now uses syslog instead of logfile,
|
|
||||||
# because syslog usually already has log rotation.
|
|
||||||
# https://github.com/wekan/wekan-snap/issues/92
|
|
||||||
#if test -f "$SNAP_COMMON/mongodb.log"; then
|
|
||||||
# rm -f "$SNAP_COMMON/mongodb.log"
|
|
||||||
#fi
|
|
||||||
|
|
||||||
# Alternative: When starting MongoDB, and using logfile, truncate log to last 1000 lines of text.
|
|
||||||
# 1) If file exists:
|
|
||||||
#if test -f "$SNAP_COMMON/mongodb.log"; then
|
|
||||||
# # 2) Copy last 1000 lines to variable loglast1000lines.
|
|
||||||
# loglast1000lines=$(tail -1000 "$SNAP_COMMON/mongodb.log")
|
|
||||||
# # 3) Copy variable to replace original MongoDB log.
|
|
||||||
# echo "$loglast1000lines" > "$SNAP_COMMON/mongodb.log"
|
|
||||||
# # 4) Set variable to be empty.
|
|
||||||
# loglast1000lines=""
|
|
||||||
#fi
|
|
||||||
|
|
||||||
if [ -z "${MONGO_URL}" ]; then
|
|
||||||
|
|
||||||
# start mongo deamon
|
|
||||||
BIND_OPTIONS=""
|
|
||||||
if [ "nill" != "${MONGODB_BIND_UNIX_SOCKET}" ] && [ "x" != "x${MONGODB_BIND_UNIX_SOCKET}" ]; then
|
|
||||||
BIND_OPTIONS+=" --unixSocketPrefix ${MONGODB_BIND_UNIX_SOCKET}"
|
|
||||||
fi
|
|
||||||
# Newest MongoDB uses --host or --bind_ip
|
|
||||||
if [ "x" != "x${MONGODB_BIND_IP}" ]; then
|
|
||||||
BIND_OPTIONS+=" --bind_ip $MONGODB_BIND_IP"
|
|
||||||
fi
|
|
||||||
if [ "x" != "x${MONGODB_PORT}" ]; then
|
|
||||||
BIND_OPTIONS+=" --port ${MONGODB_PORT}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "syslog" == "${MONGO_LOG_DESTINATION}" ]; then
|
|
||||||
echo "Sending mongodb logs to syslog"
|
|
||||||
mongod --dbpath ${SNAP_COMMON} --syslog ${BIND_OPTIONS} --quiet
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "snapcommon" == "${MONGO_LOG_DESTINATION}" ]; then
|
|
||||||
echo "Sending mongodb logs to $SNAP_COMMON"
|
|
||||||
mongod --dbpath ${SNAP_COMMON} --logpath ${SNAP_COMMON}/mongodb.log --logappend ${BIND_OPTIONS} --quiet
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "devnull" == "${MONGO_LOG_DESTINATION}" ]; then
|
|
||||||
echo "Sending mongodb logs to /dev/null"
|
|
||||||
mongod --dbpath ${SNAP_COMMON} --logpath /dev/null ${BIND_OPTIONS} --quiet
|
|
||||||
fi
|
|
||||||
#echo "mongodb log destination: ${MONGO_LOG_DESTINATION}" >> "${SNAP_COMMON}/settings.log"
|
|
||||||
|
|
||||||
# Disable MongoDB telemetry and free monitoring
|
|
||||||
/snap/${SNAP_NAME}/current/bin/mongosh wekan --eval 'disableTelemetry();' --port ${MONGODB_PORT}
|
|
||||||
/snap/${SNAP_NAME}/current/bin/mongosh wekan --eval 'db.disableFreeMonitoring();' --port ${MONGODB_PORT}
|
|
||||||
|
|
||||||
# Snap: Disable apparmor="DENIED" at syslog
|
|
||||||
# https://github.com/wekan/wekan/issues/4855
|
|
||||||
/snap/${SNAP_NAME}/current/bin/mongosh wekan --eval 'db.adminCommand({ setParameter: 1, diagnosticDataCollectionEnabled: false});' --port ${MONGODB_PORT}
|
|
||||||
|
|
||||||
# Drop indexes on database upgrade, when starting MongoDB
|
|
||||||
#mongosh wekan --eval "db.getCollectionNames().forEach(function(col_name) { var coll = db.getCollection(col_name); coll.dropIndexes(); });" $BIND_OPTIONS
|
|
||||||
|
|
||||||
# Set MongoDB feature compatibility version
|
|
||||||
#mongosh wekan --eval 'db.adminCommand({ setFeatureCompatibilityVersion: "4.4" });' ${BIND_OPTIONS}
|
|
||||||
|
|
||||||
# Delete incomplete uploads so that they would not prevent starting WeKan
|
|
||||||
/snap/${SNAP_NAME}/current/bin/mongosh wekan --eval 'db.getCollection("cfs.attachments.filerecord").find( { "uploadedAt": { "$exists": true }, "copies.attachments" : null,"failures.copies.attachments.doneTrying" : {"$ne" : true}});' --port ${MONGODB_PORT}
|
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
if [ "syslog" == "${MONGO_LOG_DESTINATION}" ]; then
|
|
||||||
echo "Sending mongodb logs to syslog"
|
|
||||||
mongod --dbpath ${SNAP_COMMON} --syslog ${MONGO_URL} --quiet
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "snapcommon" == "${MONGO_LOG_DESTINATION}" ]; then
|
|
||||||
echo "Sending mongodb logs to ${SNAP_COMMON}"
|
|
||||||
mongod --dbpath ${SNAP_COMMON} --logpath ${SNAP_COMMON}/mongodb.log --logappend ${MONGO_URL} --quiet
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "devnull" == "${MONGO_LOG_DESTINATION}" ]; then
|
|
||||||
echo "Sending mongodb logs to /dev/null"
|
|
||||||
mongod --dbpath ${SNAP_COMMON} --logpath /dev/null ${MONGO_URL} --quiet
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Disable MongoDB telemetry and free monitoring
|
|
||||||
/snap/${SNAP_NAME}/current/bin/mongosh ${MONGO_URL} --eval 'disableTelemetry();'
|
|
||||||
/snap/${SNAP_NAME}/current/bin/mongosh ${MONGO_URL} --eval 'db.disableFreeMonitoring();'
|
|
||||||
|
|
||||||
# Snap: Disable apparmor="DENIED" at syslog
|
|
||||||
# https://github.com/wekan/wekan/issues/4855
|
|
||||||
/snap/${SNAP_NAME}/current/bin/mongosh ${MONGO_URL} --eval 'db.adminCommand({ setParameter: 1, diagnosticDataCollectionEnabled: false});'
|
|
||||||
|
|
||||||
# Drop indexes on database upgrade, when starting MongoDB
|
|
||||||
#mongosh wekan --eval "db.getCollectionNames().forEach(function(col_name) { var coll = db.getCollection(col_name); coll.dropIndexes(); });" $BIND_OPTIONS
|
|
||||||
|
|
||||||
# Set MongoDB feature compatibility version
|
|
||||||
#/snap/${SNAP_NAME}/current/bin/mongosh ${MONGO_URL} --eval 'db.adminCommand({ setFeatureCompatibilityVersion: "4.4" });'
|
|
||||||
|
|
||||||
# Delete incomplete uploads so that they would not prevent starting WeKan
|
|
||||||
/snap/${SNAP_NAME}/current/bin/mongosh ${MONGO_URL} --eval 'db.getCollection("cfs.attachments.filerecord").find( { "uploadedAt": { "$exists": true }, "copies.attachments" : null,"failures.copies.attachments.doneTrying" : {"$ne" : true}});'
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
@ -1,138 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# MongoDB Version Manager
|
|
||||||
# Helps manage MongoDB server binaries for different versions (3-8)
|
|
||||||
# This script provides utilities for adding and managing MongoDB server versions
|
|
||||||
|
|
||||||
# Source settings
|
|
||||||
source $SNAP/bin/wekan-read-settings
|
|
||||||
|
|
||||||
# MongoDB version information
|
|
||||||
declare -A MONGO_VERSIONS=(
|
|
||||||
["3"]="3.2.22"
|
|
||||||
["4"]="4.4.28"
|
|
||||||
["5"]="5.0.28"
|
|
||||||
["6"]="6.0.15"
|
|
||||||
["7"]="7.0.25"
|
|
||||||
["8"]="8.0.4"
|
|
||||||
)
|
|
||||||
|
|
||||||
# MongoDB binary paths
|
|
||||||
declare -A MONGO_PATHS=(
|
|
||||||
["3"]="/snap/${SNAP_NAME}/current/migratemongo/bin"
|
|
||||||
["4"]="/snap/${SNAP_NAME}/current/mongodb4/bin"
|
|
||||||
["5"]="/snap/${SNAP_NAME}/current/mongodb5/bin"
|
|
||||||
["6"]="/snap/${SNAP_NAME}/current/mongodb6/bin"
|
|
||||||
["7"]="/snap/${SNAP_NAME}/current/bin"
|
|
||||||
["8"]="/snap/${SNAP_NAME}/current/mongodb8/bin"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check which MongoDB versions are available
|
|
||||||
check_available_versions() {
|
|
||||||
echo "=== Available MongoDB Server Versions ==="
|
|
||||||
for version in "${!MONGO_VERSIONS[@]}"; do
|
|
||||||
local path="${MONGO_PATHS[$version]}"
|
|
||||||
if [ -f "$path/mongod" ]; then
|
|
||||||
echo "✓ MongoDB $version.x (${MONGO_VERSIONS[$version]}) - Available at $path"
|
|
||||||
else
|
|
||||||
echo "✗ MongoDB $version.x (${MONGO_VERSIONS[$version]}) - Not available at $path"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
echo ""
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check which MongoDB Node.js drivers are available
|
|
||||||
check_available_drivers() {
|
|
||||||
echo "=== Available MongoDB Node.js Drivers ==="
|
|
||||||
if [ -f "/home/wekan/repos/wekan/package.json" ]; then
|
|
||||||
for version in "${!MONGO_VERSIONS[@]}"; do
|
|
||||||
if grep -q "mongodb${version}legacy" "/home/wekan/repos/wekan/package.json"; then
|
|
||||||
echo "✓ MongoDB $version.x Node.js driver - Available (mongodb${version}legacy)"
|
|
||||||
else
|
|
||||||
echo "✗ MongoDB $version.x Node.js driver - Not available"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
else
|
|
||||||
echo "package.json not found"
|
|
||||||
fi
|
|
||||||
echo ""
|
|
||||||
}
|
|
||||||
|
|
||||||
# Show current active MongoDB version
|
|
||||||
show_active_version() {
|
|
||||||
if [ -f "${SNAP_COMMON}/mongodb-active-version" ]; then
|
|
||||||
local active_version=$(cat "${SNAP_COMMON}/mongodb-active-version")
|
|
||||||
echo "=== Current Active MongoDB Version ==="
|
|
||||||
echo "Active Version: MongoDB $active_version.x"
|
|
||||||
echo "Version File: ${SNAP_COMMON}/mongodb-active-version"
|
|
||||||
echo ""
|
|
||||||
else
|
|
||||||
echo "=== Current Active MongoDB Version ==="
|
|
||||||
echo "No active version file found (will use default MongoDB 7.x)"
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Show version detection log
|
|
||||||
show_detection_log() {
|
|
||||||
if [ -f "${SNAP_COMMON}/mongodb-version-detection.log" ]; then
|
|
||||||
echo "=== MongoDB Version Detection Log ==="
|
|
||||||
tail -20 "${SNAP_COMMON}/mongodb-version-detection.log"
|
|
||||||
echo ""
|
|
||||||
else
|
|
||||||
echo "=== MongoDB Version Detection Log ==="
|
|
||||||
echo "No detection log found"
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Force version detection
|
|
||||||
force_detection() {
|
|
||||||
echo "=== Forcing MongoDB Version Detection ==="
|
|
||||||
rm -f "${SNAP_COMMON}/mongodb-active-version"
|
|
||||||
echo "Cleared cached version. Next MongoDB restart will detect version automatically."
|
|
||||||
echo ""
|
|
||||||
}
|
|
||||||
|
|
||||||
# Show help
|
|
||||||
show_help() {
|
|
||||||
echo "MongoDB Version Manager"
|
|
||||||
echo ""
|
|
||||||
echo "Usage: $0 [command]"
|
|
||||||
echo ""
|
|
||||||
echo "Commands:"
|
|
||||||
echo " versions - Show available MongoDB server versions"
|
|
||||||
echo " drivers - Show available MongoDB Node.js drivers"
|
|
||||||
echo " active - Show current active MongoDB version"
|
|
||||||
echo " log - Show version detection log"
|
|
||||||
echo " detect - Force version detection on next restart"
|
|
||||||
echo " help - Show this help message"
|
|
||||||
echo ""
|
|
||||||
echo "Examples:"
|
|
||||||
echo " $0 versions # Check which MongoDB versions are available"
|
|
||||||
echo " $0 active # Show which version is currently active"
|
|
||||||
echo " $0 detect # Force re-detection on next restart"
|
|
||||||
echo ""
|
|
||||||
}
|
|
||||||
|
|
||||||
# Main command handling
|
|
||||||
case "${1:-help}" in
|
|
||||||
"versions")
|
|
||||||
check_available_versions
|
|
||||||
;;
|
|
||||||
"drivers")
|
|
||||||
check_available_drivers
|
|
||||||
;;
|
|
||||||
"active")
|
|
||||||
show_active_version
|
|
||||||
;;
|
|
||||||
"log")
|
|
||||||
show_detection_log
|
|
||||||
;;
|
|
||||||
"detect")
|
|
||||||
force_detection
|
|
||||||
;;
|
|
||||||
"help"|*)
|
|
||||||
show_help
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
@ -1,141 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Snap Channel Manager for Wekan
|
|
||||||
# Manages snap channels for Wekan-related packages
|
|
||||||
|
|
||||||
# Source settings
|
|
||||||
source $SNAP/bin/wekan-read-settings
|
|
||||||
|
|
||||||
# Wekan-related snap packages
|
|
||||||
WEKAN_SNAPS=("wekan" "wekan-gantt-gpl" "wekan-ondra")
|
|
||||||
|
|
||||||
# Get current channel for a snap
|
|
||||||
get_current_channel() {
|
|
||||||
local snap_name="$1"
|
|
||||||
snap list "$snap_name" 2>/dev/null | awk 'NR==2 {print $4}' || echo "not-installed"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check if snap is on stable channel
|
|
||||||
is_stable_channel() {
|
|
||||||
local snap_name="$1"
|
|
||||||
local channel=$(get_current_channel "$snap_name")
|
|
||||||
[ "$channel" = "stable" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
# Switch snap to stable channel
|
|
||||||
switch_to_stable() {
|
|
||||||
local snap_name="$1"
|
|
||||||
local current_channel=$(get_current_channel "$snap_name")
|
|
||||||
|
|
||||||
if [ "$current_channel" = "not-installed" ]; then
|
|
||||||
echo "Snap $snap_name is not installed"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$current_channel" = "stable" ]; then
|
|
||||||
echo "Snap $snap_name is already on stable channel"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Switching $snap_name from $current_channel to stable channel..."
|
|
||||||
if snap refresh "$snap_name" --channel=stable; then
|
|
||||||
echo "Successfully switched $snap_name to stable channel"
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
echo "Failed to switch $snap_name to stable channel"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Show status of all Wekan snaps
|
|
||||||
show_status() {
|
|
||||||
echo "=== Wekan Snap Channel Status ==="
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
local all_stable=true
|
|
||||||
|
|
||||||
for snap_name in "${WEKAN_SNAPS[@]}"; do
|
|
||||||
local channel=$(get_current_channel "$snap_name")
|
|
||||||
local status=""
|
|
||||||
|
|
||||||
if [ "$channel" = "not-installed" ]; then
|
|
||||||
status="[NOT INSTALLED]"
|
|
||||||
elif [ "$channel" = "stable" ]; then
|
|
||||||
status="[STABLE]"
|
|
||||||
else
|
|
||||||
status="[NON-STABLE: $channel]"
|
|
||||||
all_stable=false
|
|
||||||
fi
|
|
||||||
|
|
||||||
printf "%-20s %s\n" "$snap_name:" "$status"
|
|
||||||
done
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
if [ "$all_stable" = true ]; then
|
|
||||||
echo "All Wekan snaps are on stable channel ✓"
|
|
||||||
else
|
|
||||||
echo "Some Wekan snaps are not on stable channel ⚠"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Switch all Wekan snaps to stable
|
|
||||||
switch_all_to_stable() {
|
|
||||||
echo "=== Switching All Wekan Snaps to Stable Channel ==="
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
local success_count=0
|
|
||||||
local total_count=0
|
|
||||||
|
|
||||||
for snap_name in "${WEKAN_SNAPS[@]}"; do
|
|
||||||
if [ "$(get_current_channel "$snap_name")" != "not-installed" ]; then
|
|
||||||
total_count=$((total_count + 1))
|
|
||||||
if switch_to_stable "$snap_name"; then
|
|
||||||
success_count=$((success_count + 1))
|
|
||||||
fi
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "=== Summary ==="
|
|
||||||
echo "Successfully switched: $success_count/$total_count snaps"
|
|
||||||
|
|
||||||
if [ "$success_count" -eq "$total_count" ]; then
|
|
||||||
echo "All Wekan snaps are now on stable channel ✓"
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
echo "Some snaps failed to switch to stable channel ⚠"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Show help
|
|
||||||
show_help() {
|
|
||||||
echo "Wekan Snap Channel Manager"
|
|
||||||
echo ""
|
|
||||||
echo "Usage: $0 [command]"
|
|
||||||
echo ""
|
|
||||||
echo "Commands:"
|
|
||||||
echo " status - Show current channel status for all Wekan snaps"
|
|
||||||
echo " switch - Switch all Wekan snaps to stable channel"
|
|
||||||
echo " help - Show this help"
|
|
||||||
echo ""
|
|
||||||
echo "Wekan-related snaps: ${WEKAN_SNAPS[*]}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Main execution
|
|
||||||
case "${1:-status}" in
|
|
||||||
"status")
|
|
||||||
show_status
|
|
||||||
;;
|
|
||||||
"switch")
|
|
||||||
switch_all_to_stable
|
|
||||||
;;
|
|
||||||
"help"|"-h"|"--help")
|
|
||||||
show_help
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Unknown command: $1"
|
|
||||||
show_help
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
@ -75,19 +75,6 @@ apps:
|
||||||
command: ./bin/mongodb-restore
|
command: ./bin/mongodb-restore
|
||||||
plugs: [network, network-bind]
|
plugs: [network, network-bind]
|
||||||
|
|
||||||
mongodb-migration:
|
|
||||||
command: ./bin/mongodb-migrate
|
|
||||||
plugs: [network, network-bind]
|
|
||||||
|
|
||||||
mongodb-migration-web:
|
|
||||||
command: ./bin/mongodb-migration-web
|
|
||||||
plugs: [network, network-bind]
|
|
||||||
|
|
||||||
mongodb-migration-status:
|
|
||||||
command: ./bin/mongodb-migration-status
|
|
||||||
|
|
||||||
snap-channel-manager:
|
|
||||||
command: ./bin/snap-channel-manager
|
|
||||||
|
|
||||||
parts:
|
parts:
|
||||||
mongodb:
|
mongodb:
|
||||||
|
|
@ -122,29 +109,6 @@ parts:
|
||||||
source: https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2404-x86_64-100.12.2.tgz
|
source: https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2404-x86_64-100.12.2.tgz
|
||||||
plugin: dump
|
plugin: dump
|
||||||
|
|
||||||
#mongodb3:
|
|
||||||
# source: https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-3.6.23.tgz
|
|
||||||
# plugin: dump
|
|
||||||
# stage-packages:
|
|
||||||
# - libssl1.1
|
|
||||||
# - libcurl3
|
|
||||||
# - libstemmer0d
|
|
||||||
# - zlib1g
|
|
||||||
# - libsnappy1v5
|
|
||||||
# - libyaml-cpp0.5v5
|
|
||||||
# - libpcre3
|
|
||||||
# - libpcrecpp0v5
|
|
||||||
# - libboost-system1.65.1
|
|
||||||
# - libboost-iostreams1.65.1
|
|
||||||
# - libboost-filesystem1.65.1
|
|
||||||
# - libboost-program-options1.65.1
|
|
||||||
# - libgoogle-perftools4
|
|
||||||
# stage:
|
|
||||||
# - bin
|
|
||||||
# - usr
|
|
||||||
# prime:
|
|
||||||
# - bin
|
|
||||||
# - usr
|
|
||||||
|
|
||||||
wekan:
|
wekan:
|
||||||
source: .
|
source: .
|
||||||
|
|
@ -164,7 +128,6 @@ parts:
|
||||||
- execstack
|
- execstack
|
||||||
- nodejs
|
- nodejs
|
||||||
- npm
|
- npm
|
||||||
- git # Add git for cloning migratemongo
|
|
||||||
stage-packages:
|
stage-packages:
|
||||||
- libfontconfig1
|
- libfontconfig1
|
||||||
override-build: |
|
override-build: |
|
||||||
|
|
@ -230,12 +193,6 @@ parts:
|
||||||
cp .build/bundle/.node_version.txt $SNAPCRAFT_PART_INSTALL/
|
cp .build/bundle/.node_version.txt $SNAPCRAFT_PART_INSTALL/
|
||||||
rm -f $SNAPCRAFT_PART_INSTALL/lib/node_modules/wekan
|
rm -f $SNAPCRAFT_PART_INSTALL/lib/node_modules/wekan
|
||||||
|
|
||||||
# Migrate MongoDB 3 to 6 - clone directly from git instead of downloading zip
|
|
||||||
echo "Cloning migratemongo repository..."
|
|
||||||
git clone https://github.com/wekan/migratemongo.git
|
|
||||||
echo "Copy migratemongo files to install directory..."
|
|
||||||
cp -pR migratemongo $SNAPCRAFT_PART_INSTALL/
|
|
||||||
rm -rf migratemongo
|
|
||||||
|
|
||||||
# Delete phantomjs that is in accounts-lockout
|
# Delete phantomjs that is in accounts-lockout
|
||||||
#rm -rf $SNAPCRAFT_PART_INSTALL/programs/server/npm/node_modules/meteor/lucasantoniassi_accounts-lockout/node_modules/phantomjs-prebuilt
|
#rm -rf $SNAPCRAFT_PART_INSTALL/programs/server/npm/node_modules/meteor/lucasantoniassi_accounts-lockout/node_modules/phantomjs-prebuilt
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue