// ExitAgent removes the pid file and exits the process with the given exit code. func ExitAgent(logger *comm.StreamLogger, exitCode int, pidFile string) { err := os.Remove(pidFile) if err != nil { if logger != nil { logger.LogLocal(slogger.ERROR, "Error removing .pid file: %v", err) logger.Flush() } else { fmt.Printf("Error removing .pid file: %v", err) } // exit with code 2 to indicate pid file removal error os.Exit(2) } os.Exit(exitCode) }