1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

Revert "add arg -confdir"

This commit is contained in:
Kslr 2020-01-02 01:14:36 +08:00 committed by GitHub
parent 1cb43035f1
commit e6f226c64d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 64 deletions

View File

@ -4,7 +4,6 @@ import (
"io"
"os"
"os/exec"
"strings"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/platform"
@ -36,14 +35,14 @@ func Run(args []string, input io.Reader) (buf.MultiBuffer, error) {
if err := cmd.Wait(); err != nil {
msg := "failed to execute v2ctl"
if errBuffer.Len() > 0 {
msg += ": \n" + strings.TrimSpace(errBuffer.MultiBuffer.String())
msg += ": " + errBuffer.MultiBuffer.String()
}
return nil, newError(msg).Base(err)
}
// log stderr, info message
if !errBuffer.IsEmpty() {
newError("<v2ctl message> \n", strings.TrimSpace(errBuffer.MultiBuffer.String())).AtInfo().WriteToLog()
newError("v2ctl > \n", errBuffer.MultiBuffer.String()).AtInfo().WriteToLog()
}
return outBuffer.MultiBuffer, nil

View File

@ -83,10 +83,3 @@ func GetConfigurationPath() string {
configPath := NewEnvFlag(name).GetValue(getExecutableDir)
return filepath.Join(configPath, "config.json")
}
// GetConfDirPath reads "v2ray.location.confdir"
func GetConfDirPath() string {
const name = "v2ray.location.confdir"
configPath := NewEnvFlag(name).GetValue(func() string { return "" })
return configPath
}

View File

@ -2,8 +2,6 @@ package conf
import (
"encoding/json"
"log"
"os"
"strings"
"v2ray.com/core"
@ -33,8 +31,6 @@ var (
"mtproto": func() interface{} { return new(MTProtoClientConfig) },
"dns": func() interface{} { return new(DnsOutboundConfig) },
}, "protocol", "settings")
ctllog = log.New(os.Stderr, "v2ctl> ", 0)
)
func toProtocolList(s []string) ([]proxyman.KnownProtocols, error) {
@ -365,10 +361,10 @@ func (c *Config) Override(o *Config, fn string) {
if len(c.InboundConfigs) > 0 && len(o.InboundConfigs) == 1 {
if idx := c.findInboundTag(o.InboundConfigs[0].Tag); idx > -1 {
c.InboundConfigs[idx] = o.InboundConfigs[0]
ctllog.Println("[", fn, "] updated inbound with tag: ", o.InboundConfigs[0].Tag)
newError("<", fn, "> updated inbound with tag: ", o.InboundConfigs[0].Tag).AtInfo().WriteToLog()
} else {
c.InboundConfigs = append(c.InboundConfigs, o.InboundConfigs[0])
ctllog.Println("[", fn, "] appended inbound with tag: ", o.InboundConfigs[0].Tag)
newError("<", fn, "> appended inbound with tag: ", o.InboundConfigs[0].Tag).AtInfo().WriteToLog()
}
} else {
c.InboundConfigs = o.InboundConfigs
@ -380,14 +376,14 @@ func (c *Config) Override(o *Config, fn string) {
if len(c.OutboundConfigs) > 0 && len(o.OutboundConfigs) == 1 {
if idx := c.findOutboundTag(o.OutboundConfigs[0].Tag); idx > -1 {
c.OutboundConfigs[idx] = o.OutboundConfigs[0]
ctllog.Println("[", fn, "] updated outbound with tag: ", o.OutboundConfigs[0].Tag)
newError("<", fn, "> updated outbound with tag: ", o.OutboundConfigs[0].Tag).AtInfo().WriteToLog()
} else {
if strings.Contains(strings.ToLower(fn), "tail") {
c.OutboundConfigs = append(c.OutboundConfigs, o.OutboundConfigs[0])
ctllog.Println("[", fn, "] appended outbound with tag: ", o.OutboundConfigs[0].Tag)
newError("<", fn, "> appended outbound with tag: ", o.OutboundConfigs[0].Tag).AtInfo().WriteToLog()
} else {
c.OutboundConfigs = append(o.OutboundConfigs, c.OutboundConfigs...)
ctllog.Println("[", fn, "] prepended outbound with tag: ", o.OutboundConfigs[0].Tag)
newError("<", fn, "> prepended outbound with tag: ", o.OutboundConfigs[0].Tag).AtInfo().WriteToLog()
}
}
} else {

View File

@ -2,8 +2,6 @@ package control
import (
"fmt"
"log"
"os"
"strings"
)
@ -20,7 +18,6 @@ type Command interface {
var (
commandRegistry = make(map[string]Command)
ctllog = log.New(os.Stderr, "v2ctl> ", 0)
)
func RegisterCommand(cmd Command) error {

View File

@ -37,13 +37,11 @@ func (c *ConfigCommand) Execute(args []string) error {
conf := &conf.Config{}
for _, arg := range args {
ctllog.Println("Read config: ", arg)
newError("Reading config: ", arg).AtInfo().WriteToLog()
r, err := c.LoadArg(arg)
common.Must(err)
c, err := serial.DecodeJSONConfig(r)
if err != nil {
ctllog.Fatalln(err)
}
common.Must(err)
conf.Override(c, arg)
}

View File

@ -5,11 +5,8 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/signal"
"path"
"path/filepath"
"runtime"
"strings"
@ -23,10 +20,10 @@ import (
var (
configFiles cmdarg.Arg // "Config file for V2Ray.", the option is customed type, parse in main
configDir string
version = flag.Bool("version", false, "Show current version of V2Ray.")
test = flag.Bool("test", false, "Test config file only, without launching V2Ray server.")
format = flag.String("format", "json", "Format of input file.")
errNoConfig = newError("no valid config")
)
func fileExists(file string) bool {
@ -34,27 +31,7 @@ func fileExists(file string) bool {
return err == nil && !info.IsDir()
}
func dirExists(file string) bool {
info, err := os.Stat(file)
return err == nil && info.IsDir()
}
func readConfDir(dirPath string) {
confs, err := ioutil.ReadDir(dirPath)
if err != nil {
log.Fatalln(err)
}
for _, f := range confs {
if strings.HasSuffix(f.Name(), ".json") {
configFiles.Set(path.Join(dirPath, f.Name()))
}
}
}
func getConfigFilePath() (cmdarg.Arg, error) {
if dirExists(configDir) {
readConfDir(configDir)
}
if len(configFiles) > 0 {
return configFiles, nil
}
@ -62,25 +39,14 @@ func getConfigFilePath() (cmdarg.Arg, error) {
if workingDir, err := os.Getwd(); err == nil {
configFile := filepath.Join(workingDir, "config.json")
if fileExists(configFile) {
log.Println("Using default config: ", configFile)
return cmdarg.Arg{configFile}, nil
}
}
if configFile := platform.GetConfigurationPath(); fileExists(configFile) {
log.Println("Using config from env: ", configFile)
return cmdarg.Arg{configFile}, nil
}
if envConfDir := platform.GetConfDirPath(); dirExists(envConfDir) {
log.Println("Using confdir from env: ", envConfDir)
readConfDir(envConfDir)
if len(configFiles) > 0 {
return configFiles, nil
}
}
log.Println("Using config from STDIN")
return cmdarg.Arg{"stdin:"}, nil
}
@ -121,8 +87,7 @@ func printVersion() {
func main() {
flag.Var(&configFiles, "config", "Config file for V2Ray. Multiple assign is accepted (only json). Latter ones overrides the former ones.")
flag.Var(&configFiles, "c", "Short alias of -config")
flag.StringVar(&configDir, "confdir", "", "A dir with multiple json config")
flag.Var(&configFiles, "c", "short alias of -config")
flag.Parse()
printVersion()
@ -133,8 +98,11 @@ func main() {
server, err := startV2Ray()
if err != nil {
fmt.Println(err)
fmt.Println(err.Error())
// Configuration error. Exit with a special value to prevent systemd from restarting.
if err == errNoConfig {
flag.PrintDefaults()
}
os.Exit(23)
}