summaryrefslogtreecommitdiffstats
path: root/modules/private
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-07-06 01:07:07 +0100
committerGitHub <noreply@github.com>2020-07-05 20:07:07 -0400
commitc5b08f6d5a73e6ba84da84e804d05a8dd3d651be (patch)
tree7e0f72b9c62b8764d000614714c91a01ebbee223 /modules/private
parent38fb087d1983ca8320fb1a8c90150ae7956b358d (diff)
downloadgitea-c5b08f6d5a73e6ba84da84e804d05a8dd3d651be.tar.gz
gitea-c5b08f6d5a73e6ba84da84e804d05a8dd3d651be.zip
Pause, Resume, Release&Reopen, Add and Remove Logging from command line (#11777)
* Make LogDescriptions race safe * Add manager commands for pausing, resuming, adding and removing loggers Signed-off-by: Andrew Thornton <art27@cantab.net> * Placate lint * Ensure that file logger is run! * Add support for smtp and conn Signed-off-by: Andrew Thornton <art27@cantab.net> * Add release-and-reopen Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'modules/private')
-rw-r--r--modules/private/manager.go108
1 files changed, 108 insertions, 0 deletions
diff --git a/modules/private/manager.go b/modules/private/manager.go
index 503acf17d6..6c9ec920bb 100644
--- a/modules/private/manager.go
+++ b/modules/private/manager.go
@@ -8,6 +8,7 @@ import (
"encoding/json"
"fmt"
"net/http"
+ "net/url"
"time"
"code.gitea.io/gitea/modules/setting"
@@ -81,3 +82,110 @@ func FlushQueues(timeout time.Duration, nonBlocking bool) (int, string) {
return http.StatusOK, "Flushed"
}
+
+// PauseLogging pauses logging
+func PauseLogging() (int, string) {
+ reqURL := setting.LocalURL + "api/internal/manager/pause-logging"
+
+ req := newInternalRequest(reqURL, "POST")
+ resp, err := req.Response()
+ if err != nil {
+ return http.StatusInternalServerError, fmt.Sprintf("Unable to contact gitea: %v", err.Error())
+ }
+ defer resp.Body.Close()
+
+ if resp.StatusCode != http.StatusOK {
+ return resp.StatusCode, decodeJSONError(resp).Err
+ }
+
+ return http.StatusOK, "Logging Paused"
+}
+
+// ResumeLogging resumes logging
+func ResumeLogging() (int, string) {
+ reqURL := setting.LocalURL + "api/internal/manager/resume-logging"
+
+ req := newInternalRequest(reqURL, "POST")
+ resp, err := req.Response()
+ if err != nil {
+ return http.StatusInternalServerError, fmt.Sprintf("Unable to contact gitea: %v", err.Error())
+ }
+ defer resp.Body.Close()
+
+ if resp.StatusCode != http.StatusOK {
+ return resp.StatusCode, decodeJSONError(resp).Err
+ }
+
+ return http.StatusOK, "Logging Restarted"
+}
+
+// ReleaseReopenLogging releases and reopens logging files
+func ReleaseReopenLogging() (int, string) {
+ reqURL := setting.LocalURL + "api/internal/manager/release-and-reopen-logging"
+
+ req := newInternalRequest(reqURL, "POST")
+ resp, err := req.Response()
+ if err != nil {
+ return http.StatusInternalServerError, fmt.Sprintf("Unable to contact gitea: %v", err.Error())
+ }
+ defer resp.Body.Close()
+
+ if resp.StatusCode != http.StatusOK {
+ return resp.StatusCode, decodeJSONError(resp).Err
+ }
+
+ return http.StatusOK, "Logging Restarted"
+}
+
+// LoggerOptions represents the options for the add logger call
+type LoggerOptions struct {
+ Group string
+ Name string
+ Mode string
+ Config map[string]interface{}
+}
+
+// AddLogger adds a logger
+func AddLogger(group, name, mode string, config map[string]interface{}) (int, string) {
+ reqURL := setting.LocalURL + "api/internal/manager/add-logger"
+
+ req := newInternalRequest(reqURL, "POST")
+ req = req.Header("Content-Type", "application/json")
+ jsonBytes, _ := json.Marshal(LoggerOptions{
+ Group: group,
+ Name: name,
+ Mode: mode,
+ Config: config,
+ })
+ req.Body(jsonBytes)
+ resp, err := req.Response()
+ if err != nil {
+ return http.StatusInternalServerError, fmt.Sprintf("Unable to contact gitea: %v", err.Error())
+ }
+ defer resp.Body.Close()
+
+ if resp.StatusCode != http.StatusOK {
+ return resp.StatusCode, decodeJSONError(resp).Err
+ }
+
+ return http.StatusOK, "Added"
+
+}
+
+// RemoveLogger removes a logger
+func RemoveLogger(group, name string) (int, string) {
+ reqURL := setting.LocalURL + fmt.Sprintf("api/internal/manager/remove-logger/%s/%s", url.PathEscape(group), url.PathEscape(name))
+
+ req := newInternalRequest(reqURL, "POST")
+ resp, err := req.Response()
+ if err != nil {
+ return http.StatusInternalServerError, fmt.Sprintf("Unable to contact gitea: %v", err.Error())
+ }
+ defer resp.Body.Close()
+
+ if resp.StatusCode != http.StatusOK {
+ return resp.StatusCode, decodeJSONError(resp).Err
+ }
+
+ return http.StatusOK, "Removed"
+}