Skip to content
A library for writing system daemons in golang.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples/cmd Minor improvements and corrections for examples May 4, 2019
img Update docs Sep 25, 2016
.travis.yml Fix compilation for old versions of go May 4, 2019
LICENSE Update docs Sep 25, 2016
README.md Fix README.md about CGO May 2, 2018
command.go Refactoring for support of different platforms Sep 25, 2016
compilation_test.go Fix compilation for old versions of go May 4, 2019
daemon.go Fix PID-file path with Chroot option handling May 2, 2018
daemon_stub.go Fix build on Windows (#31) Mar 5, 2018
daemon_test.go Updated documentation Feb 27, 2014
daemon_unix.go Fixed a null dereference bug (#57) May 4, 2019
lock_file.go Remove getFdName May 2, 2018
lock_file_solaris.go Added Support for Illumos via Fcntl Mar 9, 2019
lock_file_stub.go Remove getFdName May 2, 2018
lock_file_test.go Added Support for Illumos via Fcntl Mar 9, 2019
lock_file_unix.go
os_executable.go Use "github.com/kardianos/osext" when Go < 1.8 Mar 9, 2019
os_executable_pre18.go Use "github.com/kardianos/osext" when Go < 1.8 Mar 9, 2019
signal.go
syscall_dup.go Fix compilation for old versions of go May 4, 2019
syscall_dup_arm64.go Fix build for linux_arm64 (#29) Nov 24, 2017
syscall_dup_pre17.go Fix compilation for old versions of go May 4, 2019

README.md

go-daemon Build Status GoDoc

Library for writing system daemons in Go.

Now supported only UNIX-based OS (Windows is not supported). But the library was tested only on Linux and OSX, so that if you have an ability to test the library on other platforms, give me feedback, please (#26).

Please, feel free to send me bug reports and fixes. Many thanks to all contributors.

Features

  • Goroutine-safe daemonization;
  • Out of box work with pid-files;
  • Easy handling of system signals;
  • The control of a daemon.

Installation

go get github.com/sevlyar/go-daemon

You can use gopkg.in:

go get gopkg.in/sevlyar/go-daemon.v0

If you want to use the library in production project, please use vendoring, because i can not ensure backward compatibility before release v1.0.

Examples

Documentation

godoc.org/github.com/sevlyar/go-daemon

How it works

We can not use fork syscall in Golang's runtime, because child process doesn't inherit threads and goroutines in that case. The library uses a simple trick: it runs its own copy with a mark - a predefined environment variable. Availability of the variable for the process means an execution in the child's copy. So that if the mark is not setted - the library executes parent's operations and runs its own copy with mark, and if the mark is setted - the library executes child's operations:

func main() {
	Pre()

	context := new(Context)
	child, _ := context.Reborn()

	if child != nil {
		PostParent()
	} else {
		defer context.Release()
		PostChild()
	}
}

You can’t perform that action at this time.