diff --git a/CHANGELOG.md b/CHANGELOG.md index 10a30b7..d319b83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file. - Added SysV init script - Added Systemd service file - Added installation script +- Added command line option for config file --- diff --git a/doc/jilo-agent.service b/doc/jilo-agent.service index 17d7448..f29485d 100644 --- a/doc/jilo-agent.service +++ b/doc/jilo-agent.service @@ -5,7 +5,7 @@ After=network.target [Service] ExecStart=/usr/local/bin/jilo-agent -c /usr/local/etc/jilo-agent.conf PIDFile=/run/jilo-agent.pid -Restart=always +Restart=on-failure SyslogIdentifier=jilo-agent User=root Group=root diff --git a/main.go b/main.go index a5e864f..6f623d5 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ Version: 0.1 package main import ( + "flag" "fmt" "encoding/json" "gopkg.in/yaml.v2" @@ -290,8 +291,20 @@ func corsMiddleware(next http.Handler) http.Handler { // main sets up the http server and the routes func main() { - // load the configuration - config := loadConfig("jilo-agent.conf") + // Define a flag for the config file + configFile := flag.String("c", "./jilo-agent.conf", "Specify the agent config file") + + // Parse the flags + flag.Parse() + + // Check if the file exists, fallback to default config file if not + if _, err := os.Stat(*configFile); os.IsNotExist(err) { + fmt.Println("Config file not found, using default values") + } + + // Load the configuration from the specified file (option -c) or the default config file name + config := loadConfig(*configFile) + secretKey = []byte(config.SecretKey) mux := http.NewServeMux()