Skip to content

Commit

Permalink
Merge pull request #8 from alcounit/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
alcounit authored Apr 19, 2021
2 parents c560d6e + 1f7a225 commit e7728e6
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions cmd/seleniferous/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,18 @@ func command() *cobra.Command {
Handler: router,
}

stop := make(chan os.Signal)
stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)

e := make(chan error)

cancelFunc := func() {
context := context.Background()
client.CoreV1().Pods(namespace).Delete(context, hostname, metav1.DeleteOptions{
GracePeriodSeconds: pointer.Int64Ptr(15),
})
}

go func() {
e <- srv.ListenAndServe()
}()
Expand All @@ -109,11 +116,9 @@ func command() *cobra.Command {
for {
select {
case <-timeout:
context := context.Background()
client.CoreV1().Pods(namespace).Delete(context, hostname, metav1.DeleteOptions{
GracePeriodSeconds: pointer.Int64Ptr(15),
})
shuttingDown = true
logger.Warn("session wait timeout exceeded")
cancelFunc()
break loop
case <-ticker:
if storage.IsEmpty() {
Expand All @@ -128,7 +133,10 @@ func command() *cobra.Command {
case err := <-e:
logger.Fatalf("failed to start: %v", err)
case <-stop:
shuttingDown = true
if !shuttingDown {
logger.Warn("unexpected stop signal received")
defer cancelFunc()
}
logger.Warn("stopping seleniferous")
}

Expand Down

0 comments on commit e7728e6

Please sign in to comment.