daemon

module
v0.0.0-...-e445f7c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2018 License: BSD-3-Clause

README

daemon

Daemon initialization routines (process, log, pidfile, signal handling)

import (
	"github.com/aavzz/daemon/fork"
	"github.com/aavzz/daemon/log"
	"github.com/aavzz/daemon/pid"
	"github.com/aavzz/daemon/signal"
}
     
//Initialize logging to syslog with a relevant tag
//The process exits if local syslog is not running
log.InitSyslog("tag")

//Daemonize process if needed
fork.Daemonize()

//After daemonize() this part runs in child only

//Check for double invocation and write pidfile
pid.Write("/path/to/pidfile")

//Set all signals to be ignored
signal.Ignore()

//Setup SIGHUP to re-read configuration
signal.Hup(func() {
	log.Info("SIGHUP received, re-reading configuration file")
	if err := viper.ReadInConfig(); err != nil {
		pid.Remove()
		log.Fatal(err.Error())
	}
})

//Setup SIGTERM to remove pidfile and exit immidiately
signal.Term(func() {
	log.Info("SIGTERM received, exitting")
	pid.Remove()
	os.Exit(0)
})

//signal.Quit is set up to terminate the process gracefully
//in approppriate place (where required objects are available).


//further initialization and an event loop

Directories

Path Synopsis
Package fork sets up process to run in the background.
Package fork sets up process to run in the background.
Package log sets up logging for the process
Package log sets up logging for the process
Package pid checks for double invocation and manages pidfile.
Package pid checks for double invocation and manages pidfile.
Package signal manages signal handling.
Package signal manages signal handling.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL