Skip to content

Commit

Permalink
switch go goreleaser, small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
reddec committed May 23, 2018
1 parent b102ee1 commit ebb53d1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea/**
build
.goxc.local.json
vendor/
vendor/
dist
22 changes: 22 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
builds:
- binary: monexec
main: cmd/monexec/main.go
goos:
- windows
- darwin
- linux
goarch:
- amd64
- 386
- arm64
archive:
format: tar.gz
nfpm:
homepage: https://github.com/reddec/monexec
description: Tool for controlling processes like a supervisord but with some features
maintainer: RedDec <owner@reddec.net>
license: MIT
formats:
- deb
14 changes: 0 additions & 14 deletions .goxc.json

This file was deleted.

15 changes: 9 additions & 6 deletions main.go → cmd/monexec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
"syscall"
)

var (
version = "dev"
)
var (
runCommand = kingpin.Command("run", "Run single executable")
runGenerate = runCommand.Flag("generate", "Generate instead of run YAML configuration based on args").Bool()
Expand All @@ -37,7 +40,7 @@ var (
)

func run() {
config := DefaultConfig()
config := monexec.DefaultConfig()

config.Services = append(config.Services, monexec.Executable{
Name: *runLabel,
Expand All @@ -49,10 +52,10 @@ func run() {
WorkDir: *runWorkDir,
Environment: *runEnv,
})
FillDefaultExecutable(&config.Services[0])
monexec.FillDefaultExecutable(&config.Services[0])

if *runConsulEnable {
config.Consul = DefaultConsulConfig()
config.Consul = monexec.DefaultConsulConfig()
config.Consul.URL = *runConsulAddress
config.Consul.TTL = *runConsulTTL
config.Consul.AutoDeregistrationTimeout = *runConsulDeRegTTL
Expand All @@ -76,15 +79,15 @@ func run() {
}

func start() {
config, err := LoadConfig(*startSources...)
config, err := monexec.LoadConfig(*startSources...)
if err != nil {
log.Fatal(err)
}
sv := container.NewSupervisor(log.New(os.Stderr, "[supervisor] ", log.LstdFlags))
runConfigInSupervisor(config, sv)
}

func runConfigInSupervisor(config *Config, sv container.Supervisor) {
func runConfigInSupervisor(config * monexec.Config, sv container.Supervisor) {
ctx, stop := context.WithCancel(context.Background())

c := make(chan os.Signal, 2)
Expand All @@ -104,7 +107,7 @@ func runConfigInSupervisor(config *Config, sv container.Supervisor) {
}

func main() {
kingpin.Version("0.1.0").DefaultEnvars()
kingpin.Version(version).DefaultEnvars()
switch kingpin.Parse() {
case "run":
run()
Expand Down
9 changes: 4 additions & 5 deletions config.go → monexec/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package monexec

import (
"context"
Expand All @@ -15,7 +15,6 @@ import (
"github.com/hashicorp/consul/api"
"github.com/reddec/container"
"github.com/reddec/container/plugin"
"github.com/reddec/monexec/monexec"
"gopkg.in/yaml.v2"
"github.com/reddec/monexec/plugins"
"github.com/mitchellh/mapstructure"
Expand All @@ -40,7 +39,7 @@ func DefaultConsulConfig() *ConsulConfig {
}

type Config struct {
Services []monexec.Executable `yaml:"services"`
Services []Executable `yaml:"services"`
Critical []string `yaml:"critical,omitempty"`
Consul *ConsulConfig `yaml:"consul,omitempty"`
Plugins map[string]interface{} `yaml:",inline"` // all unparsed means plugins
Expand Down Expand Up @@ -99,7 +98,7 @@ func DefaultConfig() Config {
return config
}

func FillDefaultExecutable(exec *monexec.Executable) {
func FillDefaultExecutable(exec *Executable) {
if exec.RestartTimeout == 0 {
exec.RestartTimeout = 6 * time.Second
}
Expand Down Expand Up @@ -157,7 +156,7 @@ func (config *Config) Run(sv container.Supervisor, ctx context.Context) error {
for _, exec := range config.Services {
FillDefaultExecutable(&exec)
wg.Add(1)
go func(exec monexec.Executable) {
go func(exec Executable) {
defer wg.Done()
container.Wait(sv.Watch(ctx, exec.Factory, exec.Restart, exec.RestartTimeout, false))
}(exec)
Expand Down

0 comments on commit ebb53d1

Please sign in to comment.