|
|
@@ -638,3 +638,38 @@ func serviceVersionSwitchHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
json.NewEncoder(w).Encode(VersionResp{Status: "ok"})
|
|
|
}
|
|
|
+
|
|
|
+func downloadUpgradeLog(w http.ResponseWriter, r *http.Request) {
|
|
|
+ if r.Method != http.MethodGet {
|
|
|
+ http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ filename := fmt.Sprintf("upgrade.log.%s.tar.gz", time.Now().Format("20060102150405"))
|
|
|
+ tmpFile := fmt.Sprintf("/tmp/%d.tar.gz", time.Now().UnixNano())
|
|
|
+
|
|
|
+ defer os.Remove(tmpFile)
|
|
|
+
|
|
|
+ cmd := exec.Command(
|
|
|
+ "tar",
|
|
|
+ "--warning=no-file-changed",
|
|
|
+ "-czf",
|
|
|
+ tmpFile,
|
|
|
+ "-C",
|
|
|
+ "/opt/yfkj/upgrade.service/log",
|
|
|
+ ".",
|
|
|
+ )
|
|
|
+
|
|
|
+ out, err := cmd.CombinedOutput()
|
|
|
+ if err != nil {
|
|
|
+ if exitErr, ok := err.(*exec.ExitError); !ok || exitErr.ExitCode() != 1 {
|
|
|
+ http.Error(w, string(out), http.StatusInternalServerError)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ w.Header().Set("Content-Type", "application/gzip")
|
|
|
+ w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, filename))
|
|
|
+
|
|
|
+ http.ServeFile(w, r, tmpFile)
|
|
|
+}
|