mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-08-23 01:27:13 +02:00
cmd/ctrld: add "start --no-cd" flag to disable cd mode
This commit is contained in:
+16
-2
@@ -37,7 +37,13 @@ import (
|
|||||||
"github.com/Control-D-Inc/ctrld/internal/router"
|
"github.com/Control-D-Inc/ctrld/internal/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
const selfCheckFQDN = "verify.controld.com"
|
const (
|
||||||
|
selfCheckFQDN = "verify.controld.com"
|
||||||
|
cdModeConfigHeader = `# AUTO-GENERATED VIA CD FLAG - DO NOT MODIFY
|
||||||
|
# TO DISABLE AUTO-GENERATION RUN: ctrld service start --no-cd
|
||||||
|
|
||||||
|
`
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
version = "dev"
|
version = "dev"
|
||||||
@@ -240,6 +246,7 @@ func initCLI() {
|
|||||||
runCmd.Flags().StringVarP(&logPath, "log", "", "", "Path to log file")
|
runCmd.Flags().StringVarP(&logPath, "log", "", "", "Path to log file")
|
||||||
runCmd.Flags().IntVarP(&cacheSize, "cache_size", "", 0, "Enable cache with size items")
|
runCmd.Flags().IntVarP(&cacheSize, "cache_size", "", 0, "Enable cache with size items")
|
||||||
runCmd.Flags().StringVarP(&cdUID, "cd", "", "", "Control D resolver uid")
|
runCmd.Flags().StringVarP(&cdUID, "cd", "", "", "Control D resolver uid")
|
||||||
|
runCmd.Flags().BoolVarP(&noCD, "no-cd", "", false, `Disable cd mode, the same effect with --cd=""`)
|
||||||
runCmd.Flags().StringVarP(&homedir, "homedir", "", "", "")
|
runCmd.Flags().StringVarP(&homedir, "homedir", "", "", "")
|
||||||
_ = runCmd.Flags().MarkHidden("homedir")
|
_ = runCmd.Flags().MarkHidden("homedir")
|
||||||
runCmd.Flags().StringVarP(&iface, "iface", "", "", `Update DNS setting for iface, "auto" means the default interface gateway`)
|
runCmd.Flags().StringVarP(&iface, "iface", "", "", `Update DNS setting for iface, "auto" means the default interface gateway`)
|
||||||
@@ -292,6 +299,12 @@ func initCLI() {
|
|||||||
initLogging()
|
initLogging()
|
||||||
cfg.Service.LogPath = logPath
|
cfg.Service.LogPath = logPath
|
||||||
|
|
||||||
|
if noCD {
|
||||||
|
cdUID = ""
|
||||||
|
if err := writeConfigFile(); err != nil {
|
||||||
|
log.Fatalf("failed to overwrite config file with --no-cd: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
processCDFlags()
|
processCDFlags()
|
||||||
|
|
||||||
// Explicitly passing config, so on system where home directory could not be obtained,
|
// Explicitly passing config, so on system where home directory could not be obtained,
|
||||||
@@ -349,6 +362,7 @@ func initCLI() {
|
|||||||
startCmd.Flags().StringVarP(&logPath, "log", "", "", "Path to log file")
|
startCmd.Flags().StringVarP(&logPath, "log", "", "", "Path to log file")
|
||||||
startCmd.Flags().IntVarP(&cacheSize, "cache_size", "", 0, "Enable cache with size items")
|
startCmd.Flags().IntVarP(&cacheSize, "cache_size", "", 0, "Enable cache with size items")
|
||||||
startCmd.Flags().StringVarP(&cdUID, "cd", "", "", "Control D resolver uid")
|
startCmd.Flags().StringVarP(&cdUID, "cd", "", "", "Control D resolver uid")
|
||||||
|
startCmd.Flags().BoolVarP(&noCD, "no-cd", "", false, `Disable cd mode, the same effect with --cd=""`)
|
||||||
startCmd.Flags().StringVarP(&iface, "iface", "", "", `Update DNS setting for iface, "auto" means the default interface gateway`)
|
startCmd.Flags().StringVarP(&iface, "iface", "", "", `Update DNS setting for iface, "auto" means the default interface gateway`)
|
||||||
startCmd.Flags().BoolVarP(&setupRouter, "router", "", false, `setup for running on router platforms`)
|
startCmd.Flags().BoolVarP(&setupRouter, "router", "", false, `setup for running on router platforms`)
|
||||||
_ = startCmd.Flags().MarkHidden("router")
|
_ = startCmd.Flags().MarkHidden("router")
|
||||||
@@ -565,7 +579,7 @@ func writeConfigFile() error {
|
|||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
if cdUID != "" {
|
if cdUID != "" {
|
||||||
if _, err := f.WriteString("# AUTO-GENERATED VIA CD FLAG - DO NOT MODIFY\n\n"); err != nil {
|
if _, err := f.WriteString(cdModeConfigHeader); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ var (
|
|||||||
cfg ctrld.Config
|
cfg ctrld.Config
|
||||||
verbose int
|
verbose int
|
||||||
cdUID string
|
cdUID string
|
||||||
|
noCD bool
|
||||||
iface string
|
iface string
|
||||||
ifaceStartStop string
|
ifaceStartStop string
|
||||||
setupRouter bool
|
setupRouter bool
|
||||||
|
|||||||
Reference in New Issue
Block a user