Skip to content

Commit

Permalink
limiting scuttle shutdown to SIGINT signals
Browse files Browse the repository at this point in the history
  • Loading branch information
Lin Meyer authored and jvasallo committed Mar 29, 2021
1 parent 0fc99fb commit 69df4da
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 8 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os/signal"
"strings"
"time"
"syscall"

"github.com/cenk/backoff"
"github.com/monzo/typhon"
Expand Down Expand Up @@ -67,12 +68,13 @@ func main() {
}

var proc *os.Process

stop := make(chan os.Signal, 2)
signal.Notify(stop, syscall.SIGINT) // Only listen to SIGINT until after child proc starts

// Pass signals to the child process
// This takes an OS signal and passes to the child process scuttle starts (proc)
go func() {
stop := make(chan os.Signal, 2)
signal.Notify(stop)

for sig := range stop {
if proc == nil {
// Signal received before the process even started. Let's just exit.
Expand All @@ -94,6 +96,9 @@ func main() {
panic(err)
}

// Once child process starts, listen for any symbol and pass to the child proc
signal.Notify(stop)

state, err := proc.Wait()
if err != nil {
panic(err)
Expand Down
7 changes: 7 additions & 0 deletions scripts/self_destruct.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
# Helper script that self destructs scuttle by finding it's process id and killing it
# Helpful when testing signal handling
# use:
# ./scuttle /bin/bash scripts/self_destruct.sh
kill -INT $(pidof scuttle)
while 1>0; do echo -n "." && sleep 1; done;

0 comments on commit 69df4da

Please sign in to comment.