summaryrefslogtreecommitdiff
path: root/libpod/sql_state.go
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2017-12-11 10:47:50 -0600
committerGitHub <noreply@github.com>2017-12-11 10:47:50 -0600
commit62e19beeecc8f4af97388c0e715c92b582fbe685 (patch)
tree0d5cd12032d5a90305c00370c861ac69c46dc821 /libpod/sql_state.go
parent915410aafffbe91707e2dd6562a1bfb237815f88 (diff)
parentb71cde19c8b511c054ee42084113ce97ed6d5b62 (diff)
downloadpodman-62e19beeecc8f4af97388c0e715c92b582fbe685.tar.gz
podman-62e19beeecc8f4af97388c0e715c92b582fbe685.tar.bz2
podman-62e19beeecc8f4af97388c0e715c92b582fbe685.zip
Merge pull request #94 from mheon/restart
Add handling for system restart in libpod
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.*,