Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"flag"
"fmt"
"os"
"os/exec"
"strings"

"github.com/golang/glog"
Expand Down Expand Up @@ -50,8 +49,8 @@ func init() {

// podmanRemove kills and removes a container
func podmanRemove(cid string) {
exec.Command("podman", "kill", cid).Run()
exec.Command("podman", "rm", "-f", cid).Run()
utils.RunIgnoreErr("podman", "kill", cid)
utils.RunIgnoreErr("podman", "rm", "-f", cid)
}

// getDefaultDeployment uses rpm-ostree status --json to get the current deployment
Expand All @@ -71,9 +70,8 @@ func getDefaultDeployment() types.RpmOstreeDeployment {
return rosState.Deployments[0]
}

// Execute runs the command
func Execute(cmd *cobra.Command, args []string) {
container := args[0]
// Potentially rebases system if not already rebased.
func pullAndRebase(container string) (imgid string, changed bool) {
defaultDeployment := getDefaultDeployment()

previousPivot := ""
Expand All @@ -89,14 +87,11 @@ func Execute(cmd *cobra.Command, args []string) {

var imagedata types.ImageInspection
json.Unmarshal([]byte(output), &imagedata)
imgid := fmt.Sprintf("%s@%s", imagedata.Name, imagedata.Digest)
imgid = fmt.Sprintf("%s@%s", imagedata.Name, imagedata.Digest)
glog.Infof("Resolved to: %s", imgid)

if previousPivot == imgid {
glog.Info("Already at target pivot; exiting...")
if (exit_77) {
os.Exit(77)
}
changed = false
return
}

Expand Down Expand Up @@ -140,13 +135,28 @@ func Execute(cmd *cobra.Command, args []string) {
// Kill our dummy container
podmanRemove(types.PivotName)

changed = true
return
}

// Execute runs the command
func Execute(cmd *cobra.Command, args []string) {
container := args[0]
imgid, changed := pullAndRebase(container)

// By default, delete the image.
if !keep {
utils.Run("podman", "rmi", imgid)
// Related: https://github.com/containers/libpod/issues/2234
utils.RunIgnoreErr("podman", "rmi", imgid)
}

if !changed {
glog.Info("Already at target pivot; exiting...")
if (exit_77) {
os.Exit(77)
}
// Reboot the machine if asked to do so
if reboot {
} else if reboot {
utils.Run("systemctl", "reboot")
}
}
6 changes: 6 additions & 0 deletions utils/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ func Run(command string, args ...string) {
}
}

func RunIgnoreErr(command string, args ...string) {
if _, err := runImpl(false, command, args...); err != nil {
glog.Warningf("(ignored) %s: %s", command, err)
}
}

// Like Run(), but get the output as a string
func RunGetOut(command string, args ...string) string {
var err error
Expand Down