@@ -392,6 +392,7 @@ var (
392
392
Cfg * ini.File
393
393
CustomPath string // Custom directory path
394
394
CustomConf string
395
+ CustomPID string
395
396
ProdMode bool
396
397
RunUser string
397
398
IsWindows bool
@@ -471,6 +472,22 @@ func IsRunUserMatchCurrentUser(runUser string) (string, bool) {
471
472
return currentUser , runUser == currentUser
472
473
}
473
474
475
+ func createPIDFile (pidPath string ) {
476
+ currentPid := os .Getpid ()
477
+ if err := os .MkdirAll (filepath .Dir (pidPath ), os .ModePerm ); err != nil {
478
+ log .Fatal (4 , "Can't create PID folder on %s" , err )
479
+ }
480
+
481
+ file , err := os .Create (pidPath )
482
+ if err != nil {
483
+ log .Fatal (4 , "Can't create PID file: %v" , err )
484
+ }
485
+ defer file .Close ()
486
+ if _ , err := file .WriteString (strconv .FormatInt (int64 (currentPid ), 10 )); err != nil {
487
+ log .Fatal (4 , "Can'write PID information on %s" , err )
488
+ }
489
+ }
490
+
474
491
// NewContext initializes configuration context.
475
492
// NOTE: do not print any log except error.
476
493
func NewContext () {
@@ -498,6 +515,12 @@ please consider changing to GITEA_CUSTOM`)
498
515
}
499
516
}
500
517
518
+ if len (CustomPID ) == 0 {
519
+ CustomPID = CustomPath + "/run/app.pid"
520
+ }
521
+
522
+ createPIDFile (CustomPID )
523
+
501
524
if len (CustomConf ) == 0 {
502
525
CustomConf = CustomPath + "/conf/app.ini"
503
526
}
0 commit comments