-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from fffunke/master
Recursive config files || refactor structs || configurable port
- Loading branch information
Showing
28 changed files
with
428 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/.idea | ||
/mittnite | ||
/dist | ||
/dist | ||
examples/mittnite.d/local.hcl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package cmd | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var configDir string | ||
|
||
func init() { | ||
rootCmd.PersistentFlags().StringVarP(&configDir, "config-dir", "c", "/etc/mittnite.d", "") | ||
} | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "up", | ||
Short: "Mittnite - Smart init system for containers", | ||
Long: "Mittnite is a small, but smart init system designed for usage as `ENTRYPOINT` in container images.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
log.Warn("Using mittnite without 'up'. This will change in future releases!") | ||
up.Run(cmd, args) | ||
}, | ||
} | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/hcl" | ||
"github.com/mittwald/mittnite/internal/types" | ||
"github.com/mittwald/mittnite/pkg/files" | ||
"github.com/mittwald/mittnite/pkg/probe" | ||
"github.com/mittwald/mittnite/pkg/proc" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"io/ioutil" | ||
"os" | ||
"os/signal" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
var ( | ||
Version string | ||
Commit string | ||
BuiltAt string | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(up) | ||
} | ||
|
||
var up = &cobra.Command{ | ||
Use: "up", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
log.Infof("mittnite process manager, version %s (commit %s), built at %s", Version, Commit, BuiltAt) | ||
log.Infof("looking for configuration files in %s", configDir) | ||
|
||
configDir = strings.TrimRight(configDir, "/") | ||
|
||
var matches []string | ||
|
||
err := filepath.Walk(configDir, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
if strings.HasSuffix(info.Name(), "hcl") { | ||
matches = append(matches, path) | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if len(matches) == 0 { | ||
log.Fatalf("could not find any configuration files in %s", configDir) | ||
} | ||
|
||
ignitionConfig := types.IgnitionConfig{} | ||
|
||
for _, m := range matches { | ||
log.Infof("found config file: %s", m) | ||
|
||
contents, err := ioutil.ReadFile(m) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = hcl.Unmarshal(contents, &ignitionConfig) | ||
if err != nil { | ||
err = fmt.Errorf("could not parse configuration file %s: %s", m, err.Error()) | ||
panic(err) | ||
} | ||
} | ||
|
||
err = files.RenderConfigurationFiles(ignitionConfig.Files) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
signals := make(chan os.Signal) | ||
signal.Notify(signals) | ||
|
||
readinessSignals := make(chan os.Signal, 1) | ||
probeSignals := make(chan os.Signal, 1) | ||
procSignals := make(chan os.Signal, 1) | ||
|
||
go func() { | ||
for s := range signals { | ||
log.Infof("received event %s", s.String()) | ||
|
||
readinessSignals <- s | ||
probeSignals <- s | ||
procSignals <- s | ||
} | ||
}() | ||
|
||
probeHandler, _ := probe.NewProbeHandler(&ignitionConfig) | ||
|
||
go func() { | ||
err := probe.RunProbeServer(probeHandler, probeSignals) | ||
if err != nil { | ||
log.Fatalf("probe server stopped with error: %s", err) | ||
panic(err) | ||
} else { | ||
log.Info("probe server stopped without error") | ||
} | ||
}() | ||
|
||
err = probeHandler.Wait(readinessSignals) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = proc.RunServices(&ignitionConfig, procSignals) | ||
if err != nil { | ||
log.Fatalf("service runner stopped with error: %s", err) | ||
} else { | ||
log.Print("service runner stopped without error") | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
job sleep { | ||
command = "/bin/sleep" | ||
args = ["500s"] | ||
canFail = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
probe redis { | ||
wait = true | ||
redis { | ||
host = { | ||
url = "localhost" | ||
port = 6379 | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.