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

Add option to store pidfile in a different location #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ If your organization uses a centralized log management product, see its document
--hostname, Optionally set the 'Host' header (defaults to the host
found in the server url).

--pid Generate pid file in current working directory
--pid, Generate pid file 'outsystemscc.pid' in current working directory.
Synonymous to --pidpath .

--pidpath, Generate pid file at a specific destination.
Set either path to a file, or a path to a directory.

-v, Enable verbose logging

Expand Down
30 changes: 25 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"net/http"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
Expand All @@ -24,9 +25,21 @@ func main() {
client(os.Args[1:])
}

func generatePidFile() {
func generatePidFile(path string) {
pid := []byte(strconv.Itoa(os.Getpid()))
if err := ioutil.WriteFile("outsystemscc.pid", pid, 0644); err != nil {

fileInfo, err := os.Stat(path)
if err != nil {
if !os.IsNotExist(err) {
log.Fatal(err)
}
} else {
if fileInfo.IsDir() {
path = filepath.Join(path, "outsystemscc.pid")
}
}

if err := ioutil.WriteFile(path, pid, 0644); err != nil {
log.Fatal(err)
}
}
Expand Down Expand Up @@ -103,7 +116,11 @@ var clientHelp = `
--hostname, Optionally set the 'Host' header (defaults to the host
found in the server url).

--pid Generate pid file in current working directory
--pid, Generate pid file 'outsystemscc.pid' in current working directory.
Synonymous to --pidpath .

--pidpath, Generate pid file at a specific destination.
Set either path to a file, or a path to a directory.

-v, Enable verbose logging

Expand All @@ -128,6 +145,7 @@ func client(args []string) {
flags.Var(&headerFlags{config.Headers}, "header", "")
hostname := flags.String("hostname", "", "")
pid := flags.Bool("pid", false, "")
pidpath := flags.String("pidpath", "", "")
verbose := flags.Bool("v", false, "")
flags.Usage = func() {
fmt.Print(clientHelp)
Expand Down Expand Up @@ -155,8 +173,10 @@ func client(args []string) {
log.Fatal(err)
}
c.Debug = *verbose
if *pid {
generatePidFile()
if *pidpath != "" {
generatePidFile(*pidpath)
} else if *pid {
generatePidFile(".")
}
go cos.GoStats()
ctx := cos.InterruptContext()
Expand Down