Skip to content

Commit 9379ccc

Browse files
committed
handle some signals
1 parent 0271afe commit 9379ccc

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

hashicorp.hcl

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ program "consul" {
44
}
55

66
program "nomad" {
7-
command = "nomad agent -dev"
8-
check = "nomad node status"
9-
# seconds = 1 # to test check failures
7+
command = "nomad agent -dev"
8+
check = "nomad node status"
9+
# seconds = 3 # to test check failures
1010
}
1111

1212
program "vault" {

main.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package main
22

33
import (
44
"context"
5+
"fmt"
56
"log"
67
"os"
8+
"os/signal"
9+
"syscall"
710

811
"github.com/gulducat/go-run-programs/program"
912
)
@@ -14,17 +17,22 @@ func main() {
1417

1518
func CLI(args []string) int {
1619
if len(args) < 2 {
17-
log.Println("gotta provide an hcl file ok?")
20+
fmt.Println("gotta provide an hcl file ok?")
1821
return 1
1922
}
2023

24+
sig := make(chan os.Signal, 1)
25+
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
26+
2127
stop, err := program.RunFromHCL(context.Background(), args[1])
2228
defer stop()
29+
2330
if err != nil {
24-
log.Println("error:", err)
31+
fmt.Println("error:", err)
2532
return 1
2633
}
2734

28-
// let the good times roll
29-
select {}
35+
s := <-sig
36+
log.Println("signal:", s)
37+
return 0
3038
}

0 commit comments

Comments
 (0)