Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Daemon ¶
func Daemon(writepid io.Writer, processArgs func([]string, ...string) []string, args ...string) (err error)
Daemon backgrounds the current process by re-executing the existing binary (as found by os.Executable, so may there is a small window while the referenced binary can change). The function passed as processArgs is called with any further arguments passed to it as parameters and can be used to remove flags that triggered the daemonization in the first place. A helper function - RemoveArgs - is available to do this.
If successful the function never returns and the child process PID is written to writepid, which can be io.Discard if not required. On failure the function does return with an error.
process.Daemon(os.Stdout, process.RemoveArgs, "-D", "--daemon")
func RemoveArgs ¶
RemoveArgs is a helper function for Daemon(). Daemon calls the function with os.Args[1;] as origargs and removes any arguments matching members of the slice remove and returns newargs. Only bare arguments are removed and no pattern matching or adjacent values are removed. If this is required then pass your own function with the same signature.
Types ¶
This section is empty.