diff options
Diffstat (limited to 'daemon.go')
-rw-r--r-- | daemon.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/daemon.go b/daemon.go new file mode 100644 index 0000000..e2ded87 --- /dev/null +++ b/daemon.go @@ -0,0 +1,25 @@ +package main + +import ( + "os" +) + +func Daemonize(attr *os.ProcAttr) error { + path, err := os.Executable() + if err != nil { + return err + } + + argv := []string{os.Args[0], "--foreground"} + argv = append(argv, os.Args[1:]...) + process, err := os.StartProcess( + path, + argv, + attr, + ) + if err != nil { + return err + } + process.Release() + return nil +} |