Skip to content

Instantly share code, notes, and snippets.



Created Jun 12, 2012
What would you like to do?
Simple Daemon
package main
import (
func main() {
// Syslog logging
logger, err := syslog.New(syslog.LOG_EMERG, "go-daemon")
if err != nil {
log.Printf("Can't open syslog connection: %v", err)
// Become a daemon
p, err := daemonize.Daemonize(false, false)
if err != nil {
// Daemonize failed
logger.Emerg(fmt.Sprintf("Can't daemonize: %v", err))
// We are the parent, exit
if p != nil {
// Do Daemon stuff here
logger.Info("Daemon up and running")
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt, os.Kill)
logger.Info(fmt.Sprintf("Got signal (%s), exiting", (<-sigs).String()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment