code.vegaprotocol.io/vega@v0.79.0/cmd/data-node/commands/start/node_post.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package start
    17  
    18  import (
    19  	"strings"
    20  
    21  	"code.vegaprotocol.io/vega/logging"
    22  
    23  	"github.com/pkg/errors"
    24  )
    25  
    26  type errStack []error
    27  
    28  func (l *NodeCommand) postRun(_ []string) error {
    29  	var werr errStack
    30  
    31  	postLog := l.Log.Named("postRun")
    32  
    33  	if l.embeddedPostgres != nil {
    34  		if err := l.embeddedPostgres.Stop(); err != nil {
    35  			werr = append(werr, errors.Wrap(err, "error closing embedded postgres in command"))
    36  		}
    37  	}
    38  	if l.pproffhandlr != nil {
    39  		if err := l.pproffhandlr.Stop(); err != nil {
    40  			werr = append(werr, errors.Wrap(err, "error stopping pprof"))
    41  		}
    42  	}
    43  
    44  	postLog.Info("Vega datanode shutdown complete",
    45  		logging.String("version", l.Version),
    46  		logging.String("version-hash", l.VersionHash))
    47  
    48  	postLog.Sync()
    49  
    50  	if len(werr) == 0 {
    51  		// Prevent printing of empty error and exiting with non-zero code.
    52  		return nil
    53  	}
    54  	return werr
    55  }
    56  
    57  func (l *NodeCommand) persistentPost(_ []string) error {
    58  	l.cancel()
    59  	return nil
    60  }
    61  
    62  // Error - implement the error interface on the errStack type.
    63  func (e errStack) Error() string {
    64  	s := make([]string, 0, len(e))
    65  	for _, err := range e {
    66  		s = append(s, err.Error())
    67  	}
    68  	return strings.Join(s, "\n")
    69  }