lightning-terminal/cmd/litcli/proxy.go
Elle Mouton dbe62e074a
multi: add StopDaemon method to Lit
In this commit, a new Proxy service is added with a StopDaemon method.
This method can be used to stop the Litd service. This will be useful in
remote-mode itests where we want to restart Litd without also restarting
LND. It also provides a nice way of shutting down Litd in remote-mode.
A GetInfo method is also added to the service which for now just returns
the Litd version. The reason for adding this method now is so that
access to the new Proxy service can be tested in the itests withouth
actually shutting down Litd.
2023-03-17 11:14:24 +02:00

63 lines
1.1 KiB
Go

package main
import (
"context"
"fmt"
"github.com/lightninglabs/lightning-terminal/litrpc"
"github.com/urfave/cli"
)
var litCommands = []cli.Command{
{
Name: "stop",
Usage: "shutdown the LiT daemon",
Category: "LiT",
Action: shutdownLit,
},
{
Name: "getinfo",
Usage: "Returns basic information related to the active " +
"daemon.",
Category: "LiT",
Action: getInfo,
},
}
func getInfo(ctx *cli.Context) error {
clientConn, cleanup, err := connectClient(ctx)
if err != nil {
return err
}
defer cleanup()
client := litrpc.NewProxyClient(clientConn)
ctxb := context.Background()
resp, err := client.GetInfo(ctxb, &litrpc.GetInfoRequest{})
if err != nil {
return err
}
printRespJSON(resp)
return nil
}
func shutdownLit(ctx *cli.Context) error {
clientConn, cleanup, err := connectClient(ctx)
if err != nil {
return err
}
defer cleanup()
client := litrpc.NewProxyClient(clientConn)
ctxb := context.Background()
_, err = client.StopDaemon(ctxb, &litrpc.StopDaemonRequest{})
if err != nil {
return err
}
fmt.Println("Successfully shutdown LiTd")
return nil
}