feat: main
This commit is contained in:
72
main.go
72
main.go
@@ -33,17 +33,14 @@ func main() {
|
||||
watcherIface.Listen(config.ScriptBinaryPath, config.WebhookScriptPath, errors)
|
||||
|
||||
// Handle termination on ctrl+signalChan
|
||||
signalChan := make(chan os.Signal)
|
||||
signalChan := make(chan os.Signal, 1)
|
||||
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
go func() {
|
||||
<-signalChan
|
||||
os.Exit(1)
|
||||
}()
|
||||
|
||||
go func(errors chan error) {
|
||||
for {
|
||||
select {
|
||||
case <-signalChan:
|
||||
os.Exit(1)
|
||||
case err := <-errors:
|
||||
if err != nil {
|
||||
log.Fatalf("watcherIface.Monitor: %s\n", err)
|
||||
@@ -53,67 +50,6 @@ func main() {
|
||||
}
|
||||
}(errors)
|
||||
|
||||
// Block main goroutine forever.
|
||||
// TODO: Improve this: Block main goroutine forever.
|
||||
<-make(chan struct{})
|
||||
|
||||
// watcher, err := fsnotify.NewWatcher()
|
||||
// if err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
// defer watcher.Close()
|
||||
|
||||
// // Start listening for events.
|
||||
// go func() {
|
||||
// for {
|
||||
// select {
|
||||
// case event, ok := <-watcher.Events:
|
||||
// if !ok {
|
||||
// log.Printf("<-watcher.Events: %s\n", err)
|
||||
// return
|
||||
// }
|
||||
// if !event.Has(fsnotify.Write) {
|
||||
// log.Printf("is not Write: %s\n", event.Name)
|
||||
// continue
|
||||
// }
|
||||
|
||||
// if err := deploy(config.ScriptBinaryPath, config.WebhookScriptPath); err != nil {
|
||||
// log.Printf("deploy: %s\n", err)
|
||||
// continue
|
||||
// }
|
||||
// case err, ok := <-watcher.Errors:
|
||||
// if !ok {
|
||||
// return
|
||||
// }
|
||||
// log.Printf("<-watcher.Errors: %s\n", err)
|
||||
// }
|
||||
// }
|
||||
// }()
|
||||
|
||||
// if err = watcher.Add(config.FileToWatchPath); err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
|
||||
// // Block main goroutine forever.
|
||||
// <-make(chan struct{})
|
||||
}
|
||||
|
||||
// func deploy(binaryPath, scriptPath string) error {
|
||||
// err := execute(binaryPath, scriptPath)
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("execute: %s", err)
|
||||
// }
|
||||
// log.Println("deploy done")
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// func execute(binaryPath, scriptPath string) error {
|
||||
// cmd := exec.Command(binaryPath, scriptPath)
|
||||
// cmd.Stdout = os.Stdout
|
||||
// cmd.Stderr = os.Stderr
|
||||
|
||||
// if err := cmd.Run(); err != nil {
|
||||
// return fmt.Errorf("cmd.Run %s", err)
|
||||
// }
|
||||
|
||||
// return nil
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user