in cmd/xray-migration/xray-migration.go [20:92]
func main() {
//downtime flag so user can configure their downtime before calling the migration tool.
downTime := flag.Int("downTime", 5, "Set Daemon restart delay on CloudWatch failure. Note: trace data in this interval might be lost")
flag.Parse()
fmt.Printf("If the Cloudwatch agent doesn’t start within %v seconds, the X-ray daemon will restart. While the CloudWatch agent is starting, trace data generated during that time is lost.\n", *downTime)
var userInput string
fmt.Println("Enter 0 to cancel and exit, or enter a different number of seconds to wait for the CloudWatch agent to start (minimum of 2 seconds). Any trace data generated while waiting for the CloudWatch agent to start is lost.")
fmt.Scanln(&userInput)
var timeOut int
var err error
//assigning timeout duration
if userInput == "" {
//make sure downtime is at least 2 seconds
if *downTime < 2 {
timeOut = 2
} else {
timeOut = *downTime
}
} else {
timeOut, err = strconv.Atoi(userInput)
if err != nil {
fmt.Println("Input given is not a number", err)
os.Exit(1)
}
if timeOut == 0 {
os.Exit(1)
}
}
processes, _ := xraydaemonmigration.FindAllDaemons()
//Can not migrate if Daemon is not running
if len(processes) == 0 {
fmt.Println("X-Ray Daemon is not running")
return
}
//Before running wizard need to know if we need to use the user current configuration
fetchOrAppend := configExists(defaultConfigLocation)
err = RunWizard(fetchOrAppend)
if err != nil {
fmt.Println("There was a problem trying to run config wizard", err)
os.Exit(1)
}
//Save Daemon Information before shutting down for restart Daemon function
argList, _ := processes[0].CmdlineSlice()
cwd, _ := processes[0].Cwd()
isService := checkXrayStatus()
err = TerminateXray(processes[0], checkXrayStatus)
if err != nil {
fmt.Println("There was a problem terminating X-Ray Daemon: ", err)
os.Exit(1)
}
//Call Fetch or Append config depending on if user already has Daemon configuration
if fetchOrAppend == Fetch {
err = FetchConfig()
} else {
err = AppendConfig()
}
//need to restart Daemon if Fetch/Append does not work or CWA does not start within the timeout duration
if err != nil || !IsCWAOn(time.Duration(timeOut)*time.Second, checkCWAStatus) {
fmt.Println("There was a problem starting the Cloudwatch Agent. Restarting X-Ray Daemon")
err := restartDaemon(argList[0], argList[1:], cwd, isService)
if err != nil {
fmt.Println("Could not restart X-Ray Daemon: ", err)
return
} else {
fmt.Println("X-Ray Daemon has been restarted")
return
}
} else {
fmt.Println("Cloudwatch Agent has started and it is running traces!")
}
}