lnd.xprv/cmd/lncli/main.go
halseth aa4e166539 lnrpc+rpc+lnd: add new Stop command for gracefully shutting down lnd
This commit adds simple non-blocking stop command to lncli, with an
appropriate proto update and implementation within the rpcserver.  When
invoked the interrupt handler routine in signal.go with begin the graceful
shutdown of lnd.
2017-05-11 14:55:56 -07:00

89 lines
1.7 KiB
Go

package main
import (
"fmt"
"os"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/urfave/cli"
"google.golang.org/grpc"
)
func fatal(err error) {
fmt.Fprintf(os.Stderr, "[lncli] %v\n", err)
os.Exit(1)
}
func getClient(ctx *cli.Context) (lnrpc.LightningClient, func()) {
conn := getClientConn(ctx)
cleanUp := func() {
conn.Close()
}
return lnrpc.NewLightningClient(conn), cleanUp
}
func getClientConn(ctx *cli.Context) *grpc.ClientConn {
// TODO(roasbeef): macaroon based auth
// * http://www.grpc.io/docs/guides/auth.html
// * http://research.google.com/pubs/pub41892.html
// * https://github.com/go-macaroon/macaroon
opts := []grpc.DialOption{grpc.WithInsecure()}
conn, err := grpc.Dial(ctx.GlobalString("rpcserver"), opts...)
if err != nil {
fatal(err)
}
return conn
}
func main() {
app := cli.NewApp()
app.Name = "lncli"
app.Version = "0.2"
app.Usage = "control plane for your Lightning Network Daemon (lnd)"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "rpcserver",
Value: "localhost:10009",
Usage: "host:port of ln daemon",
},
}
app.Commands = []cli.Command{
newAddressCommand,
sendManyCommand,
sendCoinsCommand,
connectCommand,
disconnectCommand,
openChannelCommand,
closeChannelCommand,
listPeersCommand,
walletBalanceCommand,
channelBalanceCommand,
getInfoCommand,
pendingChannelsCommand,
sendPaymentCommand,
addInvoiceCommand,
lookupInvoiceCommand,
listInvoicesCommand,
listChannelsCommand,
listPaymentsCommand,
describeGraphCommand,
getChanInfoCommand,
getNodeInfoCommand,
queryRoutesCommand,
getNetworkInfoCommand,
debugLevelCommand,
decodePayReqComamnd,
listChainTxnsCommand,
stopCommand,
}
if err := app.Run(os.Args); err != nil {
fatal(err)
}
}