@@ -12,7 +12,6 @@ import (
12
12
"path"
13
13
"path/filepath"
14
14
"runtime"
15
- "strconv"
16
15
"strings"
17
16
"time"
18
17
@@ -42,15 +41,13 @@ var (
42
41
AppWorkPath string
43
42
44
43
// Global setting objects
45
- CfgProvider ConfigProvider
46
- CustomPath string // Custom directory path
47
- CustomConf string
48
- PIDFile = "/run/gitea.pid"
49
- WritePIDFile bool
50
- RunMode string
51
- RunUser string
52
- IsProd bool
53
- IsWindows bool
44
+ CfgProvider ConfigProvider
45
+ CustomPath string // Custom directory path
46
+ CustomConf string
47
+ RunMode string
48
+ RunUser string
49
+ IsProd bool
50
+ IsWindows bool
54
51
)
55
52
56
53
func getAppPath () (string , error ) {
@@ -141,22 +138,6 @@ func IsRunUserMatchCurrentUser(runUser string) (string, bool) {
141
138
return currentUser , runUser == currentUser
142
139
}
143
140
144
- func createPIDFile (pidPath string ) {
145
- currentPid := os .Getpid ()
146
- if err := os .MkdirAll (filepath .Dir (pidPath ), os .ModePerm ); err != nil {
147
- log .Fatal ("Failed to create PID folder: %v" , err )
148
- }
149
-
150
- file , err := os .Create (pidPath )
151
- if err != nil {
152
- log .Fatal ("Failed to create PID file: %v" , err )
153
- }
154
- defer file .Close ()
155
- if _ , err := file .WriteString (strconv .FormatInt (int64 (currentPid ), 10 )); err != nil {
156
- log .Fatal ("Failed to write PID information: %v" , err )
157
- }
158
- }
159
-
160
141
// SetCustomPathAndConf will set CustomPath and CustomConf with reference to the
161
142
// GITEA_CUSTOM environment variable and with provided overrides before stepping
162
143
// back to the default
@@ -218,17 +199,17 @@ func PrepareAppDataPath() error {
218
199
219
200
// InitProviderFromExistingFile initializes config provider from an existing config file (app.ini)
220
201
func InitProviderFromExistingFile () {
221
- CfgProvider = newFileProviderFromConf (CustomConf , WritePIDFile , false , PIDFile , "" )
202
+ CfgProvider = newFileProviderFromConf (CustomConf , false , "" )
222
203
}
223
204
224
205
// InitProviderAllowEmpty initializes config provider from file, it's also fine that if the config file (app.ini) doesn't exist
225
206
func InitProviderAllowEmpty () {
226
- CfgProvider = newFileProviderFromConf (CustomConf , WritePIDFile , true , PIDFile , "" )
207
+ CfgProvider = newFileProviderFromConf (CustomConf , true , "" )
227
208
}
228
209
229
210
// InitProviderAndLoadCommonSettingsForTest initializes config provider and load common setttings for tests
230
211
func InitProviderAndLoadCommonSettingsForTest (extraConfigs ... string ) {
231
- CfgProvider = newFileProviderFromConf (CustomConf , WritePIDFile , true , PIDFile , strings .Join (extraConfigs , "\n " ))
212
+ CfgProvider = newFileProviderFromConf (CustomConf , true , strings .Join (extraConfigs , "\n " ))
232
213
loadCommonSettingsFrom (CfgProvider )
233
214
if err := PrepareAppDataPath (); err != nil {
234
215
log .Fatal ("Can not prepare APP_DATA_PATH: %v" , err )
@@ -241,13 +222,9 @@ func InitProviderAndLoadCommonSettingsForTest(extraConfigs ...string) {
241
222
242
223
// newFileProviderFromConf initializes configuration context.
243
224
// NOTE: do not print any log except error.
244
- func newFileProviderFromConf (customConf string , writePIDFile , allowEmpty bool , pidFile , extraConfig string ) * ini.File {
225
+ func newFileProviderFromConf (customConf string , allowEmpty bool , extraConfig string ) * ini.File {
245
226
cfg := ini .Empty ()
246
227
247
- if writePIDFile && len (pidFile ) > 0 {
248
- createPIDFile (pidFile )
249
- }
250
-
251
228
isFile , err := util .IsFile (customConf )
252
229
if err != nil {
253
230
log .Error ("Unable to check if %s is a file. Error: %v" , customConf , err )
@@ -380,7 +357,7 @@ func CreateOrAppendToCustomConf(purpose string, callback func(cfg *ini.File)) {
380
357
381
358
// LoadSettings initializes the settings for normal start up
382
359
func LoadSettings () {
383
- LoadDBSetting ( )
360
+ loadDBSetting ( CfgProvider )
384
361
loadServiceFrom (CfgProvider )
385
362
loadOAuth2ClientFrom (CfgProvider )
386
363
InitLogs (false )
@@ -401,7 +378,7 @@ func LoadSettings() {
401
378
402
379
// LoadSettingsForInstall initializes the settings for install
403
380
func LoadSettingsForInstall () {
404
- LoadDBSetting ( )
381
+ loadDBSetting ( CfgProvider )
405
382
loadServiceFrom (CfgProvider )
406
383
loadMailerFrom (CfgProvider )
407
384
}
0 commit comments