From 2664ef3039373a3a216896935367b6d1e4c42448 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Mon, 9 Nov 2015 22:34:56 +0000 Subject: [PATCH] Updated the docker init-script to not re-install MySQL; it can cause more trouble than it might save; added a guard against trying to set up the ietf database if MySQL isn't running; and changed the final working directory to be the same as where the user invoked the 'docker/run' command. If not started via docker/run, drop into the home directory. - Legacy-Id: 10461 --- docker/docker-init.sh | 46 ++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/docker/docker-init.sh b/docker/docker-init.sh index 51d4366fa..db41a74b9 100755 --- a/docker/docker-init.sh +++ b/docker/docker-init.sh @@ -2,14 +2,16 @@ echo "Gathering info ..." MYSQLDIR="$(mysqld --verbose --help 2>/dev/null | awk '$1 == "datadir" { print $2; exit }')" +if [ ! "$USER" ]; then + echo "Environment variable USER is not set -- will set USER='django'." + USER="django" +fi echo "Checking if MySQL base data exists ..." if [ ! -d $MYSQLDIR/mysql ]; then - echo "Re-installing MySQL ..." - apt-get update && apt-get install --reinstall mysql-server + echo "WARNING: Expected the directory $MYSQLDIR/mysql/ to exist -- have you downloaded and unpacked the IETF binary database tarball?" fi - echo "Checking if MySQL is running ..." if ! /etc/init.d/mysql status; then echo "Starting mysql ..." @@ -18,25 +20,32 @@ fi echo "Checking if the IETF database exists at $MYSQLDIR ..." if [ ! -d $MYSQLDIR/ietf_utf8 ]; then + if [ -z "$DATADIR" ]; then + echo "DATADIR is not set, but the IETF database needs to be set up -- can't continue, exiting the docker init script." + exit 1 + fi ls -l $MYSQLDIR - echo "Creating database ..." - mysqladmin -u root --default-character-set=utf8 create ietf_utf8 + if ! /etc/init.d/mysql status; then + echo "Didn't find the IETF database, but can't set it up either, as MySQL isn't running." + else + echo "Creating database ..." + mysqladmin -u root --default-character-set=utf8 create ietf_utf8 - echo "Setting up permissions ..." - mysql -u root ietf_utf8 <<< "GRANT ALL PRIVILEGES ON ietf_utf8.* TO django@localhost IDENTIFIED BY 'RkTkDPFnKpko'; FLUSH PRIVILEGES;" + echo "Setting up permissions ..." + mysql -u root ietf_utf8 <<< "GRANT ALL PRIVILEGES ON ietf_utf8.* TO django@localhost IDENTIFIED BY 'RkTkDPFnKpko'; FLUSH PRIVILEGES;" - echo "Fetching database ..." - DUMPDIR=/home/$USER/$DATADIR - wget -N -P $DUMPDIR http://www.ietf.org/lib/dt/sprint/ietf_utf8.sql.gz - - echo "Loading database ..." - gunzip < $DUMPDIR/ietf_utf8.sql.gz \ - | pv --progress --bytes --rate --eta --cursor --size $(gzip --list --quiet $DUMPDIR/ietf_utf8.sql.gz | awk '{ print $2 }') \ - | sed -e 's/ENGINE=MyISAM/ENGINE=InnoDB/' \ - | mysql --user=django --password=RkTkDPFnKpko -s -f ietf_utf8 \ - && rm /tmp/ietf_utf8.sql.gz + echo "Fetching database ..." + DUMPDIR=/home/$USER/$DATADIR + wget -N -P $DUMPDIR http://www.ietf.org/lib/dt/sprint/ietf_utf8.sql.gz + echo "Loading database ..." + gunzip < $DUMPDIR/ietf_utf8.sql.gz \ + | pv --progress --bytes --rate --eta --cursor --size $(gzip --list --quiet $DUMPDIR/ietf_utf8.sql.gz | awk '{ print $2 }') \ + | sed -e 's/ENGINE=MyISAM/ENGINE=InnoDB/' \ + | mysql --user=django --password=RkTkDPFnKpko -s -f ietf_utf8 \ + && rm /tmp/ietf_utf8.sql.gz + fi fi if ! id -u "$USER" &> /dev/null; then @@ -68,7 +77,8 @@ if [ ! -f /opt/home/$USER/datatracker/lib/site-python/settings_local.py ]; then fi chown -R $USER /opt/home/$USER -cd /home/$USER +cd /home/$USER/ +cd /home/$USER/$CWD echo "Done!"