summaryrefslogtreecommitdiffstats
path: root/lava-master
diff options
context:
space:
mode:
authorKevin Hilman <khilman@baylibre.com>2020-07-13 10:05:26 -0700
committerGitHub <noreply@github.com>2020-07-13 10:05:26 -0700
commitc6592d385d17b89e6dd9dc244fb592d5ab38f28a (patch)
tree11383622b649dfcee41bff379380aa818371255c /lava-master
parent5b77713b6290e44cbe34a426fea71f5881949f72 (diff)
parent8c9b84ce25577375d7c0c73229881d6e14a27ee8 (diff)
Merge pull request #122 from montjoie/postgres-fix
Postgres fix
Diffstat (limited to 'lava-master')
-rw-r--r--lava-master/Dockerfile2
-rwxr-xr-xlava-master/entrypoint.d/01_setup.sh54
2 files changed, 33 insertions, 23 deletions
diff --git a/lava-master/Dockerfile b/lava-master/Dockerfile
index 5bf989a..6396253 100644
--- a/lava-master/Dockerfile
+++ b/lava-master/Dockerfile
@@ -39,6 +39,8 @@ COPY apache2/ /etc/apache2/
# Fixes 'postgresql ERROR: invalid locale name: "en_US.UTF-8"' when restoring a backup
RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && locale-gen en_US.UTF-8
+COPY pg_lava_password /root
+
# TODO: send this fix to upstream
RUN sed -i 's,find /root/entrypoint.d/ -type f,find /root/entrypoint.d/ -type f | sort,' /root/entrypoint.sh
# TODO: send this fix to upstream
diff --git a/lava-master/entrypoint.d/01_setup.sh b/lava-master/entrypoint.d/01_setup.sh
index 53db47e..e3619f7 100755
--- a/lava-master/entrypoint.d/01_setup.sh
+++ b/lava-master/entrypoint.d/01_setup.sh
@@ -1,8 +1,11 @@
#!/bin/bash
# always reset the lavaserver user, since its password could have been reseted in a "docker build --nocache"
-if [ ! -e /root/pg_lava_password ];then
- < /dev/urandom tr -dc A-Za-z0-9 | head -c16 > /root/pg_lava_password
+if [ ! -s /root/pg_lava_password ];then
+ echo "DEBUG: Generating a random LAVA password"
+ < /dev/urandom tr -dc A-Za-z0-9 | head -c16 > /root/pg_lava_password
+else
+ echo "DEBUG: use the given LAVA password"
fi
sudo -u postgres psql -c "ALTER USER lavaserver WITH PASSWORD '$(cat /root/pg_lava_password)';" || exit $?
if [ -e /etc/lava-server/instance.conf ];then
@@ -13,32 +16,37 @@ else
sed -i "s,PASSWORD:.*,PASSWORD: '$(cat /root/pg_lava_password)'," /etc/lava-server/settings.d/00-database.yaml || exit $?
fi
-if [ -e /root/backup/db_lavaserver.gz ];then
- gunzip /root/backup/db_lavaserver.gz || exit $?
-fi
+# verify that the backup was not already applied in case of persistent_db
+if [ ! -e "/var/lib/postgresql/lava-docker.backup_done" ];then
+ if [ -e /root/backup/db_lavaserver.gz ];then
+ gunzip /root/backup/db_lavaserver.gz || exit $?
+ fi
-if [ -e /root/backup/db_lavaserver ];then
- echo "Restore database from backup"
- sudo -u postgres psql < /root/backup/db_lavaserver || exit $?
- yes yes | lava-server manage migrate || exit $?
- echo "Restore jobs output from backup"
- rm -r /var/lib/lava-server/default/media/job-output/*
+ if [ -e /root/backup/db_lavaserver ];then
+ echo "Restore database from backup"
+ sudo -u postgres psql < /root/backup/db_lavaserver || exit $?
+ yes yes | lava-server manage migrate || exit $?
+ echo "Restore jobs output from backup"
+ rm -r /var/lib/lava-server/default/media/job-output/*
- # allow using different folder for tar operations (/tmp by default)
- TMPDIR=${TMPDIR:-/tmp}
+ # allow using different folder for tar operations (/tmp by default)
+ TMPDIR=${TMPDIR:-/tmp}
- tar xzf /root/backup/joboutput.tar.gz || exit $?
-fi
- lava-server manage makemigrations
- yes yes | lava-server manage migrate || exit $?
-
-if [ -e /root/backup/devices.tar.gz ];then
- echo "INFO: Restoring devices files"
- tar xzf /root/backup/devices.tar.gz
- chown -R lavaserver:lavaserver /etc/lava-server/dispatcher-config/devices
+ tar xzf /root/backup/joboutput.tar.gz || exit $?
+ chown -R lavaserver:lavaserver /var/lib/lava-server/default/media/job-output/
+ touch /var/lib/postgresql/lava-docker.backup_done
+ fi
+ if [ -e /root/backup/devices.tar.gz ];then
+ echo "INFO: Restoring devices files"
+ tar xzf /root/backup/devices.tar.gz
+ chown -R lavaserver:lavaserver /etc/lava-server/dispatcher-config/devices
+ fi
+else
+ echo "DEBUG: backup already applied"
fi
-chown -R lavaserver:lavaserver /var/lib/lava-server/default/media/job-output/
+lava-server manage makemigrations
+yes yes | lava-server manage migrate || exit $?
# default site is set as example.com
if [ -e /root/lava_http_fqdn ];then