Skip to content

Commit 4aa5021

Browse files
committed
refactor: move pid file logic out of app
1 parent 7db6788 commit 4aa5021

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/app/main.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ func (app *App) GetAccessibleOrigins(includeLoopback bool) [][]string {
5454
}
5555

5656
func NewApp(params param.Params, settings *setting.Setting) (*App, []error) {
57-
if len(settings.PidFile) > 0 {
58-
errs := writePidFile(settings.PidFile)
59-
if len(errs) > 0 {
60-
return nil, errs
61-
}
62-
}
63-
6457
vhSvc := goVirtualHost.NewService()
6558
logMan := serverLog.NewMan()
6659
themePool := make(map[string]theme.Theme)

src/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ func Main() (ok bool) {
7171
defer StopCPUProfile(cpuProfileFile)
7272
}
7373

74+
// pid file
75+
if len(settings.PidFile) > 0 {
76+
errs = writePidFile(settings.PidFile)
77+
if serverError.CheckError(errs...) {
78+
return
79+
}
80+
}
81+
7482
// log queue size
7583
if len(settings.LogQueueSize) > 0 {
7684
logQueueSize, err := strconv.Atoi(settings.LogQueueSize)

src/app/pidFile.go renamed to src/pidFile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package app
1+
package src
22

33
import (
44
"mjpclab.dev/ghfs/src/serverError"
@@ -7,12 +7,12 @@ import (
77
)
88

99
func writePidFile(pidFilePath string) (errs []error) {
10-
pidContent := strconv.Itoa(os.Getpid())
1110
pidFile, err := os.OpenFile(pidFilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
1211
if err != nil {
1312
return []error{err}
1413
}
1514

15+
pidContent := strconv.Itoa(os.Getpid())
1616
_, err = pidFile.WriteString(pidContent)
1717
errs = serverError.AppendError(errs, err)
1818

0 commit comments

Comments
 (0)