diff options
author | Corentin LABBE <clabbe@baylibre.com> | 2018-07-04 15:35:13 +0200 |
---|---|---|
committer | Corentin LABBE <clabbe@baylibre.com> | 2018-07-19 21:16:22 +0200 |
commit | 70bffaef36b2afe7c732d6f20afca008c5ef1445 (patch) | |
tree | a4f70f46f0b6c9e007516b7f2f313d2e0ca09051 | |
parent | 32221a4e8fe36fd5c3c972039932cb53a25b1d5c (diff) |
Made the database persistent
Until now, each docker-compose down will loose all data (jobs, devices, etc...).
By creating a docker volume, the database will now be persistent other restart.
Due to a risk of the lava package reseting the password, it is always reseted at start.
This patch add also another volume for job output which are stored in the filesystem and not in database.
-rw-r--r-- | README.md | 1 | ||||
-rwxr-xr-x | lava-master/scripts/setup.sh | 7 | ||||
-rwxr-xr-x | lavalab-gen.py | 12 |
3 files changed, 19 insertions, 1 deletions
@@ -215,6 +215,7 @@ masters: - name: lava-master name of the master host: name name of the host running lava-master (default to "local") webadmin_https: Does the LAVA webadmin is accessed via https + persistent_db: True/False (default False) Is the postgres DB is persistent over reboot users: - name: LAVA username token: The token of this user diff --git a/lava-master/scripts/setup.sh b/lava-master/scripts/setup.sh index 585499e..c00cb02 100755 --- a/lava-master/scripts/setup.sh +++ b/lava-master/scripts/setup.sh @@ -1,5 +1,12 @@ #!/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 /root/lava-users ];then for ut in $(ls /root/lava-users) do diff --git a/lavalab-gen.py b/lavalab-gen.py index 35b10c7..e0c1c16 100755 --- a/lavalab-gen.py +++ b/lavalab-gen.py @@ -85,7 +85,7 @@ def main(): sys.exit(1) masters = workers["masters"] for master in masters: - keywords_master = [ "name", "type", "host", "users", "tokens", "webadmin_https" ] + keywords_master = [ "name", "type", "host", "users", "tokens", "webadmin_https", "persistent_db" ] for keyword in master: if not keyword in keywords_master: print("WARNING: unknown keyword %s" % keyword) @@ -108,6 +108,16 @@ def main(): dockcomp["services"][name]["volumes"] = [ "/boot:/boot", "/lib/modules:/lib/modules" ] dockcomp["services"][name]["build"] = {} dockcomp["services"][name]["build"]["context"] = name + persistent_db = False + if "persistent_db" in master: + persistent_db = master["persistent_db"] + if persistent_db: + pg_volume_name = "pgdata_" + name + dockcomp["services"][name]["volumes"].append(pg_volume_name + ":/var/lib/postgresql") + dockcomp["services"][name]["volumes"].append("lava_job_output:/var/lib/lava-server/default/media/job-output/") + dockcomp["volumes"] = {} + dockcomp["volumes"][pg_volume_name] = {} + dockcomp["volumes"]["lava_job_output"] = {} with open(dockcomposeymlpath, 'w') as f: yaml.dump(dockcomp, f) |