in cache-config/t3c-apply/torequest/torequest.go [1143:1255]
func (r *TrafficOpsReq) StartServices(syncdsUpdate *UpdateStatus, metaData *t3cutil.ApplyMetaData, cfg config.Cfg) error {
serviceNeeds := t3cutil.ServiceNeedsNothing
if r.Cfg.ServiceAction == t3cutil.ApplyServiceActionFlagRestart {
serviceNeeds = t3cutil.ServiceNeedsRestart
} else {
err := error(nil)
if serviceNeeds, err = checkReload(r.changedFiles); err != nil {
return errors.New("determining if service needs restarted - not reloading or restarting! : " + err.Error())
}
}
log.Infof("t3c-check-reload returned '%+v'\n", serviceNeeds)
// We have our own internal knowledge of files that have been modified as well
// If check-reload does not know about these and we do, then we should initiate
// a reload as well
if serviceNeeds != t3cutil.ServiceNeedsRestart && serviceNeeds != t3cutil.ServiceNeedsReload {
if r.TrafficCtlReload || r.RemapConfigReload || r.VarnishReload {
log.Infof("ATS config files unchanged, we updated files via t3c-apply, ATS needs reload")
serviceNeeds = t3cutil.ServiceNeedsReload
}
}
packageName := "trafficserver"
if cfg.CacheType == "varnish" {
packageName = "varnish"
}
if (serviceNeeds == t3cutil.ServiceNeedsRestart || serviceNeeds == t3cutil.ServiceNeedsReload) && !r.IsPackageInstalled(packageName) {
// TODO try to reload/restart anyway? To allow non-RPM installs?
return errors.New(packageName + " needs " + serviceNeeds.String() + " but is not installed.")
}
svcStatus, _, err := util.GetServiceStatus(packageName)
if err != nil {
return errors.New("getting trafficserver service status: " + err.Error())
}
if r.Cfg.ReportOnly {
if serviceNeeds == t3cutil.ServiceNeedsRestart {
log.Errorln("ATS configuration has changed. The new config will be picked up the next time ATS is started.")
} else if serviceNeeds == t3cutil.ServiceNeedsReload {
log.Errorln("ATS configuration has changed. 'traffic_ctl config reload' needs to be run")
}
return nil
} else if r.Cfg.ServiceAction == t3cutil.ApplyServiceActionFlagRestart {
startStr := "restart"
if svcStatus != util.SvcRunning {
startStr = "start"
}
if _, err := util.ServiceStart(packageName, startStr); err != nil {
t3cutil.WriteActionLog(t3cutil.ActionLogActionATSRestart, t3cutil.ActionLogStatusFailure, metaData)
return errors.New("failed to restart trafficserver")
}
t3cutil.WriteActionLog(t3cutil.ActionLogActionATSRestart, t3cutil.ActionLogStatusSuccess, metaData)
log.Infoln("trafficserver has been " + startStr + "ed")
if !r.Cfg.NoConfirmServiceAction {
log.Infoln("confirming ATS restart succeeded")
if err := doTail(r.Cfg, TailDiagsLogRelative, ".*", tailRestartEnd, TailRestartTimeOutMS); err != nil {
log.Errorln("error running tail")
}
} else {
log.Infoln("skipping ATS restart success confirmation")
}
if *syncdsUpdate == UpdateTropsNeeded {
*syncdsUpdate = UpdateTropsSuccessful
}
return nil // we restarted, so no need to reload
} else if r.Cfg.ServiceAction == t3cutil.ApplyServiceActionFlagReload {
if serviceNeeds == t3cutil.ServiceNeedsRestart {
if *syncdsUpdate == UpdateTropsNeeded {
*syncdsUpdate = UpdateTropsSuccessful
}
log.Errorln("ATS configuration has changed. The new config will be picked up the next time ATS is started.")
} else if serviceNeeds == t3cutil.ServiceNeedsReload {
log.Infoln("ATS configuration has changed, Running 'traffic_ctl config reload' now.")
reloadCommand := config.TSHome + config.TrafficCtl
reloadArgs := []string{"config", "reload"}
if cfg.CacheType == "varnish" {
reloadCommand = "/usr/sbin/varnishreload"
reloadArgs = []string{}
}
if _, _, err := util.ExecCommand(reloadCommand, reloadArgs...); err != nil {
t3cutil.WriteActionLog(t3cutil.ActionLogActionATSReload, t3cutil.ActionLogStatusFailure, metaData)
if *syncdsUpdate == UpdateTropsNeeded {
*syncdsUpdate = UpdateTropsFailed
}
return errors.New("ATS configuration has changed and 'traffic_ctl config reload' failed, check ATS logs: " + err.Error())
}
t3cutil.WriteActionLog(t3cutil.ActionLogActionATSReload, t3cutil.ActionLogStatusSuccess, metaData)
if *syncdsUpdate == UpdateTropsNeeded {
*syncdsUpdate = UpdateTropsSuccessful
}
log.Infoln("ATS 'traffic_ctl config reload' was successful")
if !r.Cfg.NoConfirmServiceAction {
log.Infoln("confirming ATS reload succeeded")
if err := doTail(r.Cfg, TailDiagsLogRelative, tailMatch, tailReloadEnd, TailReloadTimeOutMS); err != nil {
log.Errorln("error running tail: ", err)
}
} else {
log.Infoln("skipping ATS reload success confirmation")
}
}
if *syncdsUpdate == UpdateTropsNeeded {
*syncdsUpdate = UpdateTropsSuccessful
}
return nil
}
return nil
}