func init() { parseFlags() if options.showVersion { server.ShowVersionAndExit() } server.SetupLogging(options.logFile, options.logLevel, options.crashLogFile, options.alarmLogSock, options.alarmTag) // thrift lib use "log", so we also need to customize its behavior _log.SetFlags(_log.Ldate | _log.Ltime | _log.Lshortfile) if options.kill { s := server.NewServer("fae") s.LoadConfig(options.configFile) s.Launch() // stop new requests engine.NewEngine(). LoadConfig(s.Conf). UnregisterEtcd() // finish all outstanding RPC sessions if err := signal.SignalProcessByPidFile(options.lockFile, syscall.SIGUSR1); err != nil { fmt.Fprintf(os.Stderr, "stop failed: %s\n", err) os.Exit(1) } cleanup() // TODO wait till that faed process terminates, who will do the cleanup fmt.Println("faed killed") os.Exit(0) } if options.lockFile != "" { if locking.InstanceLocked(options.lockFile) { fmt.Fprintf(os.Stderr, "Another instance is running, exit...\n") os.Exit(1) } locking.LockInstance(options.lockFile) } }
func init() { parseFlags() if options.showVersion { engine.ShowVersionAndExit() } if options.lockFile != "" { if locking.InstanceLocked(options.lockFile) { fmt.Fprintf(os.Stderr, "Another instance is running, exit...\n") os.Exit(1) } locking.LockInstance(options.lockFile) } signal.RegisterSignalHandler(syscall.SIGINT, func(sig os.Signal) { shutdown() }) }
func init() { parseFlags() if options.showversion { showVersionAndExit() } if options.lockfile != "" { if locking.InstanceLocked(options.lockfile) { fmt.Fprintf(os.Stderr, "Another instance is running, exit...\n") os.Exit(1) } locking.LockInstance(options.lockfile) } globals = engine.DefaultGlobals() globals.Debug = options.debug globals.Verbose = options.verbose globals.DryRun = options.dryrun globals.TickerLength = options.tick globals.VeryVerbose = options.veryVerbose globals.Logger = newLogger() }
func (this *Start) Run(args []string) (exitCode int) { cmdFlags := flag.NewFlagSet("start", flag.ContinueOnError) cmdFlags.Usage = func() { this.Ui.Output(this.Help()) } cmdFlags.StringVar(&this.logfile, "log", defaultLogfile, "") cmdFlags.StringVar(&this.zone, "z", ctx.ZkDefaultZone(), "") cmdFlags.StringVar(&this.root, "p", defaultPrefix, "") cmdFlags.BoolVar(&this.debugMode, "d", false, "") cmdFlags.BoolVar(&this.forwardFor, "forwardfor", false, "") cmdFlags.IntVar(&this.pubPort, "pub", 10891, "") cmdFlags.IntVar(&this.subPort, "sub", 10892, "") cmdFlags.IntVar(&this.manPort, "man", 10893, "") cmdFlags.StringVar(&this.haproxyStatsUrl, "statsurl", "", "") cmdFlags.StringVar(&this.influxdbAddr, "influxaddr", "", "") cmdFlags.StringVar(&this.influxdbDbName, "influxdb", "", "") cmdFlags.StringVar(&this.httpAddr, "addr", ":10894", "monitor http server addr") if err := cmdFlags.Parse(args); err != nil { return 1 } lockFilename := fmt.Sprintf("%s/.lock", this.root) if locking.InstanceLocked(lockFilename) { panic(fmt.Sprintf("locked[%s] by another instance", lockFilename)) } locking.LockInstance(lockFilename) err := os.Chdir(this.root) swalllow(err) this.command = fmt.Sprintf("%s/sbin/haproxy", this.root) if _, err := os.Stat(this.command); err != nil { panic(err) } this.setupLogging(this.logfile, "info", "panic") this.starting = true this.startedAt = time.Now() if this.haproxyStatsUrl != "" && this.influxdbAddr != "" && this.influxdbDbName != "" { rc, err := influxdb.NewConfig(this.influxdbAddr, this.influxdbDbName, "", "", time.Minute) if err != nil { panic(err) } telemetry.Default = influxdb.New(metrics.DefaultRegistry, rc) go func() { log.Info("telemetry started: %s", telemetry.Default.Name()) if err := telemetry.Default.Start(); err != nil { log.Error("telemetry: %v", err) } }() m := haproxyMetrics{ ctx: this, interval: time.Second * 30, uri: this.haproxyStatsUrl, } go m.start() } this.quitCh = make(chan struct{}) this.closed = make(chan struct{}) signal.RegisterHandler(func(sig os.Signal) { log.Info("ehaproxy[%s] got signal: %s", gafka.BuildId, strings.ToUpper(sig.String())) this.shutdown() log.Info("removing %s", configFile) os.Remove(configFile) log.Info("removing lock[%s]", lockFilename) locking.UnlockInstance(lockFilename) close(this.quitCh) if telemetry.Default != nil { log.Info("stopping telemetry and flush all metrics...") telemetry.Default.Stop() } log.Info("ehaproxy[%s] shutdown complete", gafka.BuildId) log.Info("ehaproxy[%s] %s bye!", gafka.BuildId, time.Since(this.startedAt)) close(this.closed) }, syscall.SIGINT, syscall.SIGTERM) this.main() <-this.closed log.Close() return }