Skip to content

Commit

Permalink
feat(pid): Write pid file
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Seguin authored and voyvodov committed Sep 18, 2024
1 parent 350ff31 commit 97b50dd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
)

type FlagStorage struct {
PidFile string

// File system
MountOptions map[string]string
MountPoint string
Expand Down
7 changes: 7 additions & 0 deletions internal/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func NewApp() (app *cli.App) {
Usage: "Print this help text and exit successfully.",
},

cli.StringFlag{
Name: "pid-file",
Usage: "Write a pid file containing the process pid.",
},

/////////////////////////
// File system
/////////////////////////
Expand Down Expand Up @@ -320,6 +325,8 @@ func parseOptions(m map[string]string, s string) {
// variables into which the flags will parse.
func PopulateFlags(c *cli.Context) (ret *FlagStorage) {
flags := &FlagStorage{
PidFile: c.String("pid-file"),

// File system
MountOptions: make(map[string]string),
DirMode: os.FileMode(c.Int("dir-mode")),
Expand Down
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
package main

import (
"io/ioutil"
"strconv"

goofys "github.com/kahing/goofys/api"
. "github.com/kahing/goofys/api/common"
. "github.com/kahing/goofys/internal"
Expand Down Expand Up @@ -221,6 +224,15 @@ func main() {
kill(os.Getppid(), syscall.SIGUSR1)
}
log.Println("File system has been successfully mounted.")

if flags.PidFile != "" {
// Write out a Pid file
err = ioutil.WriteFile(flags.PidFile, []byte(strconv.Itoa(os.Getpid())), 0644)
if err != nil {
log.Fatalf("Error writing pid file: %v", err)
}
}

// Let the user unmount with Ctrl-C
// (SIGINT). But if cache is on, catfs will
// receive the signal and we would detect that exiting
Expand Down

0 comments on commit 97b50dd

Please sign in to comment.