Skip to content

Commit

Permalink
Add support for defining -config-dir as argument when installing as a…
Browse files Browse the repository at this point in the history
… service
  • Loading branch information
Stefano Da Ros committed Feb 7, 2019
1 parent 60a166b commit 69d1f35
Showing 1 changed file with 43 additions and 14 deletions.
57 changes: 43 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"fmt"
"net/http"
"os"

Expand Down Expand Up @@ -75,12 +76,53 @@ func (a *App) run() {

func main() {
a := &App{}
serviceControl, ok := viper.Get("service").(string)
if ok && serviceControl != "" {
switch serviceControl {
case "install":
configDir, ok := viper.Get("configDir").(string)
if !ok {
msg := "the -config-dir argument must be provided " +
"when installing the workflow connector as a service "
logger.Error(fmt.Errorf(msg))
os.Exit(1)
}
svc := newService(a, "-config-dir", configDir)
if err := service.Control(svc, serviceControl); err != nil {
logger.Error(err)
os.Exit(1)
}
err := svc.Run()
if err != nil {
logger.Errorf("unable to run the service: %s\n", err)
os.Exit(1)
}
default:
// Execute user specified control on service
svc := newService(a)
if err := service.Control(svc, serviceControl); err != nil {
logger.Error(err)
os.Exit(1)
}
err := svc.Run()
if err != nil {
logger.Errorf("unable to run the service: %s\n", err)
os.Exit(1)
}
}
return
}
}

func newService(a *App, args ...string) (svc service.Service) {
var arguments []string
svc, err := service.New(
a,
&service.Config{
Name: config.Options.Name,
DisplayName: config.Options.DisplayName,
Description: config.Options.Description,
Arguments: append(arguments, args...),
},
)
if err != nil {
Expand All @@ -92,18 +134,5 @@ func main() {
logger.Errorf("unable to initialize logger: %s\n", err)
os.Exit(1)
}
serviceControl, ok := viper.Get("service").(string)
if ok && serviceControl != "" {
// Execute user specified control on service
if err := service.Control(svc, serviceControl); err != nil {
logger.Error(err)
os.Exit(1)
}
return
}
err = svc.Run()
if err != nil {
logger.Errorf("unable to run the service: %s\n", err)
os.Exit(1)
}
return
}

0 comments on commit 69d1f35

Please sign in to comment.