diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bc917e7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +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 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 && \ + ln -sf /dev/stdout /var/log/waagent.log +ENTRYPOINT ["/usr/sbin/waagent"] diff --git a/README b/README index 59fab95..b1c97e5 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 @@ -337,11 +343,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/docker-waagent.conf b/config/docker-waagent.conf new file mode 100644 index 0000000..def7231 --- /dev/null +++ b/config/docker-waagent.conf @@ -0,0 +1,75 @@ +# +# 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=n + +# Supported values are "rsa", "dsa" and "ecdsa". +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 + +# 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. +# '/var/log/waagent.log' if not set +Logs.File=/dev/stdout + +# Enable logging to serial console (y|n) +# When stdout is not enough... +# 'y' if not set +Logs.Console=n + +# 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 756eb4d..97da2b9 100644 --- a/config/waagent.conf +++ b/config/waagent.conf @@ -53,9 +53,21 @@ ResourceDisk.SwapSizeMB=0 # Respond to load balancer probes if requested by Windows Azure. LBProbeResponder=y +# File to write log to. +# '/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... +# 'y' 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 diff --git a/waagent b/waagent index ee25e3f..93722a0 100644 --- a/waagent +++ b/waagent @@ -2546,11 +2546,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]) @@ -2969,12 +2972,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: @@ -5897,6 +5901,7 @@ def main(): if MyDistro == None : sys.exit(1) args = [] + conf_file = None global force force = False for a in sys.argv[1:]: @@ -5909,6 +5914,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): @@ -5916,8 +5923,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("n"): + myLogger.con_path = None verbose = Config.get("Logs.Verbose") if verbose != None and verbose.lower().startswith("y"): myLogger.verbose=True