Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix logger in supervisor.go #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions pkg/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"log"
"github.com/karlkfi/kubexit/pkg/log"
"os"
"os/exec"
"os/signal"
Expand Down Expand Up @@ -45,7 +45,7 @@ func (s *Supervisor) Start() error {
return errors.New("not starting child process: shutdown already started")
}

log.Printf("Starting: %s\n", s)
log.Info("Starting: ", "start", s)
if err := s.cmd.Start(); err != nil {
return fmt.Errorf("failed to start child process: %v", err)
}
Expand All @@ -62,15 +62,15 @@ func (s *Supervisor) Start() error {
}
// log everything but "urgent I/O condition", which gets noisy
if sig != syscall.SIGURG {
log.Printf("Received signal: %v\n", sig)
log.Info("Received signal: ", "signal", sig)
}
// ignore "child exited" signal
if sig == syscall.SIGCHLD {
continue
}
err := s.cmd.Process.Signal(sig)
if err != nil {
log.Printf("Signal propegation failed: %v\n", err)
log.Error(err, "Signal propegation failed")
}
}
}()
Expand All @@ -88,7 +88,7 @@ func (s *Supervisor) Wait() error {
s.shutdownTimer.Stop()
}
}()
log.Println("Waiting for child process to exit...")
log.Info("Waiting for child process to exit...")
return s.cmd.Wait()
}

Expand All @@ -99,11 +99,11 @@ func (s *Supervisor) ShutdownNow() error {
s.shutdown = true

if !s.isRunning() {
log.Println("Skipping ShutdownNow: child process not running")
log.Info("Skipping ShutdownNow: child process not running")
return nil
}

log.Println("Killing child process...")
log.Info("Killing child process...")
// TODO: Use Process.Kill() instead?
// Sending Interrupt on Windows is not implemented.
err := s.cmd.Process.Signal(syscall.SIGKILL)
Expand All @@ -120,26 +120,26 @@ func (s *Supervisor) ShutdownWithTimeout(timeout time.Duration) error {
s.shutdown = true

if !s.isRunning() {
log.Println("Skipping ShutdownWithTimeout: child process not running")
log.Info("Skipping ShutdownWithTimeout: child process not running")
return nil
}

if s.shutdownTimer != nil {
return errors.New("shutdown already started")
}

log.Println("Terminating child process...")
log.Info("Terminating child process...")
err := s.cmd.Process.Signal(syscall.SIGTERM)
if err != nil {
return fmt.Errorf("failed to terminate child process: %v", err)
}

s.shutdownTimer = time.AfterFunc(timeout, func() {
log.Printf("Timeout elapsed: %s\n", timeout)
log.Info("Timeout elapsed: ", "timeout", timeout)
err := s.ShutdownNow()
if err != nil {
// TODO: ignorable?
log.Printf("Failed after timeout: %v\n", err)
log.Error(err, "Failed after timeout")
}
})

Expand Down