fixing unix socket defaults.

This commit is contained in:
greg stone
2023-03-02 23:26:44 +00:00
parent 081013f321
commit d4cda28e62
5 changed files with 25 additions and 9 deletions

View File

@@ -42,7 +42,7 @@ func init() {
cobra.OnFinalize(persistConfig)
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config-file", "C", "", "config file (default is $HOME/.indra.toml)")
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config-file", "C", "", "config file (default is $HOME/.indra/config.toml)")
rootCmd.PersistentFlags().BoolVarP(&cfgSave, "config-save", "", false, "saves the config file with any eligible envs/flags passed")
rootCmd.PersistentFlags().StringVarP(&logsDir, "logs-dir", "L", "", "logging directory (default is $HOME/.indra/logs)")
rootCmd.PersistentFlags().StringVarP(&logsLevel, "logs-level", "", "info", "set logging level off|fatal|error|warn|info|check|debug|trace")

View File

@@ -3,6 +3,7 @@ package rpc
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"os"
)
var (
@@ -20,16 +21,18 @@ var (
func InitFlags(cmd *cobra.Command) {
cobra.OnInitialize(initUnixSockPath)
cmd.PersistentFlags().StringVarP(&unixPath, unixPathFlag, "",
unixPath,
"binds to a unix socket with path",
"",
"binds to a unix socket with path (default is $HOME/.indra/indra.sock)",
)
viper.BindPFlag(unixPathFlag, cmd.PersistentFlags().Lookup(unixPathFlag))
cmd.PersistentFlags().BoolVarP(&isTunnelEnabled, tunEnableFlag, "",
isTunnelEnabled,
"enables the rpc server tunnel",
false,
"enables the rpc server tunnel (default false)",
)
viper.BindPFlag(tunEnableFlag, cmd.PersistentFlags().Lookup(tunEnableFlag))
@@ -55,3 +58,16 @@ func InitFlags(cmd *cobra.Command) {
viper.BindPFlag(tunPeersFlag, cmd.PersistentFlags().Lookup(tunPeersFlag))
}
func initUnixSockPath() {
if viper.GetString(unixPathFlag) != "" {
return
}
home, err := os.UserHomeDir()
cobra.CheckErr(err)
viper.Set(unixPathFlag, home+"/.indra/indra.sock")
}

View File

@@ -36,13 +36,13 @@ func RunWith(r func(srv *grpc.Server), opts ...ServerOption) {
r(server)
log.I.Ln("starting rpc server")
go start()
}
func start() {
log.I.Ln("starting rpc server")
var err error
createTunnel()

View File

@@ -9,7 +9,7 @@ import (
var (
isUnixSockEnabled bool = false
unixSock net.Listener
unixPath = "/tmp/indra.sock"
unixPath string
)
func startUnixSocket(srv *grpc.Server) (err error) {

View File

@@ -39,7 +39,7 @@ func InitFlags(cmd *cobra.Command) {
cmd.PersistentFlags().StringVarP(&storeFilePath, storeFilePathFlag, "",
"",
"the path of the database (defaults to --data-dir/indra.db)",
"the path of the database (default is <data-dir>/indra.db)",
)
viper.BindPFlag(storeFilePathFlag, cmd.PersistentFlags().Lookup(storeFilePathFlag))