Skip to content

Commit

Permalink
Merge pull request rook#152 from travisn/demo-defaults
Browse files Browse the repository at this point in the history
Simplify the defaults for the demo scenario
  • Loading branch information
Travis Nielsen authored Nov 8, 2016
2 parents 3a3563b + 51530b3 commit 3ab8958
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
35 changes: 22 additions & 13 deletions cmd/rook/rook.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ var (
)

const (
systemLogDir = "/var/log/rook"
debugLogVar = "ROOK_DEBUG_DIR"
logFileName = "rook.log"
outputPadding = 3
outputMinWidth = 10
outputTabWidth = 0
outputPadChar = ' '
logFileName = "rook.log"
)

var rootCmd = &cobra.Command{
Expand All @@ -31,17 +31,7 @@ var rootCmd = &cobra.Command{
}

func Main() {
// set up logging to a log file instead of stdout (only command output and errors should go to stdout/stderr)
if err := os.MkdirAll(systemLogDir, 0744); err != nil {
log.Fatalf("failed to create logging dir '%s': %+v", systemLogDir, err)
}
logFilePath := filepath.Join(systemLogDir, logFileName)
logFile, err := os.OpenFile(logFilePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
log.Fatalf("failed to open log file '%s': %v", logFilePath, err)
}
defer logFile.Close()
log.SetOutput(logFile)
enableLogging()

addCommands()
if err := rootCmd.Execute(); err != nil {
Expand All @@ -67,3 +57,22 @@ func addCommands() {
func NewTableWriter(buffer io.Writer) *tabwriter.Writer {
return tabwriter.NewWriter(buffer, outputMinWidth, outputTabWidth, outputPadding, outputPadChar, 0)
}

func enableLogging() {
debugDir := os.Getenv(debugLogVar)
if debugDir == "" {
return
}

// set up logging to a log file instead of stdout (only command output and errors should go to stdout/stderr)
if err := os.MkdirAll(debugDir, 0744); err != nil {
log.Fatalf("failed to create logging dir '%s': %+v", debugDir, err)
}
logFilePath := filepath.Join(debugDir, logFileName)
logFile, err := os.OpenFile(logFilePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
log.Fatalf("failed to open log file '%s': %v", logFilePath, err)
}
defer logFile.Close()
log.SetOutput(logFile)
}
9 changes: 3 additions & 6 deletions cmd/rookd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func init() {
rootCmd.Flags().StringVar(&cfg.nodeID, "id", "", "unique identifier in the cluster for this machine. defaults to /etc/machine-id if found.")
rootCmd.Flags().StringVar(&cfg.discoveryURL, "discovery-url", "", "etcd discovery URL. Example: http://discovery.rook.com/26bd83c92e7145e6b103f623263f61df")
rootCmd.Flags().StringVar(&cfg.etcdMembers, "etcd-members", "", "etcd members to connect to. Overrides the discovery URL. Example: http://10.23.45.56:2379")
rootCmd.Flags().StringVar(&cfg.publicIPv4, "public-ipv4", "", "public IPv4 address for this machine (required)")
rootCmd.Flags().StringVar(&cfg.privateIPv4, "private-ipv4", "", "private IPv4 address for this machine (required)")
rootCmd.Flags().StringVar(&cfg.publicIPv4, "public-ipv4", "127.0.0.1", "public IPv4 address for this machine")
rootCmd.Flags().StringVar(&cfg.privateIPv4, "private-ipv4", "127.0.0.1", "private IPv4 address for this machine")
rootCmd.Flags().StringVar(&cfg.devices, "data-devices", "", "comma separated list of devices to use for storage")
rootCmd.Flags().StringVar(&cfg.dataDir, "data-dir", "/var/lib/rook", "directory for storing configuration")
rootCmd.Flags().BoolVar(&cfg.forceFormat, "force-format", false,
Expand All @@ -75,9 +75,6 @@ func init() {

rootCmd.PersistentFlags().BoolVar(&cfg.debug, "debug", false, "true to enable debug logging/tracing")

rootCmd.MarkFlagRequired("private-ipv4")
rootCmd.MarkFlagRequired("public-ipv4")

// load the environment variables
setFlagsFromEnv(rootCmd.Flags())

Expand All @@ -91,7 +88,7 @@ func addCommands() {

func startJoinCluster(cmd *cobra.Command, args []string) error {
// verify required flags
if err := flags.VerifyRequiredFlags(cmd, []string{"private-ipv4", "public-ipv4"}); err != nil {
if err := flags.VerifyRequiredFlags(cmd, []string{}); err != nil {
return err
}

Expand Down

0 comments on commit 3ab8958

Please sign in to comment.