| #!/bin/bash |
|
|
| set -e |
|
|
| |
| log() { |
| echo "[$(date '+%Y-%m-%d %H:%M:%S')] [CORE-SERVICE-INSTALL] $*" |
| } |
|
|
| |
| cleanup() { |
| log "Cleaning up temporary files..." |
| rm -rf /tmp/service_temp* |
| } |
|
|
| |
| trap cleanup EXIT |
|
|
| log "Starting core service installation..." |
|
|
| |
| apt-get update |
|
|
| |
| log "Installing basic system dependencies..." |
| apt-get install -y --no-install-recommends \ |
| curl \ |
| wget \ |
| unzip \ |
| ca-certificates \ |
| openssl |
|
|
| |
| log "Installing minio server..." |
| MINIO_VERSION="RELEASE.2025-04-22T22-12-26Z" |
| wget -O /usr/local/bin/minio "https://dl.min.io/server/minio/release/linux-amd64/archive/minio.${MINIO_VERSION}" |
| chmod +x /usr/local/bin/minio |
|
|
| |
| log "Installing minio client..." |
| wget -O /usr/local/bin/mc "https://dl.min.io/client/mc/release/linux-amd64/mc" |
| chmod +x /usr/local/bin/mc |
|
|
| |
| mkdir -p /opt/service |
| mkdir -p /opt/service/bin |
| mkdir -p /opt/service/config |
|
|
| |
| log "Copying minio configuration template..." |
| if [ -f "/configs/minio.conf.template" ]; then |
| cp /configs/minio.conf.template /opt/service/config/minio.conf.template |
| log "Minio configuration template copied successfully" |
| else |
| log "Warning: /configs/minio.conf.template not found" |
| fi |
|
|
| |
| log "Copying service configuration template..." |
| if [ -f "/configs/service.conf.template" ]; then |
| cp /configs/service.conf.template /opt/service/config/service.conf.template |
| log "Service configuration template copied successfully" |
| else |
| log "Warning: /configs/service.conf.template not found" |
| fi |
|
|
| |
| log "Creating minio startup script..." |
| cat > /opt/service/bin/start-minio.sh << 'EOF' |
| |
|
|
| set -e |
|
|
| |
| if [ -f /home/user/config/minio.conf ]; then |
| source /home/user/config/minio.conf |
| fi |
|
|
| |
| MINIO_ROOT_USER="${MINIO_ROOT_USER:-minioadmin}" |
| MINIO_ROOT_PASSWORD="${MINIO_ROOT_PASSWORD:-minioadmin123}" |
| MINIO_DATA_DIR="${MINIO_DATA_DIR:-/home/user/data/minio}" |
| MINIO_CONSOLE_ADDRESS="${MINIO_CONSOLE_ADDRESS:-:9001}" |
|
|
| |
| mkdir -p "$MINIO_DATA_DIR" |
|
|
| |
| export MINIO_ROOT_USER |
| export MINIO_ROOT_PASSWORD |
| export MINIO_CONSOLE_ADDRESS |
|
|
| |
| exec /usr/local/bin/minio server "$MINIO_DATA_DIR" --address ":9000" |
| EOF |
|
|
| chmod +x /opt/service/bin/start-minio.sh |
|
|
| |
| cat > /opt/service/bin/health-check.sh << 'EOF' |
| |
|
|
| |
| MINIO_URL="${MINIO_SERVER_URL:-http://localhost:9000}" |
|
|
| |
| if curl -f "$MINIO_URL/minio/health/live" >/dev/null 2>&1; then |
| echo "Minio is healthy" |
| exit 0 |
| else |
| echo "Minio is not responding" |
| exit 1 |
| fi |
| EOF |
|
|
| chmod +x /opt/service/bin/health-check.sh |
|
|
| |
| cat > /opt/service/bin/init-buckets.sh << 'EOF' |
| |
|
|
| set -e |
|
|
| |
| if [ -f /home/user/config/minio.conf ]; then |
| source /home/user/config/minio.conf |
| fi |
|
|
| MINIO_ROOT_USER="${MINIO_ROOT_USER:-minioadmin}" |
| MINIO_ROOT_PASSWORD="${MINIO_ROOT_PASSWORD:-minioadmin123}" |
| MINIO_SERVER_URL="${MINIO_SERVER_URL:-http://localhost:9000}" |
|
|
| |
| echo "Waiting for minio to be ready..." |
| for i in {1..30}; do |
| if curl -f "$MINIO_SERVER_URL/minio/health/live" >/dev/null 2>&1; then |
| echo "Minio is ready" |
| break |
| fi |
| sleep 2 |
| done |
|
|
| |
| /usr/local/bin/mc alias set local "$MINIO_SERVER_URL" "$MINIO_ROOT_USER" "$MINIO_ROOT_PASSWORD" |
|
|
| |
| |
| |
| |
| |
|
|
| |
| |
|
|
| echo "Bucket initialization completed" |
| EOF |
|
|
| chmod +x /opt/service/bin/init-buckets.sh |
|
|
| |
| log "Cleaning up..." |
| apt-get autoremove -y |
| apt-get autoclean |
| rm -rf /var/lib/apt/lists/* |
|
|
| log "Minio service installation completed" |
| log "Installation path: /opt/service" |
| log "Minio server: /usr/local/bin/minio" |
| log "Minio client: /usr/local/bin/mc" |
| log "Configuration templates copied from /configs/ to /opt/service/config/" |
| log "Startup scripts created in /opt/service/bin/" |
|
|