github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cmd/dm-ctl/main.go (about)

     1  // Copyright 2019 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package main
    15  
    16  import (
    17  	"fmt"
    18  	"os"
    19  	"os/signal"
    20  	"syscall"
    21  
    22  	"github.com/pingcap/tiflow/dm/ctl"
    23  	"github.com/pingcap/tiflow/dm/ctl/common"
    24  	"github.com/pingcap/tiflow/dm/pkg/log"
    25  	"github.com/pingcap/tiflow/dm/pkg/terror"
    26  	"github.com/pingcap/tiflow/dm/pkg/utils"
    27  )
    28  
    29  func main() {
    30  	// now, we use checker in dmctl while it using some pkg which log some thing when running
    31  	// to make dmctl output more clear, simply redirect log to file rather output to stdout
    32  	err := log.InitLogger(&log.Config{
    33  		File:  "dmctl.log",
    34  		Level: "info",
    35  	})
    36  	if err != nil {
    37  		common.PrintLinesf("init logger error %s", terror.Message(err))
    38  		os.Exit(2)
    39  	}
    40  
    41  	utils.LogHTTPProxies(false)
    42  
    43  	sc := make(chan os.Signal, 1)
    44  	signal.Notify(sc,
    45  		syscall.SIGHUP,
    46  		syscall.SIGINT,
    47  		syscall.SIGTERM,
    48  		syscall.SIGQUIT)
    49  
    50  	go func() {
    51  		sig := <-sc
    52  		fmt.Printf("\nGot signal [%v] to exit.\n", sig)
    53  		switch sig {
    54  		case syscall.SIGTERM:
    55  			os.Exit(0)
    56  		default:
    57  			os.Exit(1)
    58  		}
    59  	}()
    60  
    61  	ctl.MainStart(common.AdjustArgumentsForPflags(os.Args[1:]))
    62  }