Example #1
0
File: dmn.go Project: Yossibh/envdb
func setupLogging() {
	if daemon.WasReborn() {
		file, _ := os.OpenFile(logFileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, fileMask)
		daemon.RedirectStream(os.Stdout, file)
		daemon.RedirectStream(os.Stderr, file)
		file.Close()
		log.Println("--- log ---")
	} else {
		log.SetFlags(0)
		if *silent {
			file, _ := os.OpenFile(os.DevNull, os.O_WRONLY, fileMask)
			daemon.RedirectStream(os.Stdout, file)
			daemon.RedirectStream(os.Stderr, file)
			file.Close()
		}
	}
}
Example #2
0
File: dmn.go Project: Yossibh/envdb
func lockPidFile() *daemon.PidFile {
	pidf, err := daemon.LockPidFile(pidFileName, fileMask)
	if err != nil {
		if err == daemon.ErrWouldBlock {
			log.Println("daemon copy is already running")
			os.Exit(ret_ALREADYRUN)
		} else {
			log.Println("pid file creation error:", err)
			os.Exit(ret_PIDFERROR)
		}
	}

	if !daemon.WasReborn() {
		pidf.Unlock()
	}

	if *status {
		os.Exit(ret_OK)
	}

	return pidf
}