Skip to content

Commit

Permalink
Update logger and service file for better debuggability
Browse files Browse the repository at this point in the history
Launcher logger will be published to stdout and Cloud Logging

Signed-off-by: Jiankun Lu <jiankun@google.com>
  • Loading branch information
jkl73 committed May 25, 2022
1 parent 11da8cc commit d300c60
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion launcher/container-runner.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ After=network-online.target gcr-online.target containerd.service
[Service]
ExecStart=/var/lib/google/cc_container_launcher --addr=${ATTEST_ENDPOINT}
# Shutdown the host after the launcher exits
ExecStopPost=systemctl poweroff
ExecStopPost=/bin/sleep 60
ExecStopPost=/usr/bin/systemctl poweroff
Restart=no
# RestartSec=90
StandardOutput=journal+console
Expand Down
4 changes: 1 addition & 3 deletions launcher/container_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,8 @@ func (r *ContainerRunner) Run(ctx context.Context) error {
return fmt.Errorf("failed to fetch and write OIDC token: %v", err)
}

loggerAndStdout := io.MultiWriter(os.Stdout, r.logger.Writer())
loggerAndStderr := io.MultiWriter(os.Stderr, r.logger.Writer())
for {
task, err := r.container.NewTask(ctx, cio.NewCreator(cio.WithStreams(nil, loggerAndStdout, loggerAndStderr)))
task, err := r.container.NewTask(ctx, cio.NewCreator(cio.WithStreams(nil, r.logger.Writer(), r.logger.Writer())))
if err != nil {
return err
}
Expand Down
13 changes: 10 additions & 3 deletions launcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main
import (
"context"
"flag"
"io"
"log"
"os"

Expand All @@ -21,6 +22,10 @@ var (
serverAddr = flag.String("addr", "", "The server address in the format of host:port")
)

const (
logName = "confidential-space-launcher"
)

func main() {
flag.Parse()
os.Exit(run())
Expand All @@ -39,11 +44,13 @@ func run() int {
}
logClient, err := logging.NewClient(context.Background(), projectID)
if err != nil {
logger.Printf("cannot setup Cloud Logging, using the default logger %v", err)
logger.Printf("cannot setup Cloud Logging, using the default stdout logger %v", err)
} else {
defer logClient.Close()
logger.Println("logs will publish to Cloud Logging")
logger = logClient.Logger("confidential-space-launcher").StandardLogger(logging.Info)
logger.Printf("logs will be published to Cloud Logging under the log name %s\n", logName)
logger = logClient.Logger(logName).StandardLogger(logging.Info)
loggerAndStdout := io.MultiWriter(os.Stdout, logger.Writer()) // for now also print log to stdout
logger.SetOutput(loggerAndStdout)
}

spec, err := spec.GetLauncherSpec(mdsClient)
Expand Down

0 comments on commit d300c60

Please sign in to comment.