@@ -101,6 +101,98 @@ func createPIDFile(pidPath string) {
101
101
}
102
102
}
103
103
104
+ func serveInstall (ctx * cli.Context ) error {
105
+ log .Info ("Gitea version: %s%s" , setting .AppVer , setting .AppBuiltWith )
106
+ log .Info ("App path: %s" , setting .AppPath )
107
+ log .Info ("Work path: %s" , setting .AppWorkPath )
108
+ log .Info ("Custom path: %s" , setting .CustomPath )
109
+ log .Info ("Config file: %s" , setting .CustomConf )
110
+ log .Info ("Prepare to run install page" )
111
+
112
+ routers .InitWebInstallPage (graceful .GetManager ().HammerContext ())
113
+
114
+ // Flag for port number in case first time run conflict
115
+ if ctx .IsSet ("port" ) {
116
+ if err := setPort (ctx .String ("port" )); err != nil {
117
+ return err
118
+ }
119
+ }
120
+ if ctx .IsSet ("install-port" ) {
121
+ if err := setPort (ctx .String ("install-port" )); err != nil {
122
+ return err
123
+ }
124
+ }
125
+ c := install .Routes ()
126
+ err := listen (c , false )
127
+ if err != nil {
128
+ log .Critical ("Unable to open listener for installer. Is Gitea already running?" )
129
+ graceful .GetManager ().DoGracefulShutdown ()
130
+ }
131
+ select {
132
+ case <- graceful .GetManager ().IsShutdown ():
133
+ <- graceful .GetManager ().Done ()
134
+ log .Info ("PID: %d Gitea Web Finished" , os .Getpid ())
135
+ log .GetManager ().Close ()
136
+ return err
137
+ default :
138
+ }
139
+ return nil
140
+ }
141
+
142
+ func serveInstalled (ctx * cli.Context ) error {
143
+ setting .InitCfgProvider (setting .CustomConf )
144
+ setting .LoadCommonSettings ()
145
+ setting .MustInstalled ()
146
+
147
+ log .Info ("Gitea version: %s%s" , setting .AppVer , setting .AppBuiltWith )
148
+ log .Info ("App path: %s" , setting .AppPath )
149
+ log .Info ("Work path: %s" , setting .AppWorkPath )
150
+ log .Info ("Custom path: %s" , setting .CustomPath )
151
+ log .Info ("Config file: %s" , setting .CustomConf )
152
+ log .Info ("Run mode: %s" , setting .RunMode )
153
+ log .Info ("Prepare to run web server" )
154
+
155
+ if setting .CfgProvider .Section ("" ).Key ("WORK_PATH" ).String () == "" {
156
+ setting .CfgProvider .Section ("" ).Key ("WORK_PATH" ).SetValue (setting .AppWorkPath )
157
+ if err := setting .CfgProvider .Save (); err != nil {
158
+ log .Error ("Unable to update WORK_PATH=%s to config %q: %v\n You must set it manually, otherwise there might be bugs when accessing the git repositories." , setting .AppWorkPath , setting .CustomConf , err )
159
+ }
160
+ }
161
+
162
+ routers .InitWebInstalled (graceful .GetManager ().HammerContext ())
163
+
164
+ // We check that AppDataPath exists here (it should have been created during installation)
165
+ // We can't check it in `InitWebInstalled`, because some integration tests
166
+ // use cmd -> InitWebInstalled, but the AppDataPath doesn't exist during those tests.
167
+ if _ , err := os .Stat (setting .AppDataPath ); err != nil {
168
+ log .Fatal ("Can not find APP_DATA_PATH %q" , setting .AppDataPath )
169
+ }
170
+
171
+ // Override the provided port number within the configuration
172
+ if ctx .IsSet ("port" ) {
173
+ if err := setPort (ctx .String ("port" )); err != nil {
174
+ return err
175
+ }
176
+ }
177
+
178
+ // Set up Chi routes
179
+ c := routers .NormalRoutes ()
180
+ err := listen (c , true )
181
+ <- graceful .GetManager ().Done ()
182
+ log .Info ("PID: %d Gitea Web Finished" , os .Getpid ())
183
+ log .GetManager ().Close ()
184
+ return err
185
+ }
186
+
187
+ func servePprof () {
188
+ http .DefaultServeMux .Handle ("/debug/fgprof" , fgprof .Handler ())
189
+ _ , _ , finished := process .GetManager ().AddTypedContext (context .Background (), "Web: PProf Server" , process .SystemProcessType , true )
190
+ // The pprof server is for debug purpose only, it shouldn't be exposed on public network. At the moment it's not worth to introduce a configurable option for it.
191
+ log .Info ("Starting pprof server on localhost:6060" )
192
+ log .Info ("Stopped pprof server: %v" , http .ListenAndServe ("localhost:6060" , nil ))
193
+ finished ()
194
+ }
195
+
104
196
func runWeb (ctx * cli.Context ) error {
105
197
if ctx .Bool ("verbose" ) {
106
198
setupConsoleLogger (log .TRACE , log .CanColorStdout , os .Stdout )
@@ -128,75 +220,19 @@ func runWeb(ctx *cli.Context) error {
128
220
createPIDFile (ctx .String ("pid" ))
129
221
}
130
222
131
- // Perform pre-initialization
132
- needsInstall := install .PreloadSettings (graceful .GetManager ().HammerContext ())
133
- if needsInstall {
134
- // Flag for port number in case first time run conflict
135
- if ctx .IsSet ("port" ) {
136
- if err := setPort (ctx .String ("port" )); err != nil {
137
- return err
138
- }
139
- }
140
- if ctx .IsSet ("install-port" ) {
141
- if err := setPort (ctx .String ("install-port" )); err != nil {
142
- return err
143
- }
144
- }
145
- c := install .Routes ()
146
- err := listen (c , false )
147
- if err != nil {
148
- log .Critical ("Unable to open listener for installer. Is Gitea already running?" )
149
- graceful .GetManager ().DoGracefulShutdown ()
150
- }
151
- select {
152
- case <- graceful .GetManager ().IsShutdown ():
153
- <- graceful .GetManager ().Done ()
154
- log .Info ("PID: %d Gitea Web Finished" , os .Getpid ())
155
- log .GetManager ().Close ()
223
+ if ! setting .InstallLock {
224
+ if err := serveInstall (ctx ); err != nil {
156
225
return err
157
- default :
158
226
}
159
227
} else {
160
228
NoInstallListener ()
161
229
}
162
230
163
231
if setting .EnablePprof {
164
- go func () {
165
- http .DefaultServeMux .Handle ("/debug/fgprof" , fgprof .Handler ())
166
- _ , _ , finished := process .GetManager ().AddTypedContext (context .Background (), "Web: PProf Server" , process .SystemProcessType , true )
167
- // The pprof server is for debug purpose only, it shouldn't be exposed on public network. At the moment it's not worth to introduce a configurable option for it.
168
- log .Info ("Starting pprof server on localhost:6060" )
169
- log .Info ("Stopped pprof server: %v" , http .ListenAndServe ("localhost:6060" , nil ))
170
- finished ()
171
- }()
232
+ go servePprof ()
172
233
}
173
234
174
- log .Info ("Global init" )
175
- // Perform global initialization
176
- setting .Init (& setting.Options {})
177
- routers .GlobalInitInstalled (graceful .GetManager ().HammerContext ())
178
-
179
- // We check that AppDataPath exists here (it should have been created during installation)
180
- // We can't check it in `GlobalInitInstalled`, because some integration tests
181
- // use cmd -> GlobalInitInstalled, but the AppDataPath doesn't exist during those tests.
182
- if _ , err := os .Stat (setting .AppDataPath ); err != nil {
183
- log .Fatal ("Can not find APP_DATA_PATH '%s'" , setting .AppDataPath )
184
- }
185
-
186
- // Override the provided port number within the configuration
187
- if ctx .IsSet ("port" ) {
188
- if err := setPort (ctx .String ("port" )); err != nil {
189
- return err
190
- }
191
- }
192
-
193
- // Set up Chi routes
194
- c := routers .NormalRoutes ()
195
- err := listen (c , true )
196
- <- graceful .GetManager ().Done ()
197
- log .Info ("PID: %d Gitea Web Finished" , os .Getpid ())
198
- log .GetManager ().Close ()
199
- return err
235
+ return serveInstalled (ctx )
200
236
}
201
237
202
238
func setPort (port string ) error {
0 commit comments