summaryrefslogtreecommitdiff
path: root/libpod/runtime.go
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/runtime.go')
-rw-r--r--libpod/runtime.go69
1 files changed, 55 insertions, 14 deletions
diff --git a/libpod/runtime.go b/libpod/runtime.go
index 3b1c2be98..e85242028 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -1,6 +1,7 @@
package libpod
import (
+ "context"
"fmt"
"io/ioutil"
"os"
@@ -11,6 +12,7 @@ import (
"github.com/BurntSushi/toml"
is "github.com/containers/image/storage"
"github.com/containers/image/types"
+ "github.com/containers/libpod/libpod/events"
"github.com/containers/libpod/libpod/image"
"github.com/containers/libpod/libpod/lock"
"github.com/containers/libpod/pkg/firewall"
@@ -99,12 +101,19 @@ type Runtime struct {
// unused.
doRenumber bool
+ doMigrate bool
+
// valid indicates whether the runtime is ready to use.
// valid is set to true when a runtime is returned from GetRuntime(),
// and remains true until the runtime is shut down (rendering its
// storage unusable). When valid is false, the runtime cannot be used.
valid bool
lock sync.RWMutex
+
+ // mechanism to read and write even logs
+ eventer events.Eventer
+
+ ctx context.Context
}
// OCIRuntimePath contains information about an OCI runtime.
@@ -222,6 +231,8 @@ type RuntimeConfig struct {
// pods.
NumLocks uint32 `toml:"num_locks,omitempty"`
+ // EventsLogger determines where events should be logged
+ EventsLogger string `toml:"events_logger"`
// EventsLogFilePath is where the events log is stored.
EventsLogFilePath string `toml:-"events_logfile_path"`
}
@@ -252,7 +263,6 @@ func defaultRuntimeConfig() (RuntimeConfig, error) {
if err != nil {
return RuntimeConfig{}, err
}
-
return RuntimeConfig{
// Leave this empty so containers/storage will use its defaults
StorageConfig: storage.StoreOptions{},
@@ -296,6 +306,7 @@ func defaultRuntimeConfig() (RuntimeConfig, error) {
EnablePortReservation: true,
EnableLabeling: true,
NumLocks: 2048,
+ EventsLogger: "journald",
}, nil
}
@@ -748,6 +759,17 @@ func makeRuntime(runtime *Runtime) (err error) {
if err != nil {
return err
}
+
+ defer func() {
+ if err != nil && store != nil {
+ // Don't forcibly shut down
+ // We could be opening a store in use by another libpod
+ _, err2 := store.Shutdown(false)
+ if err2 != nil {
+ logrus.Errorf("Error removing store for partially-created runtime: %s", err2)
+ }
+ }
+ }()
}
runtime.store = store
@@ -755,27 +777,24 @@ func makeRuntime(runtime *Runtime) (err error) {
// Set up image runtime and store in runtime
ir := image.NewImageRuntimeFromStore(runtime.store)
- if err != nil {
- return err
- }
runtime.imageRuntime = ir
// Setting signaturepolicypath
ir.SignaturePolicyPath = runtime.config.SignaturePolicyPath
+
// Set logfile path for events
ir.EventsLogFilePath = runtime.config.EventsLogFilePath
+ // Set logger type
+ ir.EventsLogger = runtime.config.EventsLogger
- defer func() {
- if err != nil && store != nil {
- // Don't forcibly shut down
- // We could be opening a store in use by another libpod
- _, err2 := store.Shutdown(false)
- if err2 != nil {
- logrus.Errorf("Error removing store for partially-created runtime: %s", err2)
- }
- }
- }()
+ // Setup the eventer
+ eventer, err := runtime.newEventer()
+ if err != nil {
+ return err
+ }
+ runtime.eventer = eventer
+ ir.Eventer = eventer
// Set up a storage service for creating container root filesystems from
// images
@@ -948,6 +967,24 @@ func makeRuntime(runtime *Runtime) (err error) {
// further
runtime.valid = true
+ if runtime.doMigrate {
+ if os.Geteuid() != 0 {
+ aliveLock.Unlock()
+ locked = false
+
+ became, ret, err := rootless.BecomeRootInUserNS()
+ if err != nil {
+ return err
+ }
+ if became {
+ os.Exit(ret)
+ }
+ }
+ if err := runtime.migrate(); err != nil {
+ return err
+ }
+ }
+
return nil
}
@@ -1018,6 +1055,8 @@ func (r *Runtime) Shutdown(force bool) error {
// Refreshes the state, recreating temporary files
// Does not check validity as the runtime is not valid until after this has run
func (r *Runtime) refresh(alivePath string) error {
+ logrus.Debugf("Podman detected system restart - performing state refresh")
+
// First clear the state in the database
if err := r.state.Refresh(); err != nil {
return err
@@ -1058,6 +1097,8 @@ func (r *Runtime) refresh(alivePath string) error {
}
defer file.Close()
+ r.newSystemEvent(events.Refresh)
+
return nil
}