fusor / dockerfiles

3 stars 3 forks source link

mediawiki can not work with mariadb #4

Closed ghost closed 7 years ago

ghost commented 7 years ago

Tried with this and setup mediawiki and mariadb with service-catalog and ansible-service-broker, and got "can not contact to database server", but all environment is injected to the mediawiki pod, and mariadb work well.

  1. mariadb work well
[root@host-8-241-58 ~]# mysql -u admin -p admin -h 172.30.139.86 -P 3306
Enter password: 
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.0.28-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [admin]> info
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'info' at line 1
MariaDB [admin]> status
--------------
mysql  Ver 15.1 Distrib 5.5.56-MariaDB, for Linux (x86_64) using readline 5.1

Connection id:      6
Current database:   admin
Current user:       admin@10.129.0.1
SSL:            Not in use
Current pager:      stdout
Using outfile:      ''
Using delimiter:    ;
Server:         MariaDB
Server version:     10.0.28-MariaDB MariaDB Server
Protocol version:   10
Connection:     172.30.139.86 via TCP/IP
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    utf8
Conn.  characterset:    utf8
TCP port:       3306
Uptime:         2 hours 38 min 9 sec

Threads: 1  Questions: 315  Slow queries: 0  Opens: 187  Flush tables: 1  Open tables: 113  Queries per second avg: 0.033
  1. all env is attach to the mediawiki pod
sh-4.2$ env|grep -i db
RHSCL_MARIADB_SERVICE_HOST=172.30.139.86
DB_HOST=172.30.139.86
DB_NAME=admin
DB_PORT=3306
RHSCL_MARIADB_SERVICE_PORT_PORT_3306=3306
RHSCL_MARIADB_PORT=tcp://172.30.139.86:3306
DB_TYPE=mysql
RHSCL_MARIADB_PORT_3306_TCP_ADDR=172.30.139.86
RHSCL_MARIADB_PORT_3306_TCP=tcp://172.30.139.86:3306
DB_PASSWORD=admin
MEDIAWIKI_DB_SCHEMA=mediawiki
RHSCL_MARIADB_SERVICE_PORT=3306
RHSCL_MARIADB_PORT_3306_TCP_PORT=3306
RHSCL_MARIADB_PORT_3306_TCP_PROTO=tcp
DB_USER=admin
  1. all env should be used with mediawiki123 entrypoint.sh
sh-4.2$ cat /bin/entrypoint.sh 
#!/bin/bash

USER_ID=$(id -u)
if [ ${USER_UID} != ${USER_ID} ]; then
  sed "s@${USER_NAME}:x:\${USER_ID}:@${USER_NAME}:x:${USER_ID}:@g" ${BASE_DIR}/etc/passwd.template > /etc/passwd
fi

: ${MEDIAWIKI_SITE_NAME:=MediaWiki}
: ${MEDIAWIKI_SITE_LANG:=en}
: ${MEDIAWIKI_ADMIN_USER:=admin}
: ${MEDIAWIKI_ADMIN_PASS:=rosebud}
: ${MEDIAWIKI_DB_SCHEMA:=wiki}
: ${MEDIAWIKI_SHARED:=/persistent}
: ${MEDIAWIKI_LOGO:=\$wgStylePath/common/images/wiki.png}
: ${DB_TYPE:=postgres}
: ${DB_USER:=postgres}
: ${DB_NAME:=mediawiki}

LOCAL_SETTINGS=${BASE_DIR}/httpd/mediawiki123/LocalSettings.php
IMAGE_DIR=${BASE_DIR}/httpd/mediawiki123/images
if [ -d "$MEDIAWIKI_SHARED" ]; then
  if [ ! -e "$MEDIAWIKI_SHARED/LocalSettings.php" ] && [ ! -z "${DB_HOST}" ]; then
    # If the container is restarted this will fail because the tables are already created
    # but there won't be a LocalSettings.php
    php /usr/share/mediawiki123/maintenance/install.php \
      --confpath ${BASE_DIR}/httpd/mediawiki123 \
      --dbname "$DB_NAME" \
      --dbschema "$MEDIAWIKI_DB_SCHEMA" \
      --dbport "$DB_PORT" \
      --dbserver "$DB_HOST" \
      --dbtype "$DB_TYPE" \
      --dbuser "$DB_USER" \
      --dbpass "$DB_PASSWORD" \
      --installdbuser "$DB_USER" \
      --installdbpass "$DB_PASSWORD" \
      --scriptpath "" \
      --server "http://${MEDIAWIKI_SITE_SERVER}" \
      --lang "$MEDIAWIKI_SITE_LANG" \
      --pass "$MEDIAWIKI_ADMIN_PASS" \
      "$MEDIAWIKI_ADMIN_USER" \
      "$MEDIAWIKI_SITE_NAME"
    echo "session_save_path(\"${BASE_DIR}/tmp\");" >> $LOCAL_SETTINGS
    sed -i -e "s/\$wgEnableUploads = false;/\$wgEnableUploads = true;/" $LOCAL_SETTINGS
    sed -i -e "s/#\$wgHashedUploadDirectory = false;/\$wgHashedUploadDirectory = true;/" $LOCAL_SETTINGS
    grep -q -F "\$wgUploadDirectory" "$LOCAL_SETTINGS" || (echo "\$wgUploadDirectory = \"$IMAGE_DIR\";" >> $LOCAL_SETTINGS)

    mv $LOCAL_SETTINGS $MEDIAWIKI_SHARED/LocalSettings.php
    ln -s $MEDIAWIKI_SHARED/LocalSettings.php $LOCAL_SETTINGS
  elif [ -e "$MEDIAWIKI_SHARED/LocalSettings.php" ]; then
    ln -s $MEDIAWIKI_SHARED/LocalSettings.php $LOCAL_SETTINGS
  fi

  # If the images directory only contains a README, then link it to
  # $MEDIAWIKI_SHARED/images, creating the shared directory if necessary
  if [ "$(ls $IMAGE_DIR)" = "README" -a ! -L $IMAGE_DIR ]; then
    rm -rf $IMAGE_DIR
    mkdir -p "$MEDIAWIKI_SHARED/images"
    ln -s "$MEDIAWIKI_SHARED/images" $IMAGE_DIR
  fi
fi

if [ -e "$LOCAL_SETTINGS" -a "$MEDIAWIKI_UPDATE" = true ]; then
  echo >&2 'info: Running maintenance/update.php';
  php /usr/share/mediawiki123/maintenance/update.php --quick --conf $LOCAL_SETTINGS
fi

if [ -e  "$LOCAL_SETTINGS" ]; then
  sed -i -e '/$wgLogo/c\$wgLogo = '\"$MEDIAWIKI_LOGO'\";' $LOCAL_SETTINGS
fi
ghost commented 7 years ago

Checked again and now work as expected, so close this.