add flags: dir, disableMetrics and env var DISABLE_METRICS to the app
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Dan Ballard 2021-11-26 16:54:26 -08:00
parent 872bf30b1b
commit b4bb859cdb
2 changed files with 21 additions and 3 deletions

View File

@ -19,10 +19,12 @@ The server package relies on sqlite which in turn requires the use of CGO. As pe
The app takes the following arguments The app takes the following arguments
- -debug: enabled debug logging - -debug: enabled debug logging
- -exportServerBundle: Export the server bundle to a file called serverbundle - -exportServerBundle: Export the server bundle to a file called serverbundle
- -disableMetrics: Disable metrics reporting to serverMonitor.txt and associated tracking routines
- -dir [directory]: specify a directory to store server files (default is current directory)
The app takes the following environment variables The app takes the following environment variables
- CWTCH_HOME: sets the config dir for the app - CWTCH_HOME: sets the config dir for the app
- DISABLE_METRICS: if set to any value ('1') it disables metrics reporting to serverMonitor.txt and associated tracking routines
`env CONFIG_HOME=./conf ./app` `env CONFIG_HOME=./conf ./app`
@ -38,4 +40,10 @@ or run our prebuild ones with
`pull openpriv/cwtch-server` `pull openpriv/cwtch-server`
and run it. It stores all Cwtch data in a Volume at `/var/lib/cwtch` and run it. It stores all Cwtch data in a Volume at `/var/lib/cwtch` so if you want the server data to persist you would run
`docker run openpriv/cwtch-server -v /var/lib/cwtch/server01:/var/lib/cwtch`
to create a persistent container you might try a command like:
`docker run openpriv/cwtch-server --name cwtch -v /var/lib/cwtch/server01:/var/lib/cwtch --restart always`

View File

@ -21,6 +21,8 @@ import (
func main() { func main() {
flagDebug := flag.Bool("debug", false, "Enable debug logging") flagDebug := flag.Bool("debug", false, "Enable debug logging")
flagExportServer := flag.Bool("exportServerBundle", false, "Export the server bundle to a file called serverbundle") flagExportServer := flag.Bool("exportServerBundle", false, "Export the server bundle to a file called serverbundle")
flagDir := flag.String("dir", ".", "Directory to store server files in (config, encrypted messages, metrics)")
flagDisableMetrics := flag.Bool("disableMetrics", false, "Disable metrics reporting")
flag.Parse() flag.Parse()
log.AddEverythingFromPattern("server/app/main") log.AddEverythingFromPattern("server/app/main")
@ -32,6 +34,9 @@ func main() {
log.SetLevel(log.LevelDebug) log.SetLevel(log.LevelDebug)
} }
configDir := os.Getenv("CWTCH_HOME") configDir := os.Getenv("CWTCH_HOME")
if configDir == "" {
configDir = *flagDir
}
if len(os.Args) == 2 && os.Args[1] == "gen1" { if len(os.Args) == 2 && os.Args[1] == "gen1" {
config := new(cwtchserver.Config) config := new(cwtchserver.Config)
@ -52,11 +57,16 @@ func main() {
return return
} }
serverConfig, err := cwtchserver.LoadCreateDefaultConfigFile(configDir, cwtchserver.ServerConfigFile, false, "", true) disableMetrics := *flagDisableMetrics
if os.Getenv("DISABLE_METRICS") != "" {
disableMetrics = true
}
serverConfig, err := cwtchserver.LoadCreateDefaultConfigFile(configDir, cwtchserver.ServerConfigFile, false, "", !disableMetrics)
if err != nil { if err != nil {
log.Errorf("Could not load/create config file: %s\n", err) log.Errorf("Could not load/create config file: %s\n", err)
return return
} }
serverConfig.ServerReporting.LogMetricsToFile = !disableMetrics
// we don't need real randomness for the port, just to avoid a possible conflict... // we don't need real randomness for the port, just to avoid a possible conflict...
mrand.Seed(int64(time.Now().Nanosecond())) mrand.Seed(int64(time.Now().Nanosecond()))
controlPort := mrand.Intn(1000) + 9052 controlPort := mrand.Intn(1000) + 9052