fix(watchdog): now the client could successfully send more msgs to watchdog instead of the only connection msg
- Add debug logging for watchdog operations - Standardize message format for instance operations - Improve TCP message handling with proper line termination - Enhance error handling in watchdog operations - Add proper cleanup of recvChan in sendMsg - Update response handling in instance handlers
This commit is contained in:
@@ -627,7 +627,11 @@ func StartInstanceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if is.watchdogConnected {
|
||||
watchdog.AddInstance(serviceName)
|
||||
if !watchdog.AddInstance(serviceName) {
|
||||
postLog.Warning(fmt.Sprintf("[StartInstanceHandler] Failed to add watchdog instance %s", serviceName))
|
||||
SendSuccessResponse(w, "Instance started successfully but watchdog instance add failed", nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
SendSuccessResponse(w, "Instance started successfully", nil)
|
||||
@@ -702,7 +706,7 @@ func StopInstanceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
postLog.Info(fmt.Sprintf("[StopInstanceHandler] Windows service %s stopped successfully", serviceName))
|
||||
SendSuccessResponse(w, "Instance stopped successfully", nil)
|
||||
// SendSuccessResponse(w, "Instance stopped successfully", nil)
|
||||
|
||||
case "systemd":
|
||||
if err := StopSystemdService(serviceName); err != nil {
|
||||
@@ -711,7 +715,7 @@ func StopInstanceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
postLog.Info(fmt.Sprintf("[StopInstanceHandler] Systemd service %s stopped successfully", serviceName))
|
||||
SendSuccessResponse(w, "Instance stopped successfully", nil)
|
||||
// SendSuccessResponse(w, "Instance stopped successfully", nil)
|
||||
|
||||
case "init.d":
|
||||
if err := StopInitDService(serviceName); err != nil {
|
||||
@@ -720,13 +724,22 @@ func StopInstanceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
postLog.Info(fmt.Sprintf("[StopInstanceHandler] Init.d service %s stopped successfully", serviceName))
|
||||
SendSuccessResponse(w, "Instance stopped successfully", nil)
|
||||
// SendSuccessResponse(w, "Instance stopped successfully", nil)
|
||||
|
||||
default:
|
||||
postLog.Error(fmt.Sprintf("[StopInstanceHandler] Unsupported init system: %s", initType))
|
||||
SendErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("Unsupported init system: %s", initType))
|
||||
return
|
||||
}
|
||||
|
||||
if is.watchdogConnected {
|
||||
if !watchdog.RemoveInstance(serviceName) {
|
||||
postLog.Warning(fmt.Sprintf("[StopInstanceHandler] Failed to remove watchdog instance %s", serviceName))
|
||||
SendSuccessResponse(w, "Instance stopped successfully but watchdog instance remove failed", nil)
|
||||
} else {
|
||||
SendSuccessResponse(w, "Instance stopped successfully", nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func RestartInstanceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user