2015-07-07 00:54:22 +00:00
|
|
|
// Copyright 2014 The go-ethereum Authors
|
|
|
|
// This file is part of go-ethereum.
|
|
|
|
//
|
|
|
|
// go-ethereum is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// go-ethereum is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-07-22 16:48:40 +00:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-07-07 00:54:22 +00:00
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
2015-07-22 16:48:40 +00:00
|
|
|
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
2015-01-06 11:13:57 +00:00
|
|
|
|
2015-07-07 03:08:16 +00:00
|
|
|
// Package utils contains internal helper functions for go-ethereum commands.
|
2014-05-14 10:41:30 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
2014-06-26 17:41:36 +00:00
|
|
|
"fmt"
|
2015-03-18 12:36:48 +00:00
|
|
|
"io"
|
2014-08-14 23:07:40 +00:00
|
|
|
"os"
|
2016-09-26 15:23:26 +00:00
|
|
|
"runtime"
|
2014-08-14 23:07:40 +00:00
|
|
|
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/node"
|
2022-10-25 02:58:25 +00:00
|
|
|
"github.com/ledgerwatch/erigon/turbo/debug"
|
2015-05-27 23:16:57 +00:00
|
|
|
)
|
|
|
|
|
2015-05-27 13:48:07 +00:00
|
|
|
// Fatalf formats a message to standard error and exits the program.
|
|
|
|
// The message is also printed to standard output if standard error
|
|
|
|
// is redirected to a different file.
|
2015-03-06 02:00:41 +00:00
|
|
|
func Fatalf(format string, args ...interface{}) {
|
2015-05-27 13:48:07 +00:00
|
|
|
w := io.MultiWriter(os.Stdout, os.Stderr)
|
2016-09-26 15:23:26 +00:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
// The SameFile check below doesn't work on Windows.
|
|
|
|
// stdout is unlikely to get redirected though, so just print there.
|
|
|
|
w = os.Stdout
|
|
|
|
} else {
|
|
|
|
outf, _ := os.Stdout.Stat()
|
|
|
|
errf, _ := os.Stderr.Stat()
|
|
|
|
if outf != nil && errf != nil && os.SameFile(outf, errf) {
|
|
|
|
w = os.Stderr
|
|
|
|
}
|
2015-05-27 13:48:07 +00:00
|
|
|
}
|
|
|
|
fmt.Fprintf(w, "Fatal: "+format+"\n", args...)
|
2015-03-06 02:00:41 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2021-03-12 17:26:06 +00:00
|
|
|
func StartNode(stack *node.Node) {
|
2015-11-17 16:33:25 +00:00
|
|
|
if err := stack.Start(); err != nil {
|
2017-02-22 15:22:50 +00:00
|
|
|
Fatalf("Error starting protocol stack: %v", err)
|
2015-01-05 16:12:52 +00:00
|
|
|
}
|
2021-01-19 08:26:42 +00:00
|
|
|
|
2021-09-11 11:16:39 +00:00
|
|
|
go debug.ListenSignals(stack)
|
2015-03-06 02:25:57 +00:00
|
|
|
}
|