Skip to content

Commit

Permalink
Expand config file functionality to log_server, log_signer, and map_s…
Browse files Browse the repository at this point in the history
…erver
  • Loading branch information
Roland Shoemaker committed May 23, 2017
1 parent 4712f74 commit ddcc786
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 13 deletions.
12 changes: 2 additions & 10 deletions cmd/createtree/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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.
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 9 additions & 3 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cmd
import (
"flag"
"io/ioutil"

"github.com/mattn/go-shellwords"
)

func ParseFlagFile(path string) error {
Expand All @@ -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
}
13 changes: 13 additions & 0 deletions server/trillian_log_server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ package main
import (
"context"
"flag"
"fmt"
_ "net/http/pprof"
"os"
"strings"
"time"

Expand All @@ -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"
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions server/trillian_log_signer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 ****")

Expand Down
12 changes: 12 additions & 0 deletions server/vmap/trillian_map_server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down

0 comments on commit ddcc786

Please sign in to comment.