fix: init.sh - wait MySQL first, then silent install for DB schema
All checks were successful
Docker Build & Push SugarCRM 6.5 CE / build-and-push (push) Successful in 13s
All checks were successful
Docker Build & Push SugarCRM 6.5 CE / build-and-push (push) Successful in 13s
This commit is contained in:
205
init.sh
205
init.sh
@@ -1,7 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# SugarCRM 6.5 CE Docker Entrypoint
|
# SugarCRM 6.5 CE Docker Entrypoint
|
||||||
# ==================================
|
# ==================================
|
||||||
# Creates config.php directly (bypasses broken silent installer)
|
# 1. Warten auf MySQL + Apache
|
||||||
|
# 2. Silent Install (erstellt DB-Schema + config.php)
|
||||||
|
# 3. AdminWizard deaktivieren
|
||||||
|
|
||||||
# Resolve DB connection from env
|
# Resolve DB connection from env
|
||||||
if [ -z "$DB_HOST_NAME" ]; then
|
if [ -z "$DB_HOST_NAME" ]; then
|
||||||
@@ -20,11 +22,11 @@ if [ -z "$DATABASE_NAME" ]; then
|
|||||||
export DATABASE_NAME=${DB_ENV_MYSQL_DATABASE:-sugarcrm}
|
export DATABASE_NAME=${DB_ENV_MYSQL_DATABASE:-sugarcrm}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Generate config_override.php from template (ignore perm error)
|
# Generate config_override.php from template
|
||||||
/usr/local/bin/envtemplate.py -i /usr/local/src/config_override.php.pyt -o /var/www/html/config_override.php 2>/dev/null || true
|
/usr/local/bin/envtemplate.py -i /usr/local/src/config_override.php.pyt -o /var/www/html/config_override.php 2>/dev/null || true
|
||||||
|
|
||||||
# Start Apache
|
# Start Apache
|
||||||
echo "Starting Apache (background)..."
|
echo "Starting Apache..."
|
||||||
apachectl -DFOREGROUND &
|
apachectl -DFOREGROUND &
|
||||||
APACHE_PID=$!
|
APACHE_PID=$!
|
||||||
|
|
||||||
@@ -32,152 +34,121 @@ APACHE_PID=$!
|
|||||||
echo "Waiting for Apache..."
|
echo "Waiting for Apache..."
|
||||||
for i in $(seq 1 30); do
|
for i in $(seq 1 30); do
|
||||||
if curl -s http://localhost/ >/dev/null 2>&1; then
|
if curl -s http://localhost/ >/dev/null 2>&1; then
|
||||||
echo "Apache is ready"
|
echo "Apache ready"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
# Wait for MySQL
|
# Wait for MySQL FIRST
|
||||||
echo "Waiting for MySQL..."
|
echo "Waiting for MySQL..."
|
||||||
for i in $(seq 1 30); do
|
for i in $(seq 1 30); do
|
||||||
if php -r "\$c=@mysql_connect('$DB_HOST_NAME:$DB_TCP_PORT','$DB_USER_NAME','$DB_PASSWORD');if(\$c){mysql_close(\$c);exit(0);}exit(1);" 2>/dev/null; then
|
if php -r "\$c=@mysql_connect('$DB_HOST_NAME:$DB_TCP_PORT','$DB_USER_NAME','$DB_PASSWORD');if(\$c){mysql_close(\$c);exit(0);}exit(1);" 2>/dev/null; then
|
||||||
echo "MySQL is ready"
|
echo "MySQL ready"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
sleep 2
|
sleep 2
|
||||||
done
|
done
|
||||||
|
|
||||||
# Create config.php directly if not exists or empty
|
# Run silent install if config.php missing or empty
|
||||||
CONFIG_PHP=/var/www/html/config.php
|
CONFIG_PHP=/var/www/html/config.php
|
||||||
if [ ! -s "$CONFIG_PHP" ]; then
|
if [ ! -s "$CONFIG_PHP" ]; then
|
||||||
echo "Creating config.php directly..."
|
echo "Creating config_si.php for silent install..."
|
||||||
|
|
||||||
cat > "$CONFIG_PHP" << CONFIGEOF
|
cat > /var/www/html/config_si.php << SIEOF
|
||||||
<?php
|
<?php
|
||||||
// SugarCRM 6.5 CE Configuration
|
\$sugar_config_si = array(
|
||||||
// Auto-generated by Docker entrypoint
|
'setup_db_host_name' => 'DB_HOST',
|
||||||
\$sugar_config = array(
|
'setup_db_database_name' => 'DB_NAME',
|
||||||
'adminwizard' => array('completed' => true),
|
'setup_db_admin_user_name' => 'DB_USER',
|
||||||
'dbconfig' => array(
|
'setup_db_admin_password' => 'DB_PASS',
|
||||||
'db_host_name' => '$DB_HOST_NAME',
|
'setup_db_type' => 'mysql',
|
||||||
'db_host_instance' => 'SQLEXPRESS',
|
'setup_db_port_num' => 'DB_PORT',
|
||||||
'db_user_name' => '$DB_USER_NAME',
|
'setup_db_drop_tables' => false,
|
||||||
'db_password' => '$DB_PASSWORD',
|
'setup_db_create_database' => false,
|
||||||
'db_name' => '$DATABASE_NAME',
|
'setup_db_create_sugarsales_user' => false,
|
||||||
'db_type' => 'mysql',
|
'setup_license_key' => 'free',
|
||||||
'db_port' => '$DB_TCP_PORT',
|
'setup_license_accept' => true,
|
||||||
'db_manager' => 'MysqlManager',
|
'setup_site_url' => 'http://localhost:2080',
|
||||||
),
|
'setup_system_name' => 'SugarCRM 6.5 CE',
|
||||||
'dbconfigoption' => array(
|
'setup_site_admin_user_name' => 'admin',
|
||||||
'persistent' => true,
|
'setup_site_admin_password' => 'admin123',
|
||||||
'autofree' => false,
|
'setup_site_admin_password_retype' => 'admin123',
|
||||||
'debug' => 0,
|
'demoData' => 'no',
|
||||||
'ssl' => false,
|
'dbUSRData' => 'create',
|
||||||
),
|
|
||||||
'default_currency_iso4217' => 'EUR',
|
|
||||||
'default_currency_name' => 'Euro',
|
|
||||||
'default_currency_symbol' => '€',
|
|
||||||
'default_date_format' => 'd.m.Y',
|
|
||||||
'default_time_format' => 'H:i',
|
|
||||||
'default_language' => 'en_us',
|
|
||||||
'default_theme' => 'Sugar',
|
|
||||||
'default_module_favicon' => false,
|
|
||||||
'default_charset' => 'UTF-8',
|
|
||||||
'default_number_grouping_seperator' => '.',
|
|
||||||
'default_decimal_seperator' => ',',
|
|
||||||
'disable_export' => false,
|
|
||||||
'disable_vcr' => false,
|
|
||||||
'dump_slow_queries' => false,
|
|
||||||
'email_default_client' => 'sugar',
|
|
||||||
'email_default_editor' => 'plain',
|
|
||||||
'export_delimiter' => ',',
|
|
||||||
'history_max_viewed' => 50,
|
|
||||||
'installer_locked' => true,
|
|
||||||
'languages' => array('en_us' => 'English (US)'),
|
|
||||||
'list_max_entries_per_page' => 20,
|
|
||||||
'lock_default_user_name' => 'admin',
|
|
||||||
'lock_default_user_password' => 'admin123',
|
|
||||||
'passwordsetting' => array(
|
|
||||||
'minpwdlength' => '',
|
|
||||||
'oneupper' => '',
|
|
||||||
'onelower' => '',
|
|
||||||
'onenumber' => '',
|
|
||||||
'onespecial' => '',
|
|
||||||
'systemgenerated' => '0',
|
|
||||||
'forgotpasswordON' => '1',
|
|
||||||
'linkexpiration' => '1',
|
|
||||||
'linkexpirationtime' => '24',
|
|
||||||
'linkexpirationtype' => '1',
|
|
||||||
'userexpiration' => '0',
|
|
||||||
'userexpirationtime' => '',
|
|
||||||
'userexpirationtype' => '1',
|
|
||||||
'userexpirationlogin' => '',
|
|
||||||
'lockoutexpiration' => '0',
|
|
||||||
'lockoutexpirationtime' => '',
|
|
||||||
'lockoutexpirationtype' => '1',
|
|
||||||
'lockoutexpirationlogin' => '',
|
|
||||||
),
|
|
||||||
'resource_management' => array(
|
|
||||||
'special_query_limit' => 50000,
|
|
||||||
'special_query_modules' => array('Reports', 'Export', 'Import', 'Administration', 'Sync'),
|
|
||||||
'default_limit' => 1000,
|
|
||||||
),
|
|
||||||
'site_url' => 'http://localhost:2080',
|
|
||||||
'site_url_is_set' => true,
|
|
||||||
'sugar_version' => '6.5.26',
|
|
||||||
'sugarbeet' => false,
|
|
||||||
'translation_string_prefix' => false,
|
|
||||||
'unique_key' => '$(date +%s)$(head -c 8 /dev/urandom | md5sum | cut -c1-8)',
|
|
||||||
'upload_maxsize' => 30000000,
|
|
||||||
'verify_client_ip' => false,
|
|
||||||
'logger' => array(
|
|
||||||
'level' => 'fatal',
|
|
||||||
'file' => array(
|
|
||||||
'ext' => '.log',
|
|
||||||
'name' => 'sugarcrm',
|
|
||||||
'dateFormat' => '%c',
|
|
||||||
'maxSize' => '10MB',
|
|
||||||
'dirPerm' => 0770,
|
|
||||||
'filePerm' => 0660,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'cache_dir' => 'cache/',
|
|
||||||
);
|
);
|
||||||
CONFIGEOF
|
SIEOF
|
||||||
|
|
||||||
|
sed -i "s/DB_HOST/$DB_HOST_NAME/g" /var/www/html/config_si.php
|
||||||
|
sed -i "s/DB_NAME/$DATABASE_NAME/g" /var/www/html/config_si.php
|
||||||
|
sed -i "s/DB_USER/$DB_USER_NAME/g" /var/www/html/config_si.php
|
||||||
|
sed -i "s/DB_PASS/$DB_PASSWORD/g" /var/www/html/config_si.php
|
||||||
|
sed -i "s/DB_PORT/$DB_TCP_PORT/g" /var/www/html/config_si.php
|
||||||
|
|
||||||
|
echo "Running silent install..."
|
||||||
|
curl -s "http://localhost/install.php?goto=SilentInstall&cli=true" > /tmp/install_output.html 2>&1
|
||||||
|
|
||||||
# Verify config.php has content
|
|
||||||
if [ -s "$CONFIG_PHP" ]; then
|
if [ -s "$CONFIG_PHP" ]; then
|
||||||
echo "config.php created successfully ($(wc -l < "$CONFIG_PHP") lines)"
|
echo "Silent install complete ($(wc -l < "$CONFIG_PHP") lines)"
|
||||||
|
|
||||||
# Ensure installer_locked is true
|
# Fix: installer_locked = true
|
||||||
sed -i "s/'installer_locked' => *false/'installer_locked' => true/" "$CONFIG_PHP" 2>/dev/null || true
|
sed -i "s/'installer_locked' *=> *false/'installer_locked' => true/" "$CONFIG_PHP" 2>/dev/null || true
|
||||||
if ! grep -q "installer_locked" "$CONFIG_PHP"; then
|
if ! grep -q "'installer_locked' => true" "$CONFIG_PHP"; then
|
||||||
echo " 'installer_locked' => true," >> "$CONFIG_PHP"
|
echo " 'installer_locked' => true," >> "$CONFIG_PHP"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Insert adminwizard into DB for API access
|
# Add adminwizard
|
||||||
php -r "
|
if ! grep -q adminwizard "$CONFIG_PHP"; then
|
||||||
\$c = @mysql_connect('$DB_HOST_NAME:$DB_TCP_PORT', '$DB_USER_NAME', '$DB_PASSWORD');
|
sed -i "/'site_url' =>/a\\
|
||||||
if (\$c) {
|
'adminwizard' => array('completed' => true)," "$CONFIG_PHP" 2>/dev/null || true
|
||||||
mysql_select_db('$DATABASE_NAME', \$c);
|
fi
|
||||||
mysql_query(\"INSERT IGNORE INTO config (category, name, value) VALUES ('system', 'adminwizard', '{\\\"completed\\\":true}')\", \$c);
|
echo "Admin Wizard disabled"
|
||||||
mysql_close(\$c);
|
|
||||||
}
|
|
||||||
" 2>/dev/null || true
|
|
||||||
else
|
else
|
||||||
echo "ERROR: config.php is empty!"
|
echo "FAILED: config.php empty after silent install!"
|
||||||
|
cat /tmp/install_output.html 2>/dev/null | head -20
|
||||||
|
|
||||||
|
# Fallback: write config manually + run SQL setup
|
||||||
|
echo "Attempting manual setup..."
|
||||||
|
cat > "$CONFIG_PHP" << 'CONFIGEOF'
|
||||||
|
<?php
|
||||||
|
$sugar_config = array(
|
||||||
|
'adminwizard' => array('completed' => true),
|
||||||
|
'dbconfig' => array(
|
||||||
|
'db_host_name' => '__DB_HOST__',
|
||||||
|
'db_user_name' => '__DB_USER__',
|
||||||
|
'db_password' => '__DB_PASS__',
|
||||||
|
'db_name' => '__DB_NAME__',
|
||||||
|
'db_type' => 'mysql',
|
||||||
|
'db_port' => '__DB_PORT__',
|
||||||
|
'db_manager' => 'MysqlManager',
|
||||||
|
),
|
||||||
|
'default_currency_iso4217' => 'EUR',
|
||||||
|
'default_date_format' => 'd.m.Y',
|
||||||
|
'default_time_format' => 'H:i',
|
||||||
|
'default_language' => 'en_us',
|
||||||
|
'installer_locked' => true,
|
||||||
|
'site_url' => 'http://localhost:2080',
|
||||||
|
'unique_key' => 'manual-setup',
|
||||||
|
'sugar_version' => '6.5.26',
|
||||||
|
);
|
||||||
|
CONFIGEOF
|
||||||
|
sed -i "s/__DB_HOST__/$DB_HOST_NAME/g" "$CONFIG_PHP"
|
||||||
|
sed -i "s/__DB_NAME__/$DATABASE_NAME/g" "$CONFIG_PHP"
|
||||||
|
sed -i "s/__DB_USER__/$DB_USER_NAME/g" "$CONFIG_PHP"
|
||||||
|
sed -i "s/__DB_PASS__/$DB_PASSWORD/g" "$CONFIG_PHP"
|
||||||
|
sed -i "s/__DB_PORT__/$DB_TCP_PORT/g" "$CONFIG_PHP"
|
||||||
|
echo "Manual config.php written"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "SugarCRM already configured ($(wc -l < "$CONFIG_PHP") lines)"
|
echo "SugarCRM already configured ($(wc -l < "$CONFIG_PHP") lines)"
|
||||||
|
|
||||||
# Ensure installer_locked is true
|
# Ensure installer_locked
|
||||||
if grep -q "'installer_locked' => false" "$CONFIG_PHP" 2>/dev/null; then
|
if grep -q "'installer_locked' => false" "$CONFIG_PHP" 2>/dev/null; then
|
||||||
sed -i "s/'installer_locked' => false/'installer_locked' => true/" "$CONFIG_PHP"
|
sed -i "s/'installer_locked' => false/'installer_locked' => true/" "$CONFIG_PHP"
|
||||||
echo "Fixed installer_locked"
|
echo "Fixed installer_locked"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure adminwizard is in config
|
# Ensure adminwizard
|
||||||
if ! grep -q adminwizard "$CONFIG_PHP" 2>/dev/null; then
|
if ! grep -q adminwizard "$CONFIG_PHP" 2>/dev/null; then
|
||||||
sed -i "/'site_url' =>/a\\
|
sed -i "/'site_url' =>/a\\
|
||||||
'adminwizard' => array('completed' => true)," "$CONFIG_PHP" 2>/dev/null || true
|
'adminwizard' => array('completed' => true)," "$CONFIG_PHP" 2>/dev/null || true
|
||||||
@@ -186,11 +157,9 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
rm -f /var/www/html/config_si.php
|
rm -f /var/www/html/config_si.php /tmp/install_output.html
|
||||||
|
|
||||||
# Start cron
|
# Start cron
|
||||||
/usr/sbin/cron
|
/usr/sbin/cron
|
||||||
echo "Setup complete. SugarCRM 6.5.26 CE ready."
|
echo "Setup complete. SugarCRM 6.5.26 CE ready."
|
||||||
|
|
||||||
# Bring Apache to foreground
|
|
||||||
wait $APACHE_PID
|
wait $APACHE_PID
|
||||||
|
|||||||
Reference in New Issue
Block a user