Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 40 additions & 48 deletions cache-config/t3c-apply/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,146 +50,138 @@ Typical usage is to install t3c on the cache machine, and then run it periodical

# OPTIONS

-2, --default-client-enable-h2
-2, -\-default-client-enable-h2

Whether to enable HTTP/2 on Delivery Services by default, if
they have no explicit Parameter. This is irrelevant if ATS
records.config is not serving H2. If omitted, H2 is
disabled.

-b, --dns-local-bind
-b, -\-dns-local-bind

[true | false] whether to use the server's Service Addresses
to set the ATS DNS local bind address

-c, --disable-parent-config-comments
-c, -\-disable-parent-config-comments

Whether to disable verbose parent.config comments. Default
false.

-D, --dispersion=value
-D, -\-dispersion=value

[seconds] wait a random number of seconds between 0 and
[seconds] before starting, default 300 [300]

-d, --log-location-debug=value

Where to log debugs. May be a file path, stdout, stderr, or
null, default ''

-e, --log-location-error=value

Where to log errors. May be a file path, stdout, stderr, or
null, default stderr [stderr]

-g, --git=value
-g, -\-git=value

Create and use a git repo in the config directory. Options
are yes, no, and auto. If yes, create and use. If auto, use
if it exist. Default is auto. [auto]

-H, --cache-host-name=value
-H, -\-cache-host-name=value

Host name of the cache to generate config for. Must be the
server host name in Traffic Ops, not a URL, and not the FQDN

-h, --help
-h, -\-help

Print usage information and exit

-i, --log-location-info=value

Where to log info. May be a file path, stdout, stderr, or
null, default stderr [stderr]

-I, --traffic-ops-insecure
-I, -\-traffic-ops-insecure

[true | false] ignore certificate errors from Traffic Ops

-l, --login-dispersion=value
-l, -\-login-dispersion=value

[seconds] wait a random number of seconds between 0 and
[seconds] before login to traffic ops, default 0

-M, --maxmind-location=value
-M, -\-maxmind-location=value

URL of a maxmind gzipped database file, to be installed into
the trafficserver etc directory.

-m, --run-mode=value
-m, -\-run-mode=value

[badass | report | revalidate | syncds] run mode, default is
'report' [report]

-p, --reverse-proxy-disable
-o, -\-omit-via-string-release

Whether to set the records.config via header to the ATS
release from the RPM. Default true.

-O, -\-skip-os-check

[false | true] skip os check, default is false

-p, -\-reverse-proxy-disable

[false | true] bypass the reverse proxy even if one has been
configured default is false

-P, --traffic-ops-password=value
-P, -\-traffic-ops-password=value

Traffic Ops password. Required. May also be set with the
environment variable TO_PASS

-r, --num-retries=value
-r, -\-num-retries=value

[number] retry connection to Traffic Ops URL [number] times,
default is 3 [3]

-R, --trafficserver-home=value
-R, -\-trafficserver-home=value

Trafficserver Package directory. May also be set with the
environment variable TS_HOME

-s, --skip-os-check
-s, -\-silent

[false | true] skip os check, default is false
Silent. Errors are not logged, and the 'verbose' flag is
ignored. If a fatal error occurs, the return code will be
non-zero but no text will be output to stderr

-S, --syncds-updates-ipallow
-S, -\-syncds-updates-ipallow

Whether syncds mode will update ipallow. This exists because
ATS had a bug where reloading after changing ipallow would
block everything. Default is false.

-T, --reval-wait-time=value
-T, -\-reval-wait-time=value

[seconds] wait a random number of seconds between 0 and
[seconds] before revlidation, default is 60 [60]

-t, --traffic-ops-timeout-milliseconds=value
-t, -\-traffic-ops-timeout-milliseconds=value

Timeout in milli-seconds for Traffic Ops requests, default
is 30000 [30000]

-u, --traffic-ops-url=value
-u, -\-traffic-ops-url=value

Traffic Ops URL. Must be the full URL, including the scheme.
Required. May also be set with the environment variable
TO_URL

-U, --traffic-ops-user=value
-U, -\-traffic-ops-user=value

Traffic Ops username. Required. May also be set with the
environment variable TO_USER

-V, --default-client-tls-versions=value
-V, -\-default-client-tls-versions=value

Comma-delimited list of default TLS versions for Delivery
Services with no Parameter, e.g.
--default-tls-versions='1.1,1.2,1.3'. If omitted, all
-\-default-tls-versions='1.1,1.2,1.3'. If omitted, all
versions are enabled.

-v, --omit-via-string-release

Whether to set the records.config via header to the ATS
release from the RPM. Default true.

-w, --log-location-warning=value
-v, -\-verbose

Where to log warnings. May be a file path, stdout, stderr,
or null, default stderr [stderr]
Log verbosity. Logging is output to stderr. By default,
errors are logged. To log warnings, pass '-v'. To log info,
pass '-vv'. To omit error logging, see '-s'.

-W, --wait-for-parents
-W, -\-wait-for-parents

[true | false | reval] do not update if parent_pending = 1 in the
update json. Default is 'reval', wait for parents in revalidate
Expand Down
34 changes: 24 additions & 10 deletions cache-config/t3c-apply/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,12 @@ func GetCfg() (Cfg, error) {

dispersionPtr := getopt.IntLong("dispersion", 'D', 300, "[seconds] wait a random number of seconds between 0 and [seconds] before starting, default 300")
loginDispersionPtr := getopt.IntLong("login-dispersion", 'l', 0, "[seconds] wait a random number of seconds between 0 and [seconds] before login to traffic ops, default 0")
logLocationDebugPtr := getopt.StringLong("log-location-debug", 'd', "", "Where to log debugs. May be a file path, stdout, stderr, or null, default ''")
logLocationErrorPtr := getopt.StringLong("log-location-error", 'e', "stderr", "Where to log errors. May be a file path, stdout, stderr, or null, default stderr")
logLocationInfoPtr := getopt.StringLong("log-location-info", 'i', "stderr", "Where to log info. May be a file path, stdout, stderr, or null, default stderr")
logLocationWarnPtr := getopt.StringLong("log-location-warning", 'w', "stderr", "Where to log warnings. May be a file path, stdout, stderr, or null, default stderr")
cacheHostNamePtr := getopt.StringLong("cache-host-name", 'H', "", "Host name of the cache to generate config for. Must be the server host name in Traffic Ops, not a URL, and not the FQDN")
retriesPtr := getopt.IntLong("num-retries", 'r', 3, "[number] retry connection to Traffic Ops URL [number] times, default is 3")
revalWaitTimePtr := getopt.IntLong("reval-wait-time", 'T', 60, "[seconds] wait a random number of seconds between 0 and [seconds] before revlidation, default is 60")
reverseProxyDisablePtr := getopt.BoolLong("reverse-proxy-disable", 'p', "[false | true] bypass the reverse proxy even if one has been configured default is false")
runModePtr := getopt.StringLong("run-mode", 'm', "report", "[badass | report | revalidate | syncds] run mode, default is 'report'")
skipOSCheckPtr := getopt.BoolLong("skip-os-check", 's', "[false | true] skip os check, default is false")
skipOSCheckPtr := getopt.BoolLong("skip-os-check", 'O', "[false | true] skip os check, default is false")
toInsecurePtr := getopt.BoolLong("traffic-ops-insecure", 'I', "[true | false] ignore certificate errors from Traffic Ops")
toTimeoutMSPtr := getopt.IntLong("traffic-ops-timeout-milliseconds", 't', 30000, "Timeout in milli-seconds for Traffic Ops requests, default is 30000")
toURLPtr := getopt.StringLong("traffic-ops-url", 'u', "", "Traffic Ops URL. Must be the full URL, including the scheme. Required. May also be set with the environment variable TO_URL")
Expand All @@ -232,20 +228,38 @@ func GetCfg() (Cfg, error) {
helpPtr := getopt.BoolLong("help", 'h', "Print usage information and exit")
useGitStr := getopt.StringLong("git", 'g', "auto", "Create and use a git repo in the config directory. Options are yes, no, and auto. If yes, create and use. If auto, use if it exist. Default is auto.")
syncdsUpdatesIPAllowPtr := getopt.BoolLong("syncds-updates-ipallow", 'S', "Whether syncds mode will update ipallow. This exists because ATS had a bug where reloading after changing ipallow would block everything. Default is false.")
omitViaStringReleasePtr := getopt.BoolLong("omit-via-string-release", 'v', "Whether to set the records.config via header to the ATS release from the RPM. Default true.")
omitViaStringReleasePtr := getopt.BoolLong("omit-via-string-release", 'o', "Whether to set the records.config via header to the ATS release from the RPM. Default true.")
disableParentConfigCommentsPtr := getopt.BoolLong("disable-parent-config-comments", 'c', "Whether to disable verbose parent.config comments. Default false.")
defaultEnableH2 := getopt.BoolLong("default-client-enable-h2", '2', "Whether to enable HTTP/2 on Delivery Services by default, if they have no explicit Parameter. This is irrelevant if ATS records.config is not serving H2. If omitted, H2 is disabled.")
defaultClientTLSVersions := getopt.StringLong("default-client-tls-versions", 'V', "", "Comma-delimited list of default TLS versions for Delivery Services with no Parameter, e.g. --default-tls-versions='1.1,1.2,1.3'. If omitted, all versions are enabled.")
maxmindLocationPtr := getopt.StringLong("maxmind-location", 'M', "", "URL of a maxmind gzipped database file, to be installed into the trafficserver etc directory.")
verbosePtr := getopt.CounterLong("verbose", 'v', `Log verbosity. Logging is output to stderr. By default, errors are logged. To log warnings, pass '-v'. To log info, pass '-vv'. To omit error logging, see '-s'`)
silentPtr := getopt.BoolLong("silent", 's', `Silent. Errors are not logged, and the 'verbose' flag is ignored. If a fatal error occurs, the return code will be non-zero but no text will be output to stderr`)

getopt.Parse()

dispersion := time.Second * time.Duration(*dispersionPtr)
loginDispersion := time.Second * time.Duration(*loginDispersionPtr)
logLocationDebug := *logLocationDebugPtr
logLocationError := *logLocationErrorPtr
logLocationInfo := *logLocationInfoPtr
logLocationWarn := *logLocationWarnPtr

logLocationError := log.LogLocationStderr
logLocationWarn := log.LogLocationNull
logLocationInfo := log.LogLocationNull
logLocationDebug := log.LogLocationNull
if *silentPtr {
logLocationError = log.LogLocationNull
} else {
if *verbosePtr >= 1 {
logLocationWarn = log.LogLocationStderr
}
if *verbosePtr >= 2 {
logLocationInfo = log.LogLocationStderr
logLocationDebug = log.LogLocationStderr // t3c only has 3 verbosity options: none (-s), error (default or --verbose=0), warning (-v), and info (-vv). Any code calling log.Debug is treated as Info.
}
}

if *verbosePtr > 2 {
return Cfg{}, errors.New("Too many verbose options. The maximum log verbosity level is 2 (-vv or --verbose=2) for errors (0), warnings (1), and info (2)")
}

var cacheHostName string
if len(*cacheHostNamePtr) > 0 {
Expand Down
2 changes: 2 additions & 0 deletions cache-config/t3c-apply/t3c-apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ func main() {

// create and clean the config.TmpBase (/tmp/ort)
if !util.MkDir(config.TmpBase, cfg) {
log.Errorln("mkdir TmpBase '" + config.TmpBase + "' failed, cannot continue")
os.Exit(GeneralFailure)
} else if !util.CleanTmpDir(cfg) {
log.Errorln("CleanTmpDir failed, cannot continue")
os.Exit(GeneralFailure)
}
if cfg.RunMode != t3cutil.ModeReport {
Expand Down
75 changes: 58 additions & 17 deletions cache-config/t3c-apply/torequest/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,19 @@ func generate(cfg config.Cfg) ([]t3cutil.ATSConfigFile, error) {
return nil, errors.New("requesting: " + err.Error())
}
args := []string{
"--log-location-error=" + outToErr(cfg.LogLocationErr),
"--log-location-info=" + outToErr(cfg.LogLocationInfo),
"--log-location-warning=" + outToErr(cfg.LogLocationWarn),
"--dir=" + config.TSConfigDir,
}

if cfg.LogLocationErr == log.LogLocationNull {
args = append(args, "-s")
}
if cfg.LogLocationWarn != log.LogLocationNull {
args = append(args, "-v")
}
if cfg.LogLocationInfo != log.LogLocationNull {
args = append(args, "-v")
}

if cfg.DNSLocalBind {
args = append(args, "--dns-local-bind")
}
Expand Down Expand Up @@ -93,10 +101,16 @@ func generate(cfg config.Cfg) ([]t3cutil.ATSConfigFile, error) {

// preprocess takes the to Data from 't3c-request --get-data=config' and the generated files from 't3c-generate', passes them to `t3c-preprocess`, and returns the result.
func preprocess(cfg config.Cfg, configData []byte, generatedFiles []byte) ([]byte, error) {
args := []string{
"--log-location-error=" + outToErr(cfg.LogLocationErr),
"--log-location-info=" + outToErr(cfg.LogLocationInfo),
"--log-location-warning=" + outToErr(cfg.LogLocationWarn),
args := []string{}

if cfg.LogLocationErr == log.LogLocationNull {
args = append(args, "-s")
}
if cfg.LogLocationWarn != log.LogLocationNull {
args = append(args, "-v")
}
if cfg.LogLocationInfo != log.LogLocationNull {
args = append(args, "-v")
}

cmd := exec.Command(`t3c-preprocess`, args...)
Expand Down Expand Up @@ -203,12 +217,21 @@ func sendUpdate(cfg config.Cfg, updateStatus bool, revalStatus bool) error {
"--traffic-ops-password=" + cfg.TOPass,
"--traffic-ops-url=" + cfg.TOURL,
"--traffic-ops-insecure=" + strconv.FormatBool(cfg.TOInsecure),
"--log-location-error=" + outToErr(cfg.LogLocationErr),
"--log-location-info=" + outToErr(cfg.LogLocationInfo),
"--cache-host-name=" + cfg.CacheHostName,
"--set-update-status=" + strconv.FormatBool(updateStatus),
"--set-reval-status=" + strconv.FormatBool(revalStatus),
}

if cfg.LogLocationErr == log.LogLocationNull {
args = append(args, "-s")
}
if cfg.LogLocationWarn != log.LogLocationNull {
args = append(args, "-v")
}
if cfg.LogLocationInfo != log.LogLocationNull {
args = append(args, "-v")
}

if _, used := os.LookupEnv("TO_USER"); !used {
args = append(args, "--traffic-ops-user="+cfg.TOUser)
}
Expand Down Expand Up @@ -261,12 +284,21 @@ func diff(cfg config.Cfg, newFile []byte, fileLocation string) (bool, error) {
// The cfgFile should be the full text of either a plugin.config or remap.config.
// Returns nil if t3c-check-refs returned no errors found, or the error found if any.
func checkRefs(cfg config.Cfg, cfgFile []byte, filesAdding []string) error {
stdOut, stdErr, code := t3cutil.DoInput(cfgFile, `t3c`, `check`, `refs`,
"--log-location-error="+outToErr(cfg.LogLocationErr),
"--log-location-info="+outToErr(cfg.LogLocationInfo),
"--log-location-debug="+outToErr(cfg.LogLocationDebug),
"--files-adding="+strings.Join(filesAdding, ","),
)
args := []string{`check`, `refs`,
"--files-adding=" + strings.Join(filesAdding, ","),
}
if cfg.LogLocationErr == log.LogLocationNull {
args = append(args, "-s")
}
if cfg.LogLocationWarn != log.LogLocationNull {
args = append(args, "-v")
}
if cfg.LogLocationInfo != log.LogLocationNull {
args = append(args, "-v")
}

stdOut, stdErr, code := t3cutil.DoInput(cfgFile, `t3c`, args...)

if code != 0 {
log.Errorf(`check-refs errors start
` + string(stdOut))
Expand Down Expand Up @@ -338,10 +370,19 @@ func request(cfg config.Cfg, command string) ([]byte, error) {
"--traffic-ops-insecure=" + strconv.FormatBool(cfg.TOInsecure),
"--traffic-ops-timeout-milliseconds=" + strconv.FormatInt(int64(cfg.TOTimeoutMS), 10),
"--cache-host-name=" + cfg.CacheHostName,
"--log-location-error=" + outToErr(cfg.LogLocationErr),
"--log-location-info=" + outToErr(cfg.LogLocationInfo),
`--get-data=` + command,
}

if cfg.LogLocationErr == log.LogLocationNull {
args = append(args, "-s")
}
if cfg.LogLocationWarn != log.LogLocationNull {
args = append(args, "-v")
}
if cfg.LogLocationInfo != log.LogLocationNull {
args = append(args, "-v")
}

if _, used := os.LookupEnv("TO_USER"); !used {
args = append(args, "--traffic-ops-user="+cfg.TOUser)
}
Expand Down
Loading