From 7dd04723949b07848050c061e831d86707630087 Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Sat, 28 Mar 2015 12:57:27 +0500 Subject: [PATCH 1/8] waagent docker container --- Dockerfile | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6d9c203 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM ubuntu:14.04.2 +RUN apt-get update && apt-get upgrade --no-install-recommends -y +RUN apt-get install -y --no-install-recommends \ + openssl ca-certificates ssh parted sudo net-tools python python-pyasn1 python-rpm +COPY waagent /usr/sbin/ +COPY config/waagent.conf /etc/ +RUN chmod +x /usr/sbin/waagent +ENTRYPOINT ["/usr/sbin/waagent"] From 7198565e1e44ee5bb1fd7c185be17329ebbca5b2 Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Tue, 31 Mar 2015 02:06:10 +0500 Subject: [PATCH 2/8] log to stdout --- waagent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/waagent b/waagent index 98f89ae..1811f70 100644 --- a/waagent +++ b/waagent @@ -5876,7 +5876,7 @@ def main(): if len(sys.argv) == 1: sys.exit(Usage()) - LoggerInit('/var/log/waagent.log','/dev/console') + LoggerInit('/dev/stdout',None) global LinuxDistro LinuxDistro=DistInfo()[0] From 88e8d5f472b6f06692a431c5bf224cc6ebe237b9 Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Tue, 31 Mar 2015 15:21:30 +0500 Subject: [PATCH 3/8] adjust config to be usable in containerized env Configure log file (or stdout), use console or not, add -conf=/path/to/file.conf Default behavior is unchanged --- README | 22 ++++++++++++++++++++-- config/waagent.conf | 9 +++++++++ waagent | 16 +++++++++++++--- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/README b/README index 5ea8268..f17d03f 100644 --- a/README +++ b/README @@ -128,6 +128,10 @@ Flags: -force: Skip interactive confirmation for some commands +Options: + + -conf=/path/to/file.conf: Specify configuration file to use instead of default one. + Commands: -help: Lists the supported commands and flags. @@ -203,6 +207,8 @@ ResourceDisk.MountPoint=/mnt/resource ResourceDisk.EnableSwap=n ResourceDisk.SwapSizeMB=0 LBProbeResponder=y +Logs.File=/var/log/waagent.log +Logs.Console=y Logs.Verbose=n OS.RootDeviceScsiTimeout=300 OS.OpensslPath=None @@ -335,11 +341,23 @@ Type: Boolean Default: y If set, waagent will respond to load balancer probes from the platform (if present). +Logs.File: +Type: String Default: /dev/stdout + +If set, logs are appended to this file (instead of stdout). Bundled +config (config/waagent.conf) sets this to '/var/log/waagent.log'. + +Logs.Console: +Type: Boolean Default: n + +If set, waagent also logs to serial console. Bundled config (config/waagent.conf) +sets this to 'y'. + Logs.Verbose: Type: Boolean Default: n -If set, log verbosity is boosted. Waagent logs to /var/log/waagent.log and -leverages the system logrotate functionality to rotate logs. +If set, log verbosity is boosted. When waagent logs to file it can +leverage the system logrotate functionality to rotate logs. OS.RootDeviceScsiTimeout: Type: Integer Default: 300 diff --git a/config/waagent.conf b/config/waagent.conf index dafde04..faf7a6d 100644 --- a/config/waagent.conf +++ b/config/waagent.conf @@ -53,6 +53,15 @@ ResourceDisk.SwapSizeMB=0 # Respond to load balancer probes if requested by Windows Azure. LBProbeResponder=y +# File to write log to. +# '/dev/stdout' if not set +Logs.File=/var/log/waagent.log + +# Enable logging to serial console (y|n) +# When stdout is not enough... +# 'n' if not set +Logs.Console=y + # Enable verbose logging (y|n) Logs.Verbose=n diff --git a/waagent b/waagent index 1811f70..08c4043 100644 --- a/waagent +++ b/waagent @@ -2962,12 +2962,13 @@ class ConfigurationProvider(object): """ Parse amd store key:values in waagent.conf """ - def __init__(self): + def __init__(self, walaConfigFile): self.values = dict() if 'MyDistro' not in globals(): global MyDistro MyDistro = GetMyDistro() - walaConfigFile = MyDistro.getConfigurationPath() + if walaConfigFile is None: + walaConfigFile = MyDistro.getConfigurationPath() if os.path.isfile(walaConfigFile) == False: raise Exception("Missing configuration in {0}".format(walaConfigFile)) try: @@ -5890,6 +5891,7 @@ def main(): if MyDistro == None : sys.exit(1) args = [] + conf_file = None global force force = False for a in sys.argv[1:]: @@ -5902,6 +5904,8 @@ def main(): myLogger.verbose = True elif re.match("^([-/]*)force", a): force = True + elif re.match("^(?:[-/]*)conf=.+", a): + conf_file = re.match("^(?:[-/]*)conf=(.+)", a).groups()[0] elif re.match("^([-/]*)(setup|install)", a): sys.exit(MyDistro.Install()) elif re.match("^([-/]*)(uninstall)", a): @@ -5909,8 +5913,14 @@ def main(): else: args.append(a) global Config - Config = ConfigurationProvider() + Config = ConfigurationProvider(conf_file) + logfile = Config.get("Logs.File") + if logfile is not None: + myLogger.file_path = logfile + logconsole = Config.get("Logs.Console") + if logconsole is not None and logconsole.lower().startswith("y"): + myLogger.con_path = "/dev/console" verbose = Config.get("Logs.Verbose") if verbose != None and verbose.lower().startswith("y"): myLogger.verbose=True From 0297185c6483002f60e25eb0db9b7eddced5e788 Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Wed, 8 Apr 2015 17:04:39 +0500 Subject: [PATCH 4/8] configure network interface --- Dockerfile | 2 +- config/docker-waagent.conf | 69 ++++++++++++++++++++++++++++++++++++++ config/waagent.conf | 3 ++ waagent | 5 ++- 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 config/docker-waagent.conf diff --git a/Dockerfile b/Dockerfile index 6d9c203..6506bbc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,6 @@ RUN apt-get update && apt-get upgrade --no-install-recommends -y RUN apt-get install -y --no-install-recommends \ openssl ca-certificates ssh parted sudo net-tools python python-pyasn1 python-rpm COPY waagent /usr/sbin/ -COPY config/waagent.conf /etc/ +COPY config/docker-waagent.conf /etc/waagent.conf RUN chmod +x /usr/sbin/waagent ENTRYPOINT ["/usr/sbin/waagent"] diff --git a/config/docker-waagent.conf b/config/docker-waagent.conf new file mode 100644 index 0000000..25b8778 --- /dev/null +++ b/config/docker-waagent.conf @@ -0,0 +1,69 @@ +# +# Windows Azure Linux Agent Configuration +# + +# Specified program is invoked with the argument "Ready" when we report ready status +# to the endpoint server. +Role.StateConsumer=None + +# Specified program is invoked with XML file argument specifying role +# configuration. +Role.ConfigurationConsumer=None + +# Specified program is invoked with XML file argument specifying role topology. +Role.TopologyConsumer=None + +# Enable instance creation +Provisioning.Enabled=y + +# Password authentication for root account will be unavailable. +Provisioning.DeleteRootPassword=y + +# Generate fresh host key pair. +Provisioning.RegenerateSshHostKeyPair=y + +# Supported values are "rsa", "dsa" and "ecdsa". +Provisioning.SshHostKeyPairType=rsa + +# Monitor host name changes and publish changes via DHCP requests. +Provisioning.MonitorHostName=y + +# Format if unformatted. If 'n', resource disk will not be mounted. +ResourceDisk.Format=y + +# File system on the resource disk +# Typically ext3 or ext4. FreeBSD images should use 'ufs2' here. +ResourceDisk.Filesystem=ext4 + +# Mount point for the resource disk +ResourceDisk.MountPoint=/mnt/resource + +# Create and use swapfile on resource disk. +ResourceDisk.EnableSwap=n + +# Size of the swapfile. +ResourceDisk.SwapSizeMB=0 + +# Respond to load balancer probes if requested by Windows Azure. +LBProbeResponder=y + +# File to write log to. +# '/dev/stdout' if not set +#Logs.File=/var/log/waagent.log + +# Enable logging to serial console (y|n) +# When stdout is not enough... +# 'n' if not set +#Logs.Console=y + +# Enable verbose logging (y|n) +Logs.Verbose=n + +# Preferred network interface to communicate with Azure platform +Network.Interface=eth0 + +# Root device timeout in seconds. +OS.RootDeviceScsiTimeout=300 + +# If "None", the system default version is used. +OS.OpensslPath=None diff --git a/config/waagent.conf b/config/waagent.conf index faf7a6d..96fcdf5 100644 --- a/config/waagent.conf +++ b/config/waagent.conf @@ -65,6 +65,9 @@ Logs.Console=y # Enable verbose logging (y|n) Logs.Verbose=n +# Preferred network interface to communicate with Azure platform +#Network.Interface=eth0 + # Root device timeout in seconds. OS.RootDeviceScsiTimeout=300 diff --git a/waagent b/waagent index 08c4043..5fa20dc 100644 --- a/waagent +++ b/waagent @@ -2533,11 +2533,14 @@ def GetFirstActiveNetworkInterfaceNonLoopback(): if retsize == (expected*struct_size) : Warn('SIOCGIFCONF returned more than ' + str(expected) + ' up network interfaces.') s=buff.tostring() + preferred_nic = Config.get("Network.Interface") for i in range(0,struct_size*expected,struct_size): iface=s[i:i+16].split(b'\0', 1)[0] if iface == b'lo': continue - else : + elif preferred_nic is None: + break + elif iface == preferred_nic: break return iface.decode('latin-1'), socket.inet_ntoa(s[i+20:i+24]) From 933e8ea12cfd4a4ff15671c55be3bf199f0d3da8 Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Sun, 12 Apr 2015 00:23:54 +0500 Subject: [PATCH 5/8] do not regenerate ssh host keys in docker environment --- config/docker-waagent.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/docker-waagent.conf b/config/docker-waagent.conf index 25b8778..238bcab 100644 --- a/config/docker-waagent.conf +++ b/config/docker-waagent.conf @@ -20,7 +20,7 @@ Provisioning.Enabled=y Provisioning.DeleteRootPassword=y # Generate fresh host key pair. -Provisioning.RegenerateSshHostKeyPair=y +Provisioning.RegenerateSshHostKeyPair=n # Supported values are "rsa", "dsa" and "ecdsa". Provisioning.SshHostKeyPairType=rsa From 5cffae94dba5f8d1059e19538b7ab14ee9922d37 Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Sun, 12 Apr 2015 00:52:22 +0500 Subject: [PATCH 6/8] rm /etc/skel from container image to prevent polluting home dirs --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6506bbc..6edf657 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,5 +4,5 @@ RUN apt-get install -y --no-install-recommends \ openssl ca-certificates ssh parted sudo net-tools python python-pyasn1 python-rpm COPY waagent /usr/sbin/ COPY config/docker-waagent.conf /etc/waagent.conf -RUN chmod +x /usr/sbin/waagent +RUN chmod +x /usr/sbin/waagent && rm -rf /etc/skel ENTRYPOINT ["/usr/sbin/waagent"] From 71611cd9682a1e533bf27dd4176314bfd58d7fe4 Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Sun, 24 May 2015 18:00:49 +0500 Subject: [PATCH 7/8] migrate to debian:jessie for a smaller image --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6edf657..3d7572a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ -FROM ubuntu:14.04.2 +FROM debian:jessie RUN apt-get update && apt-get upgrade --no-install-recommends -y RUN apt-get install -y --no-install-recommends \ - openssl ca-certificates ssh parted sudo net-tools python python-pyasn1 python-rpm + openssl ca-certificates ssh parted sudo net-tools ifupdown python python-pyasn1 python-rpm COPY waagent /usr/sbin/ COPY config/docker-waagent.conf /etc/waagent.conf RUN chmod +x /usr/sbin/waagent && rm -rf /etc/skel From 63a0a7498e9a461c3fc12c299387318f942e9181 Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Wed, 10 Jun 2015 11:53:55 +0500 Subject: [PATCH 8/8] revert to hardcoded defaults per request from maintainers --- Dockerfile | 4 +++- config/docker-waagent.conf | 14 ++++++++++---- config/waagent.conf | 4 ++-- waagent | 6 +++--- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3d7572a..bc917e7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,5 +4,7 @@ RUN apt-get install -y --no-install-recommends \ openssl ca-certificates ssh parted sudo net-tools ifupdown python python-pyasn1 python-rpm COPY waagent /usr/sbin/ COPY config/docker-waagent.conf /etc/waagent.conf -RUN chmod +x /usr/sbin/waagent && rm -rf /etc/skel +RUN chmod +x /usr/sbin/waagent && \ + rm -rf /etc/skel && \ + ln -sf /dev/stdout /var/log/waagent.log ENTRYPOINT ["/usr/sbin/waagent"] diff --git a/config/docker-waagent.conf b/config/docker-waagent.conf index 238bcab..def7231 100644 --- a/config/docker-waagent.conf +++ b/config/docker-waagent.conf @@ -28,6 +28,12 @@ Provisioning.SshHostKeyPairType=rsa # Monitor host name changes and publish changes via DHCP requests. Provisioning.MonitorHostName=y +# Decode CustomData from Base64. +Provisioning.DecodeCustomData=n + +# Execute CustomData after provisioning. +Provisioning.ExecuteCustomData=n + # Format if unformatted. If 'n', resource disk will not be mounted. ResourceDisk.Format=y @@ -48,13 +54,13 @@ ResourceDisk.SwapSizeMB=0 LBProbeResponder=y # File to write log to. -# '/dev/stdout' if not set -#Logs.File=/var/log/waagent.log +# '/var/log/waagent.log' if not set +Logs.File=/dev/stdout # Enable logging to serial console (y|n) # When stdout is not enough... -# 'n' if not set -#Logs.Console=y +# 'y' if not set +Logs.Console=n # Enable verbose logging (y|n) Logs.Verbose=n diff --git a/config/waagent.conf b/config/waagent.conf index 96fcdf5..5b308cd 100644 --- a/config/waagent.conf +++ b/config/waagent.conf @@ -54,12 +54,12 @@ ResourceDisk.SwapSizeMB=0 LBProbeResponder=y # File to write log to. -# '/dev/stdout' if not set +# '/var/log/waagent.log' if not set Logs.File=/var/log/waagent.log # Enable logging to serial console (y|n) # When stdout is not enough... -# 'n' if not set +# 'y' if not set Logs.Console=y # Enable verbose logging (y|n) diff --git a/waagent b/waagent index 5fa20dc..9000da0 100644 --- a/waagent +++ b/waagent @@ -5880,7 +5880,7 @@ def main(): if len(sys.argv) == 1: sys.exit(Usage()) - LoggerInit('/dev/stdout',None) + LoggerInit('/var/log/waagent.log','/dev/console') global LinuxDistro LinuxDistro=DistInfo()[0] @@ -5922,8 +5922,8 @@ def main(): if logfile is not None: myLogger.file_path = logfile logconsole = Config.get("Logs.Console") - if logconsole is not None and logconsole.lower().startswith("y"): - myLogger.con_path = "/dev/console" + if logconsole is not None and logconsole.lower().startswith("n"): + myLogger.con_path = None verbose = Config.get("Logs.Verbose") if verbose != None and verbose.lower().startswith("y"): myLogger.verbose=True