summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorMatthias Loibl <mail@matthiasloibl.com>2017-01-09 14:51:26 +0100
committerGitHub <noreply@github.com>2017-01-09 14:51:26 +0100
commit97170916a3268c359476c00865c0369c9dc095bb (patch)
tree2ffb6da12eb2c2db71bf065e10cf5b6d8f5521ca /modules
parent19570f2d43a31ecdb3b33761df7712cbe327e5c1 (diff)
parent9f575986d8021cfab87d1dd664517d4fbd4ea58a (diff)
downloadgitea-97170916a3268c359476c00865c0369c9dc095bb.tar.gz
gitea-97170916a3268c359476c00865c0369c9dc095bb.zip
Merge pull request #610 from appleboy/pid
feat: support pid file.
Diffstat (limited to 'modules')
-rw-r--r--modules/setting/setting.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index 7b9cf43cb3..7fd4cfc2fa 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -392,6 +392,7 @@ var (
Cfg *ini.File
CustomPath string // Custom directory path
CustomConf string
+ CustomPID string
ProdMode bool
RunUser string
IsWindows bool
@@ -471,6 +472,22 @@ func IsRunUserMatchCurrentUser(runUser string) (string, bool) {
return currentUser, runUser == currentUser
}
+func createPIDFile(pidPath string) {
+ currentPid := os.Getpid()
+ if err := os.MkdirAll(filepath.Dir(pidPath), os.ModePerm); err != nil {
+ log.Fatal(4, "Can't create PID folder on %s", err)
+ }
+
+ file, err := os.Create(pidPath)
+ if err != nil {
+ log.Fatal(4, "Can't create PID file: %v", err)
+ }
+ defer file.Close()
+ if _, err := file.WriteString(strconv.FormatInt(int64(currentPid), 10)); err != nil {
+ log.Fatal(4, "Can'write PID information on %s", err)
+ }
+}
+
// NewContext initializes configuration context.
// NOTE: do not print any log except error.
func NewContext() {
@@ -498,6 +515,12 @@ please consider changing to GITEA_CUSTOM`)
}
}
+ if len(CustomPID) == 0 {
+ CustomPID = CustomPath + "/run/app.pid"
+ }
+
+ createPIDFile(CustomPID)
+
if len(CustomConf) == 0 {
CustomConf = CustomPath + "/conf/app.ini"
}