summaryrefslogtreecommitdiffhomepage
path: root/daemon.go
blob: e2ded877c86b9d55a8843ab777d4637552c9a9b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
}