feat: write pprof to file when daemon quit (#247)

This commit is contained in:
naison
2024-05-14 11:19:58 +08:00
committed by GitHub
parent 984ab2ce89
commit cc032c4a6d
4 changed files with 33 additions and 4 deletions

View File

@@ -85,6 +85,7 @@ const (
// pprof port
PProfPort = 32345
SudoPProfPort = 33345
PProfDir = "pprof"
// startup by KubeVPN
EnvStartSudoKubeVPNByKubeVPN = "DEPTH_SIGNED_BY_NAISON"
@@ -109,6 +110,7 @@ var (
DaemonPath string
HomePath string
PprofPath string
)
var (
@@ -129,6 +131,7 @@ func init() {
dir, _ := os.UserHomeDir()
DaemonPath = filepath.Join(dir, HOME, Daemon)
HomePath = filepath.Join(dir, HOME)
PprofPath = filepath.Join(dir, HOME, Daemon, PProfDir)
}
var Debug bool

View File

@@ -29,11 +29,19 @@ const (
var config []byte
func init() {
err := os.MkdirAll(DaemonPath, os.ModePerm)
err := os.MkdirAll(DaemonPath, 0755)
if err != nil {
panic(err)
}
err = os.Chmod(DaemonPath, os.ModePerm)
err = os.Chmod(DaemonPath, 0755)
if err != nil {
panic(err)
}
err = os.MkdirAll(PprofPath, 0755)
if err != nil {
panic(err)
}
err = os.Chmod(PprofPath, 0755)
if err != nil {
panic(err)
}

View File

@@ -215,10 +215,10 @@ func (o *SvrOption) detectUnixSocksFile(ctx context.Context) {
func writePIDToFile(isSudo bool) error {
pidPath := GetPidPath(isSudo)
pid := os.Getpid()
err := os.WriteFile(pidPath, []byte(strconv.Itoa(pid)), os.ModePerm)
err := os.WriteFile(pidPath, []byte(strconv.Itoa(pid)), 0644)
if err != nil {
return err
}
err = os.Chmod(pidPath, os.ModePerm)
err = os.Chmod(pidPath, 0644)
return err
}