Log bootstrap / installer messages to file as well

This enables debugging when a server does not come up as
expected.

Fixes #22
This commit is contained in:
yuvipanda
2018-07-29 02:17:12 -07:00
parent 25475916c5
commit 414d3932ac
4 changed files with 61 additions and 28 deletions

View File

@@ -14,7 +14,7 @@ def trust_gpg_key(key):
# If gpg2 doesn't exist, install it.
if not os.path.exists('/usr/bin/gpg2'):
install_packages(['gnupg2'])
subprocess.run(['apt-key', 'add', '-'], input=key, check=True)
subprocess.check_output(['apt-key', 'add', '-'], input=key, stderr=subprocess.STDOUT)
def add_source(name, source_url, section):
@@ -24,7 +24,7 @@ def add_source(name, source_url, section):
distro is determined from /etc/os-release
"""
# lsb_release is not installed in most docker images by default
distro = subprocess.check_output(['/bin/bash', '-c', 'source /etc/os-release && echo ${VERSION_CODENAME}']).decode().strip()
distro = subprocess.check_output(['/bin/bash', '-c', 'source /etc/os-release && echo ${VERSION_CODENAME}'], stderr=subprocess.STDOUT).decode().strip()
line = f'deb {source_url} {distro} {section}'
with open(os.path.join('/etc/apt/sources.list.d/', name + '.list'), 'a+') as f:
# Write out deb line only if it already doesn't exist
@@ -32,7 +32,7 @@ def add_source(name, source_url, section):
f.seek(0)
f.write(line)
f.truncate()
subprocess.check_output(['apt-get', 'update', '--yes'])
subprocess.check_output(['apt-get', 'update', '--yes'], stderr=subprocess.STDOUT)
def install_packages(packages):
@@ -41,9 +41,9 @@ def install_packages(packages):
"""
# Check if an apt-get update is required
if len(os.listdir('/var/lib/apt/lists')) == 0:
subprocess.check_output(['apt-get', 'update', '--yes'])
subprocess.check_output(['apt-get', 'update', '--yes'], stderr=subprocess.STDOUT)
subprocess.check_output([
'apt-get',
'install',
'--yes'
] + packages)
] + packages, stderr=subprocess.STDOUT)