File tree 5 files changed +50
-3
lines changed
5 files changed +50
-3
lines changed Original file line number Diff line number Diff line change 21
21
Subcommands : []cli.Command {
22
22
subcmdShutdown ,
23
23
subcmdRestart ,
24
+ subcmdReloadTemplates ,
24
25
subcmdFlushQueues ,
25
26
subcmdLogging ,
26
27
subCmdProcesses ,
46
47
},
47
48
Action : runRestart ,
48
49
}
50
+ subcmdReloadTemplates = cli.Command {
51
+ Name : "reload-templates" ,
52
+ Usage : "Reload template files in the running process" ,
53
+ Flags : []cli.Flag {
54
+ cli.BoolFlag {
55
+ Name : "debug" ,
56
+ },
57
+ },
58
+ Action : runReloadTemplates ,
59
+ }
49
60
subcmdFlushQueues = cli.Command {
50
61
Name : "flush-queues" ,
51
62
Usage : "Flush queues in the running process" ,
@@ -115,6 +126,15 @@ func runRestart(c *cli.Context) error {
115
126
return handleCliResponseExtra (extra )
116
127
}
117
128
129
+ func runReloadTemplates (c * cli.Context ) error {
130
+ ctx , cancel := installSignals ()
131
+ defer cancel ()
132
+
133
+ setup (ctx , c .Bool ("debug" ))
134
+ extra := private .ReloadTemplates (ctx )
135
+ return handleCliResponseExtra (extra )
136
+ }
137
+
118
138
func runFlushQueues (c * cli.Context ) error {
119
139
ctx , cancel := installSignals ()
120
140
defer cancel ()
Original file line number Diff line number Diff line change @@ -29,6 +29,13 @@ func Restart(ctx context.Context) ResponseExtra {
29
29
return requestJSONClientMsg (req , "Restarting" )
30
30
}
31
31
32
+ // ReloadTemplates calls the internal reload-templates function
33
+ func ReloadTemplates (ctx context.Context ) ResponseExtra {
34
+ reqURL := setting .LocalURL + "api/internal/manager/reload-templates"
35
+ req := newInternalRequest (ctx , reqURL , "POST" )
36
+ return requestJSONClientMsg (req , "Reloaded" )
37
+ }
38
+
32
39
// FlushOptions represents the options for the flush call
33
40
type FlushOptions struct {
34
41
Timeout time.Duration
Original file line number Diff line number Diff line change @@ -96,6 +96,14 @@ func HTMLRenderer() *HTMLRender {
96
96
return htmlRender
97
97
}
98
98
99
+ func ReloadHTMLTemplates () error {
100
+ if err := htmlRender .CompileTemplates (); err != nil {
101
+ log .Error ("Template error: %v\n %s" , err , log .Stack (2 ))
102
+ return err
103
+ }
104
+ return nil
105
+ }
106
+
99
107
func initHTMLRenderer () {
100
108
rendererType := "static"
101
109
if ! setting .IsProd {
@@ -115,9 +123,7 @@ func initHTMLRenderer() {
115
123
116
124
if ! setting .IsProd {
117
125
go AssetFS ().WatchLocalChanges (graceful .GetManager ().ShutdownContext (), func () {
118
- if err := htmlRender .CompileTemplates (); err != nil {
119
- log .Error ("Template error: %v\n %s" , err , log .Stack (2 ))
120
- }
126
+ _ = ReloadHTMLTemplates ()
121
127
})
122
128
}
123
129
}
Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ func Routes() *web.Route {
67
67
r .Get ("/serv/command/{keyid}/{owner}/{repo}" , ServCommand )
68
68
r .Post ("/manager/shutdown" , Shutdown )
69
69
r .Post ("/manager/restart" , Restart )
70
+ r .Post ("/manager/reload-templates" , ReloadTemplates )
70
71
r .Post ("/manager/flush-queues" , bind (private.FlushOptions {}), FlushQueues )
71
72
r .Post ("/manager/pause-logging" , PauseLogging )
72
73
r .Post ("/manager/resume-logging" , ResumeLogging )
Original file line number Diff line number Diff line change @@ -15,9 +15,22 @@ import (
15
15
"code.gitea.io/gitea/modules/private"
16
16
"code.gitea.io/gitea/modules/queue"
17
17
"code.gitea.io/gitea/modules/setting"
18
+ "code.gitea.io/gitea/modules/templates"
18
19
"code.gitea.io/gitea/modules/web"
19
20
)
20
21
22
+ // ReloadTemplates reloads all the templates
23
+ func ReloadTemplates (ctx * context.PrivateContext ) {
24
+ err := templates .ReloadHTMLTemplates ()
25
+ if err != nil {
26
+ ctx .JSON (http .StatusInternalServerError , private.Response {
27
+ UserMsg : fmt .Sprintf ("Template error: %v" , err ),
28
+ })
29
+ return
30
+ }
31
+ ctx .PlainText (http .StatusOK , "success" )
32
+ }
33
+
21
34
// FlushQueues flushes all the Queues
22
35
func FlushQueues (ctx * context.PrivateContext ) {
23
36
opts := web .GetForm (ctx ).(* private.FlushOptions )
You can’t perform that action at this time.
0 commit comments