Write termination message
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
@@ -45,9 +46,9 @@ func (f *simpleTextFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
||||
return []byte(formatSimple(entry.Time.Format(timestampFormat), entry.Message)), nil
|
||||
}
|
||||
|
||||
func logDebug(msg string) {
|
||||
func logDebug(args ...interface{}) {
|
||||
if debug {
|
||||
log.Debugln(msg)
|
||||
log.Debug(args)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +58,22 @@ func logDebugf(format string, args ...interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func logTerminationf(format string, args ...interface{}) {
|
||||
logTermination(fmt.Sprintf(format, args))
|
||||
}
|
||||
|
||||
func logTermination(args ...interface{}) {
|
||||
msg := fmt.Sprint(args)
|
||||
// Write the message to the termination log. This is the default place
|
||||
// that Kubernetes will look for termination information.
|
||||
log.Debugf("Writing termination message: %v", msg)
|
||||
err := ioutil.WriteFile("/dev/termination-log", []byte(msg), 0660)
|
||||
if err != nil {
|
||||
log.Debug(err)
|
||||
}
|
||||
log.Error(msg)
|
||||
}
|
||||
|
||||
func jsonLogs() bool {
|
||||
e := os.Getenv("MQ_ALPHA_JSON_LOGS")
|
||||
if e == "true" || e == "1" {
|
||||
@@ -78,7 +95,7 @@ func mirrorLogs(ctx context.Context, wg *sync.WaitGroup, name string, fromStart
|
||||
// Put the queue manager name in quotes to handle cases like name=..
|
||||
qm, err := mqini.GetQueueManager(name)
|
||||
if err != nil {
|
||||
logDebugf("%v", err)
|
||||
logDebug(err)
|
||||
return nil, err
|
||||
}
|
||||
f := filepath.Join(mqini.GetErrorLogDirectory(qm), "AMQERR01.json")
|
||||
|
||||
@@ -34,19 +34,23 @@ func doMain() error {
|
||||
configureDebugLogger()
|
||||
err := ready.Clear()
|
||||
if err != nil {
|
||||
logTermination(err)
|
||||
return err
|
||||
}
|
||||
name, err := name.GetQueueManagerName()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
logTermination(err)
|
||||
return err
|
||||
}
|
||||
accepted, err := checkLicense()
|
||||
if err != nil {
|
||||
logTerminationf("Error checking license acceptance: %v", err)
|
||||
return err
|
||||
}
|
||||
if !accepted {
|
||||
return errors.New("License not accepted")
|
||||
err = errors.New("License not accepted")
|
||||
logTermination(err)
|
||||
return err
|
||||
}
|
||||
log.Printf("Using queue manager name: %v", name)
|
||||
|
||||
@@ -56,7 +60,7 @@ func doMain() error {
|
||||
logConfig()
|
||||
err = createVolume("/mnt/mqm")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
logTermination(err)
|
||||
return err
|
||||
}
|
||||
err = createDirStructure()
|
||||
@@ -65,6 +69,7 @@ func doMain() error {
|
||||
}
|
||||
newQM, err := createQueueManager(name)
|
||||
if err != nil {
|
||||
logTermination(err)
|
||||
return err
|
||||
}
|
||||
var wg sync.WaitGroup
|
||||
@@ -80,14 +85,17 @@ func doMain() error {
|
||||
// TODO: Use the error channel
|
||||
_, err = mirrorLogs(ctx, &wg, name, newQM)
|
||||
if err != nil {
|
||||
logTermination(err)
|
||||
return err
|
||||
}
|
||||
err = updateCommandLevel()
|
||||
if err != nil {
|
||||
logTermination(err)
|
||||
return err
|
||||
}
|
||||
err = startQueueManager()
|
||||
if err != nil {
|
||||
logTermination(err)
|
||||
return err
|
||||
}
|
||||
configureQueueManager()
|
||||
|
||||
@@ -18,6 +18,7 @@ package main
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -42,7 +43,7 @@ func waitForFile(ctx context.Context, path string) (os.FileInfo, error) {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
continue
|
||||
} else {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("mirror: unable to get info on file %v", path)
|
||||
}
|
||||
}
|
||||
log.Debugf("File exists: %v, %v", path, fi.Size())
|
||||
@@ -101,7 +102,6 @@ func mirrorLog(ctx context.Context, wg *sync.WaitGroup, path string, fromStart b
|
||||
// File already exists, so start reading at the end
|
||||
offset = fi.Size()
|
||||
}
|
||||
|
||||
// Increment wait group counter, only if the goroutine gets started
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
|
||||
Reference in New Issue
Block a user