VividCortex/godaemon — pull request #17 by abhishekkr (2014-05-14 11:03:34+00:00)
Title: provide capability for process to be aware of PID of daemon

#### To make your daemon pid-aware

* *PersistPID* : to persist PID of daemon process in a (default or path passed as param) pidfile
* *KillPID* : to kill PID from process' pidfile
* *StatusPID* : to check status of PID from process' pidfile

```go
package main

import (
"flag"
"fmt"

"github.com/ChaosCloud/godaemon"
)

var (
axn = flag.String("axn", "status", "status|start|stop")
)

func main() {
godaemon.MakeDaemon(&godaemon.DaemonAttr{})
flag.Parse()

switch *axn {
case "stop":
fmt.Println("Stopping...")
if godaemon.KillPID("") {
fmt.Println("Status: Stopped.")
} else {
fmt.Printf("Failed to stop. Status: ")
godaemon.StatusPID("")
}
case "status":
fmt.Printf("Status: ")
godaemon.StatusPID("")
default:
if godaemon.PersistPID("") {
// call whatever process is actually gotta run as daemon
}
}
}

```