bugfix: installation ID now follows configdir
This commit is contained in:
parent
0a77f89374
commit
e05083ebeb
|
|
@ -14,6 +14,7 @@ import (
|
||||||
config "github.com/jamesread/OliveTin/internal/config"
|
config "github.com/jamesread/OliveTin/internal/config"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -37,7 +38,7 @@ func init() {
|
||||||
|
|
||||||
log.SetLevel(log.DebugLevel) // Default to debug, to catch cfg issues
|
log.SetLevel(log.DebugLevel) // Default to debug, to catch cfg issues
|
||||||
|
|
||||||
var configDir string;
|
var configDir string
|
||||||
flag.StringVar(&configDir, "configdir", ".", "Config directory path")
|
flag.StringVar(&configDir, "configdir", ".", "Config directory path")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
|
@ -82,11 +83,15 @@ func reloadConfig() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.Info("OliveTin started")
|
configDir := path.Dir(viper.ConfigFileUsed())
|
||||||
|
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"configDir": configDir,
|
||||||
|
}).Infof("OliveTin started")
|
||||||
|
|
||||||
log.Debugf("Config: %+v", cfg)
|
log.Debugf("Config: %+v", cfg)
|
||||||
|
|
||||||
go updatecheck.StartUpdateChecker(version, commit, cfg)
|
go updatecheck.StartUpdateChecker(version, commit, cfg, configDir)
|
||||||
|
|
||||||
go grpcapi.Start(cfg)
|
go grpcapi.Start(cfg)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,24 +30,7 @@ var AvailableVersion = "none"
|
||||||
// CurrentVersion is set by the main cmd (which is in tern set as a compile constant)
|
// CurrentVersion is set by the main cmd (which is in tern set as a compile constant)
|
||||||
var CurrentVersion = "?"
|
var CurrentVersion = "?"
|
||||||
|
|
||||||
func getInstanceIDFilename() string {
|
func installationID(filename string) string {
|
||||||
directory := "./"
|
|
||||||
|
|
||||||
if _, err := os.Stat("/etc/OliveTin"); !os.IsNotExist(err) {
|
|
||||||
directory = "/etc/OliveTin/"
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := os.Stat("/config"); !os.IsNotExist(err) {
|
|
||||||
directory = "/config/"
|
|
||||||
}
|
|
||||||
|
|
||||||
return directory + "installation-id.txt"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func installationID() string {
|
|
||||||
filename := getInstanceIDFilename()
|
|
||||||
|
|
||||||
content := "unset"
|
content := "unset"
|
||||||
contentBytes, err := ioutil.ReadFile(filename)
|
contentBytes, err := ioutil.ReadFile(filename)
|
||||||
|
|
||||||
|
|
@ -64,10 +47,18 @@ func installationID() string {
|
||||||
fileHandle.Close()
|
fileHandle.Close()
|
||||||
} else {
|
} else {
|
||||||
content = string(contentBytes)
|
content = string(contentBytes)
|
||||||
|
|
||||||
|
_, err := uuid.Parse(content)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Invalid installation ID, %v", err)
|
||||||
|
content = "invalid-installation-id"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"content": content,
|
"content": content,
|
||||||
|
"from": filename,
|
||||||
}).Infof("Installation ID")
|
}).Infof("Installation ID")
|
||||||
|
|
||||||
return content
|
return content
|
||||||
|
|
@ -83,7 +74,7 @@ func isInContainer() bool {
|
||||||
|
|
||||||
// StartUpdateChecker will start a job that runs periodically, checking
|
// StartUpdateChecker will start a job that runs periodically, checking
|
||||||
// for updates.
|
// for updates.
|
||||||
func StartUpdateChecker(currentVersion string, currentCommit string, cfg *config.Config) {
|
func StartUpdateChecker(currentVersion string, currentCommit string, cfg *config.Config, configDir string) {
|
||||||
CurrentVersion = currentVersion
|
CurrentVersion = currentVersion
|
||||||
|
|
||||||
if !cfg.CheckForUpdates {
|
if !cfg.CheckForUpdates {
|
||||||
|
|
@ -96,7 +87,7 @@ func StartUpdateChecker(currentVersion string, currentCommit string, cfg *config
|
||||||
CurrentCommit: currentCommit,
|
CurrentCommit: currentCommit,
|
||||||
OS: runtime.GOOS,
|
OS: runtime.GOOS,
|
||||||
Arch: runtime.GOARCH,
|
Arch: runtime.GOARCH,
|
||||||
InstallationID: installationID(),
|
InstallationID: installationID(configDir + "/installation-id.txt"),
|
||||||
InContainer: isInContainer(),
|
InContainer: isInContainer(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue