From 3a430420898ab2df707dd037bfaf220ac5d583d2 Mon Sep 17 00:00:00 2001 From: Evan Phoenix Date: Thu, 18 Jun 2015 11:31:16 -0700 Subject: [PATCH] Add -pidfile and Commit variable --- cmd/telegraf/telegraf.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index aa6a95138..f36693ebc 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -17,8 +17,10 @@ var fTest = flag.Bool("test", false, "gather metrics, print them out, and exit") var fConfig = flag.String("config", "", "configuration file to load") var fVersion = flag.Bool("version", false, "display the version") var fSampleConfig = flag.Bool("sample-config", false, "print out full sample configuration") +var fPidfile = flag.String("pidfile", "", "file to write our pid to") var Version = "unreleased" +var Commit = "" func main() { flag.Parse() @@ -104,5 +106,16 @@ func main() { log.Printf("Tags enabled: %v", config.ListTags()) } + if *fPidfile != "" { + f, err := os.Create(*fPidfile) + if err != nil { + log.Fatalf("Unable to create pidfile: %s", err) + } + + fmt.Fprintf(f, "%d\n", os.Getpid()) + + f.Close() + } + ag.Run(shutdown) }