| 187 | } |
| 188 | |
| 189 | func sendSuspendRequest(port string, udsListener net.Listener) (err error) { |
| 190 | var ( |
| 191 | req *http.Request |
| 192 | resp *http.Response |
| 193 | data []byte |
| 194 | ) |
| 195 | udsFilePath := udsListener.Addr().String() |
| 196 | |
| 197 | url := fmt.Sprintf("http://%s:%s/suspend?sock=%s", DefaultIP, port, udsFilePath) |
| 198 | if req, err = http.NewRequest("POST", url, nil); err != nil { |
| 199 | log.LogErrorf("Failed to get new request: %v\n", err) |
| 200 | return err |
| 201 | } |
| 202 | req.Header.Set("Content-Type", "application/text") |
| 203 | |
| 204 | client := http.DefaultClient |
| 205 | client.Timeout = 120 * time.Second |
| 206 | if resp, err = client.Do(req); err != nil { |
| 207 | log.LogErrorf("Failed to post request: %v\n", err) |
| 208 | return err |
| 209 | } |
| 210 | defer resp.Body.Close() |
| 211 | |
| 212 | if data, err = io.ReadAll(resp.Body); err != nil { |
| 213 | log.LogErrorf("Failed to read response: %v\n", err) |
| 214 | return err |
| 215 | } |
| 216 | |
| 217 | if resp.StatusCode == http.StatusOK { |
| 218 | log.LogInfof("\n==> %s\n==> Could restore cfs-client now with -r option.\n\n", string(data)) |
| 219 | } else { |
| 220 | log.LogErrorf("\n==> %s\n==> Status: %s\n\n", string(data), resp.Status) |
| 221 | return fmt.Errorf(resp.Status) |
| 222 | } |
| 223 | |
| 224 | return nil |
| 225 | } |
| 226 | |
| 227 | func sendResumeRequest(port string) (err error) { |
| 228 | var ( |