diff --git a/entrypoint.sh b/entrypoint.sh index c83d9a8..3482c82 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -13,7 +13,17 @@ source "${LIB_PATH}/core/cron.sh" if [ "$(id -u)" = "0" ]; then # Ensure correct permissions on key directories # Create and set permissions on required directories - mkdir -p $DATA_DIR $RUN_DIR $LOG_DIR $CONFIG_DIR + mkdir -p $DATA_DIR $RUN_DIR $LOG_DIR $CONFIG_DIR /var/lib/mysql-files + + # Set proper permissions for MySQL directories + chown -R mysql:mysql $DATA_DIR $RUN_DIR $LOG_DIR $CONFIG_DIR /var/lib/mysql-files + chmod 750 $DATA_DIR /var/lib/mysql-files + chmod 755 $RUN_DIR $LOG_DIR $CONFIG_DIR + + # Ensure directory is clean for initialization + if [ ! -d "$DATA_DIR/mysql" ]; then + rm -rf "$DATA_DIR"/* + fi # Create base MySQL configuration cat > "/etc/my.cnf" << EOF diff --git a/lib/mysql-startup.sh b/lib/mysql-startup.sh index 0c1e9c9..12653ab 100644 --- a/lib/mysql-startup.sh +++ b/lib/mysql-startup.sh @@ -43,7 +43,13 @@ init_mysql() { rm -f /var/run/mysqld/mysqld.pid rm -f /var/run/mysqld/mysqld.sock* - # Initialize MySQL with explicit paths (directories should be created by root) + # Verify directory permissions before initialization + if [ ! -w "$DATA_DIR" ]; then + log_error "Data directory $DATA_DIR is not writable" + return 1 + fi + + # Initialize MySQL with explicit paths mysqld --initialize-insecure --user=mysql \ --datadir="$DATA_DIR" \ --basedir=/usr \ @@ -58,7 +64,13 @@ init_mysql() { if [ -n "$MYSQL_ROOT_PASSWORD" ]; then log_info "Starting MySQL with skip-grant-tables to set root password..." - # Remove any stale files (directories should exist and be owned by mysql) + # Verify socket directory is writable + if [ ! -w "$RUN_DIR" ]; then + log_error "Socket directory $RUN_DIR is not writable" + return 1 + fi + + # Remove any stale files rm -f /var/run/mysqld/mysqld.sock* rm -f /var/run/mysqld/mysqld.pid @@ -166,14 +178,6 @@ start_mysql() { return 1 fi - # Ensure required directories exist - mkdir -p "$RUN_DIR" - chown mysql:mysql "$RUN_DIR" - - # Ensure data directory exists and has correct permissions - mkdir -p /var/lib/mysql - chown -R mysql:mysql "$DATA_DIR" - # Check for forced master recovery FORCE_MASTER_RECOVERY=${FORCE_MASTER_RECOVERY:-0}