@@ -12,7 +12,6 @@ import (
1212 "path"
1313 "path/filepath"
1414 "runtime"
15- "strconv"
1615 "strings"
1716 "time"
1817
@@ -42,15 +41,13 @@ var (
4241 AppWorkPath string
4342
4443 // 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
5451)
5552
5653func getAppPath () (string , error ) {
@@ -141,22 +138,6 @@ func IsRunUserMatchCurrentUser(runUser string) (string, bool) {
141138 return currentUser , runUser == currentUser
142139}
143140
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-
160141// SetCustomPathAndConf will set CustomPath and CustomConf with reference to the
161142// GITEA_CUSTOM environment variable and with provided overrides before stepping
162143// back to the default
@@ -218,17 +199,17 @@ func PrepareAppDataPath() error {
218199
219200// InitProviderFromExistingFile initializes config provider from an existing config file (app.ini)
220201func InitProviderFromExistingFile () {
221- CfgProvider = newFileProviderFromConf (CustomConf , WritePIDFile , false , PIDFile , "" )
202+ CfgProvider = newFileProviderFromConf (CustomConf , false , "" )
222203}
223204
224205// InitProviderAllowEmpty initializes config provider from file, it's also fine that if the config file (app.ini) doesn't exist
225206func InitProviderAllowEmpty () {
226- CfgProvider = newFileProviderFromConf (CustomConf , WritePIDFile , true , PIDFile , "" )
207+ CfgProvider = newFileProviderFromConf (CustomConf , true , "" )
227208}
228209
229210// InitProviderAndLoadCommonSettingsForTest initializes config provider and load common setttings for tests
230211func InitProviderAndLoadCommonSettingsForTest (extraConfigs ... string ) {
231- CfgProvider = newFileProviderFromConf (CustomConf , WritePIDFile , true , PIDFile , strings .Join (extraConfigs , "\n " ))
212+ CfgProvider = newFileProviderFromConf (CustomConf , true , strings .Join (extraConfigs , "\n " ))
232213 loadCommonSettingsFrom (CfgProvider )
233214 if err := PrepareAppDataPath (); err != nil {
234215 log .Fatal ("Can not prepare APP_DATA_PATH: %v" , err )
@@ -241,13 +222,9 @@ func InitProviderAndLoadCommonSettingsForTest(extraConfigs ...string) {
241222
242223// newFileProviderFromConf initializes configuration context.
243224// 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 {
245226 cfg := ini .Empty ()
246227
247- if writePIDFile && len (pidFile ) > 0 {
248- createPIDFile (pidFile )
249- }
250-
251228 isFile , err := util .IsFile (customConf )
252229 if err != nil {
253230 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)) {
380357
381358// LoadSettings initializes the settings for normal start up
382359func LoadSettings () {
383- LoadDBSetting ( )
360+ loadDBSetting ( CfgProvider )
384361 loadServiceFrom (CfgProvider )
385362 loadOAuth2ClientFrom (CfgProvider )
386363 InitLogs (false )
@@ -401,7 +378,7 @@ func LoadSettings() {
401378
402379// LoadSettingsForInstall initializes the settings for install
403380func LoadSettingsForInstall () {
404- LoadDBSetting ( )
381+ loadDBSetting ( CfgProvider )
405382 loadServiceFrom (CfgProvider )
406383 loadMailerFrom (CfgProvider )
407384}
0 commit comments