Skip to content

Commit

Permalink
fix install service method
Browse files Browse the repository at this point in the history
- Fixed the service install plist
  • Loading branch information
cjlapao committed Sep 16, 2024
1 parent f7e8598 commit 6b0d1e1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
4 changes: 4 additions & 0 deletions install_cfg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"port": "5470",
"log_output": true
}
15 changes: 12 additions & 3 deletions src/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func New(ctx basecontext.ApiContext) *Config {
mode: "api",
ctx: ctx,
fileFormat: "yaml",
filename: "config.yml",
filename: "prldevops_config",
config: ConfigFile{},
}

Expand Down Expand Up @@ -77,13 +77,22 @@ func (c *Config) Load() bool {
fileName = configFileName
}
} else {
configFolder := filepath.Join(filepath.Dir(execPath), "prldevops_config")
for _, extension := range extensions {
configFolder := filepath.Join(filepath.Dir(execPath), "config")
if _, err := os.Stat(fmt.Sprintf("%s%s", configFolder, extension)); !os.IsNotExist(err) {
fileName = fmt.Sprintf("%s%s", configFolder, extension)
break
}
}
if fileName == "" {
configFolder = filepath.Join(filepath.Dir(execPath), "config")
for _, extension := range extensions {
if _, err := os.Stat(fmt.Sprintf("%s%s", configFolder, extension)); !os.IsNotExist(err) {
fileName = fmt.Sprintf("%s%s", configFolder, extension)
break
}
}
}
}

if fileName == "" {
Expand Down Expand Up @@ -143,7 +152,7 @@ func (c *Config) Save() bool {
}
}

err = helper.WriteToFile(string(content), c.filename)
err = helper.WriteToFile(string(content), fmt.Sprintf("%s.%s", c.filename, c.fileFormat))
if err != nil {
c.ctx.LogErrorf("Error saving configuration file: %s", err.Error())
return false
Expand Down
12 changes: 7 additions & 5 deletions src/install/mac_plist_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type PlistTemplateData struct {
TokenDurationMinutes string
Mode string
UseOrchestratorResources string
LogOutput bool
}

var plistTemplate = `<?xml version="1.0" encoding="UTF-8"?>
Expand Down Expand Up @@ -104,14 +105,14 @@ var plistTemplate = `<?xml version="1.0" encoding="UTF-8"?>
<key>SuccessfulExit</key>
<false/>
</dict>
{{- if .LogOutput }}
<key>StandardErrorPath</key>
<string>/tmp/api-service.job.err</string>
<string>/tmp/devops-service.job.err</string>
<key>StandardOutPath</key>
<key>RunAtLoad</key>
<true/>
<string>/tmp/api-service.job.out</string>
<string>/tmp/devops-service.job.out</string>
{{- end }}
</dict>
</plist>"`
</plist>`

func generatePlist(path string, config ApiServiceConfig) (string, error) {
// Define the text template
Expand All @@ -136,6 +137,7 @@ func generatePlist(path string, config ApiServiceConfig) (string, error) {
TlsPrivateKey: config.TLSPrivateKey,
TokenDurationMinutes: config.TokenDurationMinutes,
Mode: config.Mode,
LogOutput: config.LogOutput,
}
if config.EnableTLS {
templateData.EnableTLS = "true"
Expand Down
1 change: 1 addition & 0 deletions src/install/service_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ type ApiServiceConfig struct {
TokenDurationMinutes string `json:"token_duration_minutes,omitempty"`
Mode string `json:"mode,omitempty"`
UseOrchestratorResources bool `json:"use_orchestrator_resources,omitempty"`
LogOutput bool `json:"log_output,omitempty"`
}

0 comments on commit 6b0d1e1

Please sign in to comment.