2013-12-03 22:19:42 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2014-11-11 05:25:03 +00:00
|
|
|
"log"
|
2013-12-03 22:19:42 +00:00
|
|
|
"os"
|
2014-11-21 03:31:04 +00:00
|
|
|
"strings"
|
2013-12-03 22:19:42 +00:00
|
|
|
)
|
|
|
|
|
2014-10-22 05:32:19 +00:00
|
|
|
const logo = `
|
|
|
|
+---------------------------------------------+
|
|
|
|
| _____ __ _ _____ ____ |
|
|
|
|
| |_ _| / _| | | __ \| _ \ |
|
|
|
|
| | | _ __ | |_| |_ ___ _| | | | |_) | |
|
|
|
|
| | | | '_ \| _| | | | \ \/ / | | | _ < |
|
|
|
|
| _| |_| | | | | | | |_| |> <| |__| | |_) | |
|
|
|
|
| |_____|_| |_|_| |_|\__,_/_/\_\_____/|____/ |
|
|
|
|
+---------------------------------------------+
|
|
|
|
`
|
|
|
|
|
2014-11-18 00:34:47 +00:00
|
|
|
// These variables are populated via the Go linker.
|
|
|
|
var (
|
2014-12-06 01:02:30 +00:00
|
|
|
version string = "0.9"
|
2014-11-18 00:34:47 +00:00
|
|
|
commit string
|
|
|
|
)
|
|
|
|
|
2014-12-11 21:49:42 +00:00
|
|
|
// Various constants used by the main package.
|
|
|
|
const (
|
|
|
|
configDefaultPath string = "/etc/influxdb.conf"
|
|
|
|
)
|
|
|
|
|
2013-12-03 22:19:42 +00:00
|
|
|
func main() {
|
2014-12-06 01:02:30 +00:00
|
|
|
log.SetFlags(0)
|
|
|
|
|
|
|
|
// Shift binary name off argument list.
|
|
|
|
args := os.Args[1:]
|
|
|
|
|
|
|
|
// Retrieve command name as first argument.
|
|
|
|
var cmd string
|
|
|
|
if len(args) > 0 && !strings.HasPrefix(args[0], "-") {
|
|
|
|
cmd = args[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Special case -h immediately following binary name
|
2014-12-12 00:04:53 +00:00
|
|
|
if len(args) > 0 && args[0] == "-h" {
|
2014-12-06 01:02:30 +00:00
|
|
|
cmd = "help"
|
|
|
|
}
|
|
|
|
|
|
|
|
// If command is "help" and has an argument then rewrite args to use "-h".
|
|
|
|
if cmd == "help" && len(args) > 1 {
|
|
|
|
args[0], args[1] = args[1], "-h"
|
|
|
|
cmd = args[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract name from args.
|
|
|
|
switch cmd {
|
|
|
|
case "create-cluster":
|
|
|
|
execCreateCluster(args[1:])
|
|
|
|
case "join-cluster":
|
|
|
|
execJoinCluster(args[1:])
|
|
|
|
case "run":
|
|
|
|
execRun(args[1:])
|
|
|
|
case "":
|
|
|
|
execRun(args)
|
|
|
|
case "version":
|
|
|
|
execVersion(args[1:])
|
|
|
|
case "help":
|
|
|
|
execHelp(args[1:])
|
|
|
|
default:
|
|
|
|
log.Fatalf(`influxd: unknown command "%s"`+"\n"+`Run 'influxd help' for usage`+"\n\n", cmd)
|
2014-11-04 20:36:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-06 01:02:30 +00:00
|
|
|
// execVersion runs the "version" command.
|
|
|
|
// Prints the commit SHA1 if set by the build process.
|
|
|
|
func execVersion(args []string) {
|
|
|
|
fs := flag.NewFlagSet("", flag.ExitOnError)
|
|
|
|
fs.Usage = func() {
|
|
|
|
log.Println(`usage: version
|
2014-10-22 00:20:43 +00:00
|
|
|
|
2014-12-06 01:02:30 +00:00
|
|
|
version displays the InfluxDB version and build git commit hash
|
|
|
|
`)
|
2013-12-03 22:19:42 +00:00
|
|
|
}
|
2014-12-06 01:02:30 +00:00
|
|
|
fs.Parse(args)
|
2014-11-11 05:25:03 +00:00
|
|
|
|
2014-12-06 01:02:30 +00:00
|
|
|
s := fmt.Sprintf("InfluxDB v%s", version)
|
|
|
|
if commit != "" {
|
|
|
|
s += fmt.Sprintf(" (git: %s)", commit)
|
2014-03-27 23:09:08 +00:00
|
|
|
}
|
2014-12-06 01:02:30 +00:00
|
|
|
log.Print(s)
|
|
|
|
}
|
2014-03-27 16:24:40 +00:00
|
|
|
|
2014-12-06 01:02:30 +00:00
|
|
|
// execHelp runs the "help" command.
|
|
|
|
func execHelp(args []string) {
|
|
|
|
fmt.Println(`
|
|
|
|
Configure and start an InfluxDB server.
|
2014-11-11 05:25:03 +00:00
|
|
|
|
2014-12-06 01:02:30 +00:00
|
|
|
Usage:
|
2014-11-11 05:25:03 +00:00
|
|
|
|
2014-12-06 01:02:30 +00:00
|
|
|
influxd [[command] [arguments]]
|
2014-11-11 05:25:03 +00:00
|
|
|
|
2014-12-06 01:02:30 +00:00
|
|
|
The commands are:
|
2014-11-11 05:25:03 +00:00
|
|
|
|
2014-12-06 01:02:30 +00:00
|
|
|
create-cluster create a new node that other nodes can join to form a new cluster
|
|
|
|
join-cluster create a new node that will join an existing cluster
|
|
|
|
run run node with existing configuration
|
|
|
|
version displays the InfluxDB version
|
2014-10-21 05:32:47 +00:00
|
|
|
|
2014-12-06 01:02:30 +00:00
|
|
|
"run" is the default command.
|
2014-10-21 05:32:47 +00:00
|
|
|
|
2014-12-06 01:02:30 +00:00
|
|
|
Use "influxd help [command]" for more information about a command.
|
|
|
|
`)
|
2014-10-21 05:32:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Stopper interface {
|
|
|
|
Stop()
|
|
|
|
}
|
2014-12-06 01:02:30 +00:00
|
|
|
|
|
|
|
type State struct {
|
|
|
|
Mode string `json:"mode"`
|
|
|
|
}
|