Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support pid file. #610

Merged
merged 1 commit into from
Jan 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: support pid file.
  • Loading branch information
appleboy committed Jan 9, 2017
commit 9f575986d8021cfab87d1dd664517d4fbd4ea58a
10 changes: 10 additions & 0 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ and it takes care of all the other things for you`,
Value: "custom/conf/app.ini",
Usage: "Custom configuration file path",
},
cli.StringFlag{
Name: "pid, P",
Value: "custom/run/app.pid",
Usage: "Custom pid file path",
},
},
}

Expand Down Expand Up @@ -156,6 +161,11 @@ func runWeb(ctx *cli.Context) error {
if ctx.IsSet("config") {
setting.CustomConf = ctx.String("config")
}

if ctx.IsSet("pid") {
setting.CustomPID = ctx.String("pid")
}

routers.GlobalInit()

m := newMacaron()
Expand Down
23 changes: 23 additions & 0 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ var (
Cfg *ini.File
CustomPath string // Custom directory path
CustomConf string
CustomPID string
ProdMode bool
RunUser string
IsWindows bool
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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"
}
Expand Down