DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Git (397f3d396f)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
<powershell><#
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
.Synopsis
  Bootstrap an AWS EC2 instance with cloud-tools (https://github.com/mozilla/build-cloud-tools)
.Description
  This script will do the following when run:
  - log output to the puppet mailing list, to enable debugging
  - check and/or correct the hostname if required
  - check and/or correct the primary dns suffix
  - check and/or correct the nxlog aggregator configuration
  - ensure only a single puppet run on the golden instance
  - handle reboots and shutdowns (eg: after hostname changes or puppet runs)
.Notes
  All parameters have sensible defaults and only need to be provided when running outside of the cloud-tools environment (eg: testing).
  If running outside of cloud tools, ensure that you provide sensible values for: hostname, domain & aggregator.
  Double angle brackets used in this script are intentional and used to escape the bracket when python pre-processing replaces single bracket tokens.
.Parameter hostname
  Defines the hostname of the target instance.
  When run by cloud-tools, the hostname token will be replaced before the script is uploaded to the target instance.
  Defaults to: '{{hostname}}', if not defined.
.Parameter domain
  Defines the primary DNS suffix of the target instance.
  When run by cloud-tools, the domain token will be replaced before the script is uploaded to the target instance.
  Defaults to: '{{domain}}', if not defined.
.Parameter puppetServer
  Defines the hostname of the puppet server.
  When run by cloud-tools, the puppet_server token will be replaced before the script is uploaded to the target instance.
  Defaults to: '{{puppet_server}}', if not defined.
.Parameter aggregator
  Defines the hostname of the log aggregation server.
  When run by cloud-tools, the region_dns_atom token will be replaced before the script is uploaded to the target instance.
  Defaults to: 'log-aggregator.srv.releng.{{region_dns_atom}}.mozilla.com', if not defined.
.Parameter logDir
  Defines the local directory on the target host where log files will be generated and kept.
  The directory will be created if it does not exist.
  Defaults to: 'C:\log', if not defined.
.Parameter smtpServer
  Defines the smtp server that will relay log messages.
  Defaults to: 'smtp.mail.scl3.mozilla.com', if not defined.
.Parameter logSender
  Defines the email sender (from address) for log reports generated by this script.
  Defaults to an address comprised of the username from environment variable and the hostname and domain arguments mentioned above.
.Parameter logRecipients
  Defines the email recipient list for log reports generated by this script.
  Accepts a string, if only one recipient, or a string array, if more than one.
  Defaults to: 'releng-puppet-mail@mozilla.com', if not defined.
.Example
  PS>.\userscript.ps1 -hostname b-2008-ec2-something -domain build.releng.use1.mozilla.com -aggregator log-aggregator.srv.releng.use1.mozilla.com
#>
param (
  # accept tokens from cloud-tools (change tokens to actual values if running outside cloud-tools)
  [string] $hostname = '{hostname}',
  [string] $domain = '{domain}',
  [string] $puppetServer = '{puppet_server}',
  [string] $deployPass = '{password}',
  [string] $aggregator = 'log-aggregator.srv.releng.{region_dns_atom}.mozilla.com',

  # runtime configuration
  [string] $logDir = ('{{0}}\log' -f $env:SystemDrive),
  [string] $smtpServer = 'smtp.mail.scl3.mozilla.com',
  [string] $logSender = ('{{0}}@{{1}}.{{2}}' -f $env:USERNAME, $hostname, $domain),
  [string[]] $logRecipients = @('releng-puppet-mail@mozilla.com'),

  [string] $buildUsername = 'cltbld'
)
# runtime configuration
$runLog = [IO.Path]::Combine($logDir, 'userdata-run.log')
$puppetLog = [IO.Path]::Combine($logDir, 'puppet-agent-run.log')
$ec2Log = ('{{0}}\Amazon\Ec2ConfigService\Logs\Ec2ConfigLog.txt' -f $env:ProgramFiles)
$smtpServer = $smtpServer

function Download-Module {{
  <#
  .Synopsis
    Downloads a psm1 module file to the local modules folder
  .Description
    The local module will use the psm1 filename, minus extension, as the module name
  .Parameter url
    The full url to the userdata module.
  .Parameter modulesPath
    The full path to the local modules folder.
  #>
  param (
    [string] $url,
    [string] $modulesPath = ('{{0}}\Modules' -f $pshome)
  )
  $filename = $url.Substring($url.LastIndexOf('/') + 1)
  $moduleName = [IO.Path]::GetFileNameWithoutExtension($filename)
  $modulePath = ('{{0}}\{{1}}' -f $modulesPath, $moduleName)
  if (Test-Path $modulePath) {{
    Remove-Module $moduleName -ErrorAction SilentlyContinue
    Remove-Item -path $modulePath -recurse -force
  }}
  New-Item -ItemType Directory -Force -Path $modulePath
  (New-Object Net.WebClient).DownloadFile($url, ('{{0}}\{{1}}' -f $modulePath, $filename))
}}

# download and import the Ec2UserdataUtils module
Download-Module -url 'https://raw.githubusercontent.com/mozilla-releng/build-cloud-tools/master/configs/Ec2UserdataUtils.psm1'
Import-Module Ec2UserdataUtils

# create the log directory if it doesn't exist
New-Item -ItemType Directory -Force -Path $logDir
Set-Ec2ConfigPluginsState
Set-Timezone
Disable-Firewall 
Disable-WindowsUpdate
Rename-Admin
if (!(Is-DomainSetCorrectly -domainExpected $domain)) {{
  Set-Domain -domain $domain
}}
$hostRenamed = $false
if (!(Is-HostnameSetCorrectly -hostnameExpected $hostname)) {{
  Set-Hostname -hostname $hostname
  $hostRenamed = $true
  Stop-ComputerWithDelay -reason 'host renamed' -restart
}}
if (!$hostRenamed) {{
  if ($hostname.Contains("-golden")) {{
    Install-BasePrerequisites -aggregator $aggregator -domain $domain
    Prep-Golden -puppetServer $puppetServer -logdest $puppetLog -deployPass $deployPass -hostname $hostname -domain $domain
    Flush-EventLog
    Stop-ComputerWithDelay -reason 'userdata golden run complete'
  }} elseif ($hostname.contains("-spot")) {{
    Prep-spot -force
  }} elseif ($hostname -match "((b|y)-2008-ec2-[a-z].*|(t|g)-w732-ec2-[a-z].*)") {{
    Prep-Loaner -deployPass $deployPass
  }}
}}
if (!($hostname.Contains("-spot-"))) {{
  Send-Log -logfile $runLog -subject ('UserData Run Report for {{0}}.{{1}}' -f $hostname, $domain) -to 'releng-puppet-mail@mozilla.com' -from $logSender
  Send-Log -logfile $ec2Log -subject ('EC2 Config Report for {{0}}.{{1}}' -f $hostname, $domain) -to 'releng-puppet-mail@mozilla.com' -from $logSender
}}
Move-Item -path $runLog -destination ([IO.Path]::Combine($logDir, ('userdata-run-{{0}}.log' -f [DateTime]::Now.ToString("yyyyMMdd-HHmm"))))-ErrorAction SilentlyContinue
Move-Item -path $ec2Log -destination ([IO.Path]::Combine($logDir, ('ec2config-run-{{0}}.log' -f [DateTime]::Now.ToString("yyyyMMdd-HHmm"))))-ErrorAction SilentlyContinue
</powershell>
<persist>true</persist>
<mozuserdata>
# see bug 1243421
hostname: {fqdn}
moz_instance_type: {moz_instance_type}
</mozuserdata>