Skip to content
/ godaemon Public

Simple API to start daemon process in Go program.

License

Notifications You must be signed in to change notification settings

xuges/godaemon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

godaemon

Overview

Simple API to start daemon process in Go program.

Normaly in Go, child process will exit when parent process exitd, sometimes you maybe want start a indepent, detached daemon process, not a child process, so you need this library.

Supported OS:

  • Windows
  • Linux
  • MacOS

Usage

Just like exec.Command:

Windows:

package main

import "github.com/xuges/godaemon"

func main() {
    name := "notepad.exe"
    args := []string{ "test.txt"}
    attr := &godaemon.ProcAttr {
        Dir: "C:/",
        Env: []string{ "TEST=daemon" },
    }

    err := godaemon.StartDaemonProcess(name, args, attr)
    if err != nil {
        panic(err)
    }
}

Linux:

package main

import "github.com/xuges/godaemon"

func main() {
    name := "gedit"
    args := []string{ "test.txt"}
    attr := &godaemon.ProcAttr {
        Dir: "/tmp",
        Env: []string{ "TEST=daemon" },
    }

    err := godaemon.StartDaemonProcess(name, args, attr)
    if err != nil {
        panic(err)
    }
}

About

Simple API to start daemon process in Go program.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages