2021-09-06 11:26:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2022-03-15 15:27:34 +00:00
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
2022-03-11 15:37:41 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2021-09-06 11:26:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var logger = NewLogger()
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
err := run(os.Args)
|
|
|
|
if err != nil {
|
2022-03-30 11:18:57 +00:00
|
|
|
logger.Errorf("%v", err)
|
2021-09-06 11:26:48 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// run is an entry point that allows for idiomatic handling of errors
|
|
|
|
// when calling from the main function.
|
2022-02-22 13:17:10 +00:00
|
|
|
func run(argv []string) (rerr error) {
|
2022-03-30 11:18:57 +00:00
|
|
|
logger.Debugf("Running %v", argv)
|
2022-03-29 10:01:12 +00:00
|
|
|
cfg, err := config.GetConfig()
|
2021-09-06 11:26:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error loading config: %v", err)
|
|
|
|
}
|
|
|
|
|
2022-03-29 10:01:12 +00:00
|
|
|
err = logger.LogToFile(cfg.NVIDIAContainerRuntimeConfig.DebugFilePath)
|
2021-09-06 11:26:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error opening debug log file: %v", err)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
// We capture and log a returning error before closing the log file.
|
2022-02-22 13:17:10 +00:00
|
|
|
if rerr != nil {
|
2022-03-30 11:18:57 +00:00
|
|
|
logger.Errorf("%v", rerr)
|
2021-09-06 11:26:48 +00:00
|
|
|
}
|
|
|
|
logger.CloseFile()
|
|
|
|
}()
|
|
|
|
|
2022-03-11 15:37:41 +00:00
|
|
|
if logLevel, err := logrus.ParseLevel(cfg.NVIDIAContainerRuntimeConfig.LogLevel); err == nil {
|
|
|
|
logger.SetLevel(logLevel)
|
|
|
|
} else {
|
|
|
|
logger.Warnf("Invalid log-level '%v'; using '%v'", cfg.NVIDIAContainerRuntimeConfig.LogLevel, logger.Level.String())
|
|
|
|
}
|
|
|
|
|
2022-03-24 11:45:03 +00:00
|
|
|
runtime, err := newNVIDIAContainerRuntime(logger.Logger, cfg, argv)
|
2021-09-06 11:26:48 +00:00
|
|
|
if err != nil {
|
2022-03-15 12:29:14 +00:00
|
|
|
return fmt.Errorf("failed to create NVIDIA Container Runtime: %v", err)
|
2021-09-06 11:26:48 +00:00
|
|
|
}
|
|
|
|
|
2022-03-24 11:45:03 +00:00
|
|
|
return runtime.Exec(argv)
|
2021-09-06 11:26:48 +00:00
|
|
|
}
|