From b02d70df38334e54a1ac62cb3b8d8a5651cfb846 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Wed, 12 Sep 2018 13:54:24 +0200 Subject: [PATCH] remove ephemeral layer --- basic/srv/vm/mgr/__init__.py | 4 ++++ basic/srv/vm/mgr/tools.py | 7 +++++++ setup-all.sh | 14 ++++++++++++++ 3 files changed, 25 insertions(+) create mode 100755 setup-all.sh diff --git a/basic/srv/vm/mgr/__init__.py b/basic/srv/vm/mgr/__init__.py index a9875d9..bf3fd10 100644 --- a/basic/srv/vm/mgr/__init__.py +++ b/basic/srv/vm/mgr/__init__.py @@ -215,11 +215,15 @@ class VMMgr: ip = tools.get_unused_ip() tools.update_hosts_lease(ip, app) tools.set_container_ip(pid, ip) + # Remove ephemeral layer data + tools.remove_ephemeral_layer(app) def unregister_container(self): # Unset IP of a container based on values given via lxc.hook.post-stop hook app = os.environ['LXC_NAME'] tools.update_hosts_lease(None, app) + # Remove ephemeral layer data + tools.remove_ephemeral_layer(app) def register_proxy(self, app, reload_nginx=True): # Rebuild nginx configuration using IP of referenced app container and reload nginx diff --git a/basic/srv/vm/mgr/tools.py b/basic/srv/vm/mgr/tools.py index 86006c0..a8b7b98 100644 --- a/basic/srv/vm/mgr/tools.py +++ b/basic/srv/vm/mgr/tools.py @@ -5,6 +5,7 @@ import dns.exception import dns.resolver import os import requests +import shutil import socket import ssl import subprocess @@ -153,3 +154,9 @@ def set_container_ip(pid, ip): # Set IP in container based on PID given via lxc.hook.start-host hook cmd = 'ip addr add {}/16 broadcast 172.17.255.255 dev eth0 && ip route add default via 172.17.0.1'.format(ip) subprocess.run(['nsenter', '-a', '-t', pid, '--', '/bin/sh', '-c', cmd]) + +def remove_ephemeral_layer(app): + layer = os.path.join('/var/lib/lxc', app, 'delta0') + if os.path.exists(layer): + for item in os.scandir(layer): + shutil.rmtree(item.path) if item.is_dir() else os.unlink(item.path) diff --git a/setup-all.sh b/setup-all.sh new file mode 100755 index 0000000..6a064c6 --- /dev/null +++ b/setup-all.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -e + +SOURCE_DIR=$(realpath $(dirname "${0}")) + +# Setup components +${SOURCE_DIR}/activemq/setup.sh +${SOURCE_DIR}/ckan-datapusher/setup.sh +${SOURCE_DIR}/postgres/setup.sh +${SOURCE_DIR}/redis/setup.sh +${SOURCE_DIR}/solr/setup.sh + +# Setup applications +${SOURCE_DIR}/ckan