summaryrefslogtreecommitdiff
path: root/libpod/sql_state.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2017-12-07 13:15:34 -0500
committerMatthew Heon <matthew.heon@gmail.com>2017-12-07 13:15:34 -0500
commitb71cde19c8b511c054ee42084113ce97ed6d5b62 (patch)
treec69fc6b6a6ad1d931c059ad2325ca7778b8ba4e8 /libpod/sql_state.go
parentb66287689a0c8c9f2f8c01cdca065fb1f6e8d872 (diff)
downloadpodman-b71cde19c8b511c054ee42084113ce97ed6d5b62.tar.gz
podman-b71cde19c8b511c054ee42084113ce97ed6d5b62.tar.bz2
podman-b71cde19c8b511c054ee42084113ce97ed6d5b62.zip
Add ability to refresh state in DB
Also, ensure we always recreate runtime spec so our net namespace paths will be correct Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Diffstat (limited to 'libpod/sql_state.go')
-rw-r--r--libpod/sql_state.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/libpod/sql_state.go b/libpod/sql_state.go
index fb6be85d7..bba697d18 100644
--- a/libpod/sql_state.go
+++ b/libpod/sql_state.go
@@ -103,6 +103,52 @@ func (s *SQLState) Close() error {
return nil
}
+// Refresh clears the state after a reboot
+// Resets mountpoint, PID, state for all containers
+func (s *SQLState) Refresh() (err error) {
+ const refresh = `UPDATE containerState SET
+ State=?,
+ Mountpoint=?,
+ Pid=?;`
+
+ s.lock.Lock()
+ defer s.lock.Unlock()
+
+ if !s.valid {
+ return ErrDBClosed
+ }
+
+ tx, err := s.db.Begin()
+ if err != nil {
+ return errors.Wrapf(err, "error beginning database transaction")
+ }
+ defer func() {
+ if err != nil {
+ if err2 := tx.Rollback(); err2 != nil {
+ logrus.Errorf("Error rolling back transaction to refresh state: %v", err2)
+ }
+ }
+ }()
+
+ // Refresh container state
+ // The constants could be moved into the SQL, but keeping them here
+ // will keep us in sync in case ContainerStateConfigured ever changes in
+ // the container state
+ _, err = tx.Exec(refresh,
+ ContainerStateConfigured,
+ "",
+ 0)
+ if err != nil {
+ return errors.Wrapf(err, "error refreshing database state")
+ }
+
+ if err := tx.Commit(); err != nil {
+ return errors.Wrapf(err, "error committing transaction to refresh database")
+ }
+
+ return nil
+}
+
// Container retrieves a container from its full ID
func (s *SQLState) Container(id string) (*Container, error) {
const query = `SELECT containers.*,