Documentation ¶
Overview ¶
Package gdaemon does add daemon, logging and forever function to your program.
the below command line arguments you can passed to your program after you using daemon package.
--forver or -forver
the argument will fork a worker process and master process monit worker process , and restart it when it crashed.
--daemon or -daemon
the argument will put your program running in background , only working in linux uinx etc.
--flog or -flog <filename.log>
the argument will logging your program stdout to the log file.
notice:
before you maybe execute your program like this:
./foobar -u root
after using daemon package, execute your program can be like this:
./foobar -u root -forever -daemon -flog foobar.log
Example ¶
package main import ( "fmt" "os" "os/signal" "syscall" ) func main() { //the code block should be in your main function,and the actual main() change to doMain() if err := Start(); err != nil { fmt.Println(err) return } if CanRun() { //call actual main() go doMain() } //waiting kill signal signalChan := make(chan os.Signal, 1) signal.Notify(signalChan, os.Interrupt, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) <-signalChan //do clean Clean() } // your main function func doMain() { //flag.Parse() should be called here if you have }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.