diff --git a/cmd/createtree/main.go b/cmd/createtree/main.go index 9cc0a0bac3..f35c1673ae 100644 --- a/cmd/createtree/main.go +++ b/cmd/createtree/main.go @@ -48,7 +48,6 @@ import ( ) var ( - configFile = flag.String("config", "", "Config file containing flags") adminServerAddr = flag.String("admin_server", "", "Address of the gRPC Trillian Admin Server (host:port)") treeState = flag.String("tree_state", trillian.TreeState_ACTIVE.String(), "State of the new tree") @@ -62,6 +61,8 @@ var ( privateKeyFormat = flag.String("private_key_format", "PEMKeyFile", "Type of private key to be used") pemKeyPath = flag.String("pem_key_path", "", "Path to the private key PEM file") pemKeyPassword = flag.String("pem_key_password", "", "Password of the private key PEM file") + + configFile = flag.String("config", "", "Config file containing flags, file contents can be overridden by command line flags") ) // createOpts contains all user-supplied options required to run the program. @@ -178,19 +179,10 @@ func main() { flag.Parse() if *configFile != "" { - if flag.NFlag() != 1 { - fmt.Printf("No other flags can be provided when --config is set") - os.Exit(1) - } - if err := cmd.ParseFlagFile(*configFile); err != nil { fmt.Fprintf(os.Stderr, "Failed to parse %v: %v\n", *configFile, err) os.Exit(1) } - - // Alternative to printing error if more than just "--config" flag is provided: - // let command-line flags take precedent by re-parsing from the command-line. - // flag.Parse() } ctx := context.Background() diff --git a/cmd/flags.go b/cmd/flags.go index 25232ae211..daf7575a95 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -3,8 +3,6 @@ package cmd import ( "flag" "io/ioutil" - - "github.com/mattn/go-shellwords" ) func ParseFlagFile(path string) error { @@ -20,5 +18,13 @@ func ParseFlagFile(path string) error { return err } - return flag.CommandLine.Parse(args) + err = flag.CommandLine.Parse(args) + if err != nil { + return err + } + + // Call flag.Parse() again so that command line flags + // can override flags provided in the provided flag file. + flag.Parse() + return nil } diff --git a/server/trillian_log_server/main.go b/server/trillian_log_server/main.go index 84b741f403..8ca07c4585 100644 --- a/server/trillian_log_server/main.go +++ b/server/trillian_log_server/main.go @@ -17,7 +17,9 @@ package main import ( "context" "flag" + "fmt" _ "net/http/pprof" + "os" "strings" "time" @@ -27,6 +29,7 @@ import ( etcdnaming "github.com/coreos/etcd/clientv3/naming" "github.com/golang/glog" "github.com/google/trillian" + "github.com/google/trillian/cmd" "github.com/google/trillian/crypto/keys" "github.com/google/trillian/extension" "github.com/google/trillian/monitoring" @@ -48,10 +51,20 @@ var ( etcdServers = flag.String("etcd_servers", "", "A comma-separated list of etcd servers; no etcd registration if empty") etcdService = flag.String("etcd_service", "trillian-log", "Service name to announce ourselves under") maxUnsequencedRows = flag.Int("max_unsequenced_rows", mysqlq.DefaultMaxUnsequenced, "Max number of unsequenced rows before rate limiting kicks in") + + configFile = flag.String("config", "", "Config file containing flags, file contents can be overridden by command line flags") ) func main() { flag.Parse() + + if *configFile != "" { + if err := cmd.ParseFlagFile(*configFile); err != nil { + fmt.Fprintf(os.Stderr, "Failed to parse %v: %v\n", *configFile, err) + os.Exit(1) + } + } + ctx := context.Background() // First make sure we can access the database, quit if not diff --git a/server/trillian_log_signer/main.go b/server/trillian_log_signer/main.go index 93ce5d72f3..2a5e242b71 100644 --- a/server/trillian_log_signer/main.go +++ b/server/trillian_log_signer/main.go @@ -23,6 +23,7 @@ import ( _ "github.com/go-sql-driver/mysql" // Load MySQL driver "github.com/golang/glog" + "github.com/google/trillian/cmd" "github.com/google/trillian/crypto/keys" "github.com/google/trillian/extension" "github.com/google/trillian/monitoring/metric" @@ -50,10 +51,20 @@ var ( masterCheckInterval = flag.Duration("master_check_interval", 5*time.Second, "Interval between checking mastership still held") masterHoldInterval = flag.Duration("master_hold_interval", 60*time.Second, "Minimum interval to hold mastership for") resignOdds = flag.Int("resign_odds", 10, "Chance of resigning mastership after each check, the N in 1-in-N") + + configFile = flag.String("config", "", "Config file containing flags, file contents can be overridden by command line flags") ) func main() { flag.Parse() + + if *configFile != "" { + if err := cmd.ParseFlagFile(*configFile); err != nil { + fmt.Fprintf(os.Stderr, "Failed to parse %v: %v\n", *configFile, err) + os.Exit(1) + } + } + glog.CopyStandardLogTo("WARNING") glog.Info("**** Log Signer Starting ****") diff --git a/server/vmap/trillian_map_server/main.go b/server/vmap/trillian_map_server/main.go index 4a08525164..39eb01e7f9 100644 --- a/server/vmap/trillian_map_server/main.go +++ b/server/vmap/trillian_map_server/main.go @@ -17,12 +17,15 @@ package main import ( "context" "flag" + "fmt" _ "net/http/pprof" + "os" _ "github.com/go-sql-driver/mysql" // Load MySQL driver "github.com/golang/glog" "github.com/google/trillian" + "github.com/google/trillian/cmd" "github.com/google/trillian/crypto/keys" "github.com/google/trillian/extension" mysqlq "github.com/google/trillian/quota/mysql" @@ -39,11 +42,20 @@ var ( rpcEndpoint = flag.String("rpc_endpoint", "localhost:8090", "Endpoint for RPC requests (host:port)") httpEndpoint = flag.String("http_endpoint", "localhost:8091", "Endpoint for HTTP metrics and REST requests on (host:port, empty means disabled)") maxUnsequencedRows = flag.Int("max_unsequenced_rows", mysqlq.DefaultMaxUnsequenced, "Max number of unsequenced rows before rate limiting kicks in") + + configFile = flag.String("config", "", "Config file containing flags, file contents can be overridden by command line flags") ) func main() { flag.Parse() + if *configFile != "" { + if err := cmd.ParseFlagFile(*configFile); err != nil { + fmt.Fprintf(os.Stderr, "Failed to parse %v: %v\n", *configFile, err) + os.Exit(1) + } + } + db, err := mysql.OpenDB(*mySQLURI) if err != nil { glog.Exitf("Failed to open database: %v", err)