fix #40. Replace json with toml for configuration
parent
982015332b
commit
69544aa6bf
|
@ -154,6 +154,8 @@
|
|||
- [Issue #62](https://github.com/influxdb/influxdb/issues/62). Support updating and deleting column values
|
||||
- [Issue #96](https://github.com/influxdb/influxdb/issues/96). Replicate deletes in a cluster
|
||||
- [Issue #94](https://github.com/influxdb/influxdb/issues/94). delete queries
|
||||
- [Issue #116](https://github.com/influxdb/influxdb/issues/116). Use proper logging
|
||||
- [Issue #40](https://github.com/influxdb/influxdb/issues/40). Use TOML instead of JSON in the config file
|
||||
|
||||
## Bugfixes
|
||||
|
||||
|
|
51
Makefile.in
51
Makefile.in
|
@ -20,7 +20,7 @@ endif
|
|||
export GOARCH
|
||||
export CGO_ENABLED
|
||||
|
||||
.PHONY: all valgrind parser package package_init build
|
||||
.PHONY: all valgrind parser package package_init build binary_package
|
||||
|
||||
all: | parser valgrind build test integration_test
|
||||
|
||||
|
@ -100,6 +100,7 @@ github.com/fitstar/falcore/filter \
|
|||
github.com/gorilla/mux \
|
||||
github.com/goraft/raft \
|
||||
github.com/influxdb/go-cache \
|
||||
github.com/stvp/go-toml-config \
|
||||
$(proto_dependency)
|
||||
|
||||
dependencies_paths := $(addprefix src/,$(dependencies))
|
||||
|
@ -224,19 +225,37 @@ $(source_package): dependencies
|
|||
rm -rf src/$(levigo_dependency)
|
||||
rm -rf admin
|
||||
|
||||
sample_config = ' \
|
||||
{ \
|
||||
"AdminHttpPort": 8083, \
|
||||
"AdminAssetsDir": "/opt/influxdb/current/admin", \
|
||||
"ApiHttpPort": 8086, \
|
||||
"RaftServerPort": 8090, \
|
||||
"SeedServers": [], \
|
||||
"DataDir": "/opt/influxdb/shared/data/db", \
|
||||
"RaftDir": "/opt/influxdb/shared/data/raft" \
|
||||
} \
|
||||
'
|
||||
define sample_config
|
||||
# A command separated list of servers to seed
|
||||
# this server. this is only relevant when the
|
||||
# server is joining a new cluster. Otherwise
|
||||
# the server will use the list of known servers
|
||||
# prior to shutting down
|
||||
|
||||
$(binary_package): $(admin_dir)/build build
|
||||
# seed-servers =
|
||||
datadir = "/opt/influxdb/shared/data/db"
|
||||
|
||||
# Configure the admin server
|
||||
[admin]
|
||||
# port = 8083
|
||||
assets = "/opt/influxdb/current/admin"
|
||||
|
||||
# Configure the http api
|
||||
[api]
|
||||
# port = 8086
|
||||
|
||||
# Raft configuration
|
||||
[raft]
|
||||
# port = 8090
|
||||
dir = "/opt/influxdb/shared/data/raft"
|
||||
|
||||
# Protobuf configuration
|
||||
[protobuf]
|
||||
# port = 8099
|
||||
endef
|
||||
export sample_config
|
||||
|
||||
$(binary_package): $(admin_dir)/build build packages
|
||||
rm -rf build
|
||||
mkdir build
|
||||
mv daemon build/influxdb
|
||||
|
@ -244,11 +263,11 @@ $(binary_package): $(admin_dir)/build build
|
|||
cp -R $(admin_dir)/build/* build/admin/
|
||||
cp -R scripts/ build/
|
||||
rm -f build/scripts/post_install.sh.bak
|
||||
@echo $(sample_config) > build/config.json
|
||||
sed -i.bak 's/,/,\n/g' build/config.json
|
||||
rm build/config.json.bak
|
||||
@echo "$$sample_config" > build/config.toml
|
||||
tar -czf $(binary_package) build/*
|
||||
|
||||
binary_package: $(binary_package)
|
||||
|
||||
packages:
|
||||
mkdir $@
|
||||
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"AdminHttpPort": 8083,
|
||||
"AdminAssetsDir": "./admin/",
|
||||
"ApiHttpPort": 8086,
|
||||
"RaftServerPort": 8090,
|
||||
"SeedServers": [],
|
||||
"DataDir": "/tmp/influxdb/development/db",
|
||||
"RaftDir": "/tmp/influxdb/development/raft",
|
||||
"ProtobufPort": 8099
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
# A command separated list of servers to seed
|
||||
# this server. this is only relevant when the
|
||||
# server is joining a new cluster. Otherwise
|
||||
# the server will use the list of known servers
|
||||
# prior to shutting down
|
||||
|
||||
# seed-servers =
|
||||
# datadir = "/tmp/influxdb/development/db"
|
||||
|
||||
# Configure the admin server
|
||||
[admin]
|
||||
# port = 8083
|
||||
# assets = "./admin"
|
||||
|
||||
# Configure the http api
|
||||
[api]
|
||||
# port = 8086
|
||||
|
||||
# Raft configuration
|
||||
[raft]
|
||||
# port = 8090
|
||||
# dir = "/tmp/influxdb/development/raft"
|
||||
|
||||
# Protobuf configuration
|
||||
[protobuf]
|
||||
port = 8099
|
|
@ -87,11 +87,11 @@ case $1 in
|
|||
# Log the message appropriately
|
||||
cd /
|
||||
if which start-stop-daemon > /dev/null 2>&1; then
|
||||
nohup start-stop-daemon -d / --start --quiet --oknodo --pidfile $pidfile --exec $daemon -- -pidfile $pidfile -config /opt/$name/shared/config.json > /dev/null 2>> /opt/$name/shared/log.txt &
|
||||
nohup start-stop-daemon -d / --start --quiet --oknodo --pidfile $pidfile --exec $daemon -- -pidfile $pidfile -config /opt/$name/shared/config.toml > /dev/null 2>> /opt/$name/shared/log.txt &
|
||||
elif set | egrep '^start_daemon' > /dev/null 2>&1; then
|
||||
start_daemon ${daemon}-daemon -pidfile $pidfile -config /opt/$name/shared/config.json
|
||||
start_daemon ${daemon}-daemon -pidfile $pidfile -config /opt/$name/shared/config.toml
|
||||
else
|
||||
sudo ${daemon}-daemon -pidfile $pidfile -config /opt/$name/shared/config.json
|
||||
sudo ${daemon}-daemon -pidfile $pidfile -config /opt/$name/shared/config.toml
|
||||
fi
|
||||
log_success_msg "Anomalous agent started"
|
||||
;;
|
||||
|
|
|
@ -7,7 +7,7 @@ ln -sfn $influx_dir/versions/$version $influx_dir/current
|
|||
[ -e /usr/bin/influxdb ] || ln -sfn $influx_dir/current/influxdb /usr/bin/influxdb
|
||||
[ -e /usr/bin/influxdb-daemon ] || ln -sfn $influx_dir/current/scripts/influxdb-daemon.sh /usr/bin/influxdb-daemon
|
||||
[ -d $influx_dir/shared ] || mkdir $influx_dir/shared
|
||||
[ -e $influx_dir/shared/config.json ] || cp $influx_dir/current/config.json $influx_dir/shared/
|
||||
[ -e $influx_dir/shared/config.toml ] || cp $influx_dir/current/config.toml $influx_dir/shared/
|
||||
touch $influx_dir/shared/log.txt
|
||||
if [ ! -L /etc/init.d/influxdb ]; then
|
||||
ln -sfn $influx_dir/current/scripts/init.sh /etc/init.d/influxdb
|
||||
|
|
|
@ -3,9 +3,12 @@ package configuration
|
|||
import (
|
||||
log "code.google.com/p/log4go"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/stvp/go-toml-config"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Configuration struct {
|
||||
|
@ -21,6 +24,51 @@ type Configuration struct {
|
|||
}
|
||||
|
||||
func LoadConfiguration(fileName string) *Configuration {
|
||||
config, err := parseTomlConfiguration(fileName)
|
||||
if err != nil {
|
||||
log.Error("Couldn't parse configuration file: " + fileName)
|
||||
panic(err)
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
func parseTomlConfiguration(filename string) (*Configuration, error) {
|
||||
configSet := config.NewConfigSet("influxdb", flag.ContinueOnError)
|
||||
adminPort := configSet.Int("admin.port", 8083)
|
||||
adminAssetsDir := configSet.String("admin.assets", "./admin")
|
||||
apiHttpPort := configSet.Int("api.port", 8086)
|
||||
raftPort := configSet.Int("raft.port", 8090)
|
||||
raftDir := configSet.String("raft.dir", "/tmp/influxdb/development/raft")
|
||||
seedServers := configSet.String("seed-servers", "")
|
||||
dataDir := configSet.String("datadir", "/tmp/influxdb/development/db")
|
||||
protobufPort := configSet.Int("protobuf.port", 8099)
|
||||
|
||||
if err := configSet.Parse(filename); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
config := &Configuration{
|
||||
AdminHttpPort: *adminPort,
|
||||
AdminAssetsDir: *adminAssetsDir,
|
||||
ApiHttpPort: *apiHttpPort,
|
||||
RaftServerPort: *raftPort,
|
||||
RaftDir: *raftDir,
|
||||
ProtobufPort: *protobufPort,
|
||||
DataDir: *dataDir,
|
||||
}
|
||||
|
||||
servers := strings.Split(*seedServers, ",")
|
||||
for _, server := range servers {
|
||||
server = strings.TrimSpace(server)
|
||||
if server == "" {
|
||||
continue
|
||||
}
|
||||
config.SeedServers = append(config.SeedServers, server)
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func parseJsonConfiguration(fileName string) (*Configuration, error) {
|
||||
log.Info("Loading Config from " + fileName)
|
||||
config := &Configuration{}
|
||||
|
||||
|
@ -28,15 +76,14 @@ func LoadConfiguration(fileName string) *Configuration {
|
|||
if err == nil {
|
||||
err = json.Unmarshal(data, config)
|
||||
if err != nil {
|
||||
log.Error("Couldn't parse configuration file: " + fileName)
|
||||
panic(err)
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
log.Error("Couldn't load configuration file: " + fileName)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return config
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func (self *Configuration) AdminHttpPortString() string {
|
||||
|
|
|
@ -15,6 +15,6 @@ type LoadConfigurationSuite struct{}
|
|||
var _ = Suite(&LoadConfigurationSuite{})
|
||||
|
||||
func (self *LoadConfigurationSuite) TestConfig(c *C) {
|
||||
config := LoadConfiguration("../../config.json.sample")
|
||||
config := LoadConfiguration("../../config.toml.sample")
|
||||
c.Assert(config.DataDir, Equals, "/tmp/influxdb/development/db")
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ func setupLogging(loggingLevel string) {
|
|||
}
|
||||
|
||||
func main() {
|
||||
fileName := flag.String("config", "config.json.sample", "Config file")
|
||||
fileName := flag.String("config", "config.toml.sample", "Config file")
|
||||
wantsVersion := flag.Bool("v", false, "Get version number")
|
||||
resetRootPassword := flag.Bool("reset-root", false, "Reset root password")
|
||||
pidFile := flag.String("pidfile", "", "the pid file")
|
||||
|
|
Loading…
Reference in New Issue