diff options
author | khilman <khilman@users.noreply.github.com> | 2018-07-20 11:38:40 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-20 11:38:40 -0500 |
commit | 45f76344b4278f1ecf9956f3a81bfe11cd525c43 (patch) | |
tree | 08cfb059940190cac3eb62bcb8b5a6d01ca67396 /lava-master/scripts/setup.sh | |
parent | ed83f7aa1af39e75c10d5e8c4f1385c302beec12 (diff) | |
parent | 0f09e5c9b89cee21a6ee39db9daf8e17525dd493 (diff) |
Merge pull request #32 from montjoie/persistantdb_pr
Persistantdb pr
Diffstat (limited to 'lava-master/scripts/setup.sh')
-rwxr-xr-x | lava-master/scripts/setup.sh | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/lava-master/scripts/setup.sh b/lava-master/scripts/setup.sh index 585499e..6ab0663 100755 --- a/lava-master/scripts/setup.sh +++ b/lava-master/scripts/setup.sh @@ -1,5 +1,26 @@ #!/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 +fi +sudo -u postgres psql -c "ALTER USER lavaserver WITH PASSWORD '$(cat /root/pg_lava_password)';" || exit $? +sed -i "s,^LAVA_DB_PASSWORD=.*,LAVA_DB_PASSWORD='$(cat /root/pg_lava_password)'," /etc/lava-server/instance.conf || exit $? + +if [ -e /db_lavaserver.gz ];then + gunzip /db_lavaserver.gz || exit $? +fi + +if [ -e /db_lavaserver ];then + echo "Restore database from backup" + sudo -u postgres psql < /db_lavaserver || exit $? + lava-server manage migrate || exit $? + echo "Restore jobs output from backup" + rm -r /var/lib/lava-server/default/media/job-output/* + tar xzf /joboutput.tar.gz || exit $? +fi +chown -R lavaserver:lavaserver /var/lib/lava-server/default/media/job-output/ + if [ -e /root/lava-users ];then for ut in $(ls /root/lava-users) do @@ -49,8 +70,13 @@ if [ -e /root/lava-callback-tokens ];then echo "Missing DESCRIPTION for $USER" exit 1 fi - echo "Adding $USER ($DESCRIPTION) DEBUG($TOKEN)" - lava-server manage tokens add --user $USER --secret $TOKEN --description "$DESCRIPTION" || exit 1 + lava-server manage tokens list --user $USER |grep -q $TOKEN + if [ $? -eq 0 ];then + echo "SKIP already present token for $USER" + else + echo "Adding $USER ($DESCRIPTION) DEBUG($TOKEN)" + lava-server manage tokens add --user $USER --secret $TOKEN --description "$DESCRIPTION" || exit 1 + fi done fi |