• Stars
    star
    494
  • Rank 85,765 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 11 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Daemonize Go applications deviously.

godaemon

Daemonize Go applications with exec() instead of fork(). Read our blog post on the subject.

You can't daemonize the usual way in Go. Daemonizing is a Unix concept that requires some specific things you can't do easily in Go. But you can still accomplish the same goals if you don't mind that your program will start copies of itself several times, as opposed to using fork() the way many programmers are accustomed to doing.

It is somewhat controversial whether it's even a good idea to make programs daemonize themselves, or how to do it correctly (and whether it's even possible to do correctly in Go). Read here, here, and here for more on this topic. However, at VividCortex we do need to run one of our processes as a daemon with the usual attributes of a daemon, and we chose the approach implemented in this package.

Because of the factors mentioned in the first link just given, you should take great care when using this package's approach. It works for us, because we don't do anything like starting up goroutines in our init() functions, or other things that are perfectly legal in Go in general.

Getting Started

View the package documentation for details about how it works. Briefly, to make your program into a daemon, do the following as soon as possible in your main() function:

import (
	"github.com/VividCortex/godaemon"
)

func main() {
	godaemon.MakeDaemon(&godaemon.DaemonAttr{})
}

Use the CaptureOutput attribute if you need to capture your program's standard output and standard error streams. In that case, the function returns two valid readers (io.Reader) that you can read from the program itself. That's particularly useful for functions that write error or diagnosis messages right to the error output, which are normally lost in a daemon.

Use the Files attribute if you need to inherit open files into the daemon. This is primarily intended for avoiding race conditions when holding locks on those files (flocks). Releasing and re-acquiring locks between successive fork calls opens up the chance for another program to steal the lock. However, by declaring your file descriptors in the Files attribute, MakeDaemon() will guarantee that locks are not released throughout the whole process. Your daemon will inherit the file still holding the same locks, with no other process having intervened in between. See the package documentation for more details and sample code. (Note that you shouldn't use this feature to inherit TTY descriptors; otherwise what you get is technically not a daemon.)

Contribute

Contributions are welcome. Please open pull requests or issue reports!

License

This repository is Copyright (c) 2013 VividCortex, Inc. All rights reserved. It is licensed under the MIT license. Please see the LICENSE file for applicable license terms.

Authors

The primary author is Gustavo Kristic, with some documentation and other minor contributions by others at VividCortex.

History

An earlier version of this concept with a slightly different interface was developed internally at VividCortex.

Cats

A Go Daemon is a good thing, and so we present an angelic cat picture:

Angelic Cat

More Repositories

1

go-database-sql-tutorial

A tutorial for Go's database/sql package
CSS
801
star
2

angular-recaptcha

AngularJS directive to add a reCaptcha widget to your form
JavaScript
497
star
3

ewma

Exponentially Weighted Moving Average algorithms for Go.
Go
428
star
4

siesta

Composable framework for writing HTTP handlers in Go.
Go
350
star
5

johnny-deps

Barebones dependency manager for Go.
Perl
214
star
6

mysqlerr

MySQL Server Error Constants for Golang
Go
191
star
7

ebooks

LaTeX source files for VividCortex's ebooks
TeX
176
star
8

gohistogram

Streaming approximate histograms in Go
Go
174
star
9

robustly

Run functions resiliently in Go, catching and restarting panics
Go
157
star
10

pm

Processlist manager with TCP listener
Go
81
star
11

multitick

A multiplexor for aligned time.Time tickers in Go
Go
70
star
12

trace

Easily trace goroutines at runtime
Go
50
star
13

dbcontrol

A wrapper around Go's database/sql package that provides connection pool limits
Go
29
star
14

lastseen

Last-seen sketch implementation in Go
Go
16
star
15

wlr

Weighted linear regression
Go
15
star
16

approx-queueing-theory

Approximations to the Erlang C queue length formula for M/M/n queues
Go
11
star
17

golibpcap

This is a fork of the https://code.google.com/p/golibpcap/ project.
Go
11
star
18

pm-web

A simple web front-end for pm, a process manager for Go
JavaScript
10
star
19

grafana-datasource

Datasource plugin for connecting your Grafana dashboard to SolarWind's DPM
TypeScript
5
star
20

grunt-circleci

[DEPRECATED] A Grunt plugin for checking build statuses in CircleCI
JavaScript
5
star
21

puppet

Puppet example for the installation of the VividCortex repository
Puppet
2
star
22

hubot-vividcortex

VividCortex hubot script!
CoffeeScript
2
star
23

snappy-go

Clone of the snappy package for Go from code.google.coml (DEPRECATED: we're moving to VividCortex/snappy)
Go
2
star
24

docker

Docker container for VividCortex agents
Dockerfile
1
star