|
|
|
@ -10,7 +10,6 @@ import ( |
|
|
|
|
"os" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Read a configuration from fname or die
|
|
|
|
|
|
|
|
|
|
func ReadGlobalConfig(fname string) *SCORSHmaster { |
|
|
|
@ -20,11 +19,10 @@ func ReadGlobalConfig(fname string) *SCORSHmaster { |
|
|
|
|
log.Fatal("Error while reading file: ", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var cfg *SCORSHmaster |
|
|
|
|
|
|
|
|
|
cfg = new(SCORSHmaster) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Unmarshal the YAML configuration file into a SCORSHcfg structure
|
|
|
|
|
err = yaml.Unmarshal(data, cfg) |
|
|
|
|
if err != nil { |
|
|
|
@ -33,21 +31,12 @@ func ReadGlobalConfig(fname string) *SCORSHmaster { |
|
|
|
|
|
|
|
|
|
fmt.Printf("%s", cfg) |
|
|
|
|
|
|
|
|
|
// If the user has not set a spooldir, crash loudly
|
|
|
|
|
if cfg.Spooldir == "" { |
|
|
|
|
log.Fatal("No spooldir defined in ", fname, ". Exiting\n") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Check if the user has set a custom logprefix
|
|
|
|
|
|
|
|
|
|
// Check if the user wants to redirect the logs to a file
|
|
|
|
|
if cfg.Logfile != "" { |
|
|
|
|
log.Printf("Opening log file: %s\n", cfg.Logfile) |
|
|
|
|
f, err := os.OpenFile(cfg.Logfile, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0600) |
|
|
|
|
if err != nil { |
|
|
|
|
log.SetOutput(io.Writer(f)) |
|
|
|
|
} else { |
|
|
|
|
log.Fatal("Error opening logfile: ", cfg.Logfile, err) |
|
|
|
|
} else { |
|
|
|
|
log.SetOutput(io.Writer(f)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -55,6 +44,15 @@ func ReadGlobalConfig(fname string) *SCORSHmaster { |
|
|
|
|
log.SetPrefix(cfg.LogPrefix) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// If the user has not set a spooldir, crash loudly
|
|
|
|
|
if cfg.Spooldir == "" { |
|
|
|
|
log.Fatal("No spooldir defined in ", fname, ". Exiting\n") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Check if the user has set a custom logprefix
|
|
|
|
|
|
|
|
|
|
// Check if the user wants to redirect the logs to a file
|
|
|
|
|
|
|
|
|
|
// If we got so far, then there is some sort of config in cfg
|
|
|
|
|
log.Printf("Successfully read config from %s\n", fname) |
|
|
|
|
|
|
|
|
@ -62,9 +60,6 @@ func ReadGlobalConfig(fname string) *SCORSHmaster { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (cfg *SCORSHmaster) String() string { |
|
|
|
|
|
|
|
|
|
var buff bytes.Buffer |
|
|
|
|