Skip to content

Commit

Permalink
Merge pull request #7 from ChrisMcKenzie/version1.0.1
Browse files Browse the repository at this point in the history
Version 1.0.1
  • Loading branch information
ChrisMcKenzie committed Oct 29, 2015
2 parents a9fe2bd + 9e8a4b4 commit 89052b1
Show file tree
Hide file tree
Showing 26 changed files with 777 additions and 521 deletions.
64 changes: 64 additions & 0 deletions commands/agent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package commands

import (
"io/ioutil"
"log"
"os"
"os/signal"
"path/filepath"

"github.com/ChrisMcKenzie/dropship/service"
"github.com/hashicorp/hcl"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

const maxGoRoutines = 10

var agentCmd = &cobra.Command{
Use: "agent",
Short: "starts automatic checks and update",
Run: agent,
}

func agent(c *cobra.Command, args []string) {
InitializeConfig()

root := viper.GetString("servicePath")
services, err := loadServices(root)
if err != nil {
log.Fatalln(err)
}

t := service.NewRunner(len(services))
shutdownCh := make(chan struct{})

for _, s := range services {
service.NewDispatcher(s, t, shutdownCh)
}

sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt)
<-sigs
close(shutdownCh)

t.Shutdown()
}

func loadServices(root string) (d []service.Config, err error) {
files, _ := filepath.Glob(root + "/*.hcl")
for _, file := range files {
var data []byte
data, err = ioutil.ReadFile(file)
if err != nil {
return
}

var deploy struct {
Services []service.Config `hcl:"service,expand"`
}
hcl.Decode(&deploy, string(data))
d = append(d, deploy.Services...)
}
return
}
70 changes: 0 additions & 70 deletions commands/agent/action.go

This file was deleted.

29 changes: 0 additions & 29 deletions commands/agent/config.go

This file was deleted.

19 changes: 0 additions & 19 deletions commands/agent/semaphore.go

This file was deleted.

24 changes: 0 additions & 24 deletions commands/agent/services.go

This file was deleted.

11 changes: 0 additions & 11 deletions commands/agent/services_test.go

This file was deleted.

34 changes: 0 additions & 34 deletions commands/agent/setup.go

This file was deleted.

64 changes: 0 additions & 64 deletions commands/agent/setup_test.go

This file was deleted.

Loading

0 comments on commit 89052b1

Please sign in to comment.