Commit adf57071 authored by Thor Bjorgvinsson's avatar Thor Bjorgvinsson Committed by Ivan Aguilar
Browse files

Support relative config file on windows like on linux

cr: https://code.amazon.com/reviews/CR-52290210
parent e5e55bb0
......@@ -197,7 +197,8 @@ const (
// PluginNameAwsApplications is the name of the Applications plugin
PluginNameAwsApplications = "aws:applications"
AppConfigFileName = "amazon-ssm-agent.json"
AppConfigFileName = "amazon-ssm-agent.json"
SeelogConfigFileName = "seelog.xml"
// Output truncation limits
......
......@@ -104,9 +104,6 @@ const (
// customCertificateFileName is the name of the custom certificate
customCertificateFileName = "amazon-ssm-agent.crt"
// seelogFileName is the name of the log configuration file
seelogFileName = "seelog.xml"
// SSM Agent Update download legacy path
LegacyUpdateDownloadFolder = "/var/log/amazon/ssm/download"
)
......@@ -130,7 +127,7 @@ var AppConfigPath = DefaultProgramFolder + AppConfigFileName
var CustomCertificatePath = ""
// SeelogFilePath specifies the path to the seelog
var SeelogFilePath = DefaultProgramFolder + seelogFileName
var SeelogFilePath = DefaultProgramFolder + SeelogConfigFileName
func init() {
/*
......@@ -171,8 +168,8 @@ func init() {
}
// Check if seelog.xml is available in relative path
if validateRelativeConfigFile(filepath.Join(curdir, relativeConfigFolder, seelogFileName)) {
SeelogFilePath = filepath.Join(curdir, relativeConfigFolder, seelogFileName)
if validateRelativeConfigFile(filepath.Join(curdir, relativeConfigFolder, SeelogConfigFileName)) {
SeelogFilePath = filepath.Join(curdir, relativeConfigFolder, SeelogConfigFileName)
}
// Check if certificate is available in relative path
......
......@@ -83,6 +83,9 @@ var DefaultSessionLogger string
// AppConfig Path
var AppConfigPath string
// Seelog file path
var SeelogFilePath string
// DefaultDataStorePath represents the directory for storing system data
var DefaultDataStorePath string
......@@ -152,9 +155,6 @@ var EnvWinDir string
// Default Custom Inventory Data Folder
var DefaultCustomInventoryFolder string
// Plugin folder path
var PluginFolder string
// SSM Agent Update download legacy path
var LegacyUpdateDownloadFolder string
......@@ -183,6 +183,7 @@ func init() {
DefaultSessionLogger = fmt.Sprintf("&'%s'", filepath.Join(DefaultProgramFolder, "ssm-session-logger.exe"))
ManifestCacheDirectory = filepath.Join(EnvProgramFiles, ManifestCacheFolder)
AppConfigPath = filepath.Join(DefaultProgramFolder, AppConfigFileName)
SeelogFilePath = filepath.Join(DefaultProgramFolder, SeelogConfigFileName)
DefaultDataStorePath = filepath.Join(SSMDataPath, "InstanceData")
PackageRoot = filepath.Join(SSMDataPath, "Packages")
PackageLockRoot = filepath.Join(SSMDataPath, "Locks\\Packages")
......@@ -204,4 +205,26 @@ func init() {
EC2ConfigSettingPath = filepath.Join(EnvProgramFiles, EC2ConfigServiceFolder, "Settings")
SessionFilesPath = filepath.Join(SSMDataPath, "Session")
// Support reading configuration from relative path like in linux
// curdir is amazon-ssm-agent current directory path
curdir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
return
}
const relativeConfigFolder = "configuration"
// check if relative appconfig file in configuration folder exists, if so use it
if shouldUseConfig(filepath.Join(curdir, relativeConfigFolder, AppConfigFileName)) {
AppConfigPath = filepath.Join(curdir, relativeConfigFolder, AppConfigFileName)
}
// check if relative seelog file in configuration folder exists, if so use it
if shouldUseConfig(filepath.Join(curdir, relativeConfigFolder, SeelogConfigFileName)) {
SeelogFilePath = filepath.Join(curdir, relativeConfigFolder, SeelogConfigFileName)
}
}
func shouldUseConfig(filePath string) bool {
_, err := os.Stat(filePath)
// Return false for any stat error
return err == nil
}
......@@ -31,7 +31,7 @@ var ExeNamePlaceHolder = "{{EXECUTABLENAME}}"
// The underlying logger is based of https://github.com/cihub/seelog
// See Seelog documentation to customize the logger
var DefaultSeelogConfigFilePath = filepath.Join(appconfig.DefaultProgramFolder, appconfig.SeelogConfigFileName)
var DefaultSeelogConfigFilePath = appconfig.SeelogFilePath
var getExePath = getExecutablePath
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment