feat(frpc): improve boot service error handling and response
- Add bootServiceError field to system config modify response when boot service operations fail - Include instanceID in list instances response - Update error message for unknown modify type - Document bootServiceError behavior in README
This commit is contained in:
@@ -350,7 +350,7 @@ func ModifyInstanceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if modifyType != "configFile" && modifyType != "systemConfig" { // Detect valid modify type
|
||||
SendErrorResponse(w, http.StatusBadRequest, "type must be 'configFile' or 'systemConfig'")
|
||||
SendErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("Unknown modify type %s", modifyType))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -501,6 +501,7 @@ func handleSystemConfigModify(w http.ResponseWriter, r *http.Request, instance F
|
||||
newRunUser := instance.RunUser
|
||||
newBootAtStart := instance.BootAtStart
|
||||
oldBootAtStart := instance.BootAtStart
|
||||
var bootServiceError string
|
||||
|
||||
if v, ok := modifiedData["name"].(string); ok && v != "" {
|
||||
newName = v
|
||||
@@ -556,27 +557,38 @@ func handleSystemConfigModify(w http.ResponseWriter, r *http.Request, instance F
|
||||
if oldBootAtStart && !newBootAtStart {
|
||||
if err := removeBootService(user.Username, instance.Name); err != nil {
|
||||
postLog.Error(fmt.Sprintf("[handleSystemConfigModify] Failed to remove boot service: %v", err))
|
||||
bootServiceError = fmt.Sprintf("Failed to remove boot service: %v", err)
|
||||
}
|
||||
} else if !oldBootAtStart && newBootAtStart {
|
||||
if err := createBootService(user.Username, newName, newConfigPath, newRunUser); err != nil {
|
||||
postLog.Error(fmt.Sprintf("[handleSystemConfigModify] Failed to create boot service: %v", err))
|
||||
bootServiceError = fmt.Sprintf("Failed to create boot service: %v", err)
|
||||
}
|
||||
} else if oldBootAtStart && newBootAtStart && (instance.Name != newName || instance.RunUser != newRunUser) {
|
||||
if err := removeBootService(user.Username, instance.Name); err != nil {
|
||||
postLog.Error(fmt.Sprintf("[handleSystemConfigModify] Failed to remove old boot service: %v", err))
|
||||
bootServiceError = fmt.Sprintf("Failed to remove old boot service: %v", err)
|
||||
}
|
||||
if err := createBootService(user.Username, newName, newConfigPath, newRunUser); err != nil {
|
||||
postLog.Error(fmt.Sprintf("[handleSystemConfigModify] Failed to create new boot service: %v", err))
|
||||
if bootServiceError != "" {
|
||||
bootServiceError += "; "
|
||||
}
|
||||
bootServiceError += fmt.Sprintf("Failed to create new boot service: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
SendSuccessResponse(w, "System config modified successfully", map[string]interface{}{
|
||||
data := map[string]interface{}{
|
||||
"instanceName": newName,
|
||||
"instanceID": instance.ID,
|
||||
"configPath": newConfigPath,
|
||||
"bootAtStart": newBootAtStart,
|
||||
"runUser": newRunUser,
|
||||
})
|
||||
}
|
||||
if bootServiceError != "" {
|
||||
data["bootServiceError"] = bootServiceError
|
||||
}
|
||||
SendSuccessResponse(w, "System config modified successfully", data)
|
||||
postLog.Info(fmt.Sprintf("[handleSystemConfigModify] System config for instance %s modified successfully: bootAtStart=%v, runUser=%s", newName, newBootAtStart, newRunUser))
|
||||
}
|
||||
|
||||
@@ -614,6 +626,7 @@ func ListInstancesHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var responseInstances []map[string]interface{}
|
||||
for _, instance := range instanceList {
|
||||
instanceData := map[string]interface{}{
|
||||
"instanceID": instance.ID,
|
||||
"name": instance.Name,
|
||||
"serverAddr": instance.ServerAddr,
|
||||
"serverPort": instance.ServerPort,
|
||||
|
||||
Reference in New Issue
Block a user