(mo *SingleMethodObj, action, dest, service string)
| 52 | } |
| 53 | |
| 54 | func enableRestartSystemdService(mo *SingleMethodObj, action, dest, service string) error { |
| 55 | act := action |
| 56 | if action == "autoupdate" { |
| 57 | act = "enable" |
| 58 | } |
| 59 | klog.Infof("Target: %s, running systemctl %s %s", mo.Target.Name, act, service) |
| 60 | sd := mo.Target.Methods.Systemd |
| 61 | if err := detectOrFetchImage(mo.Conn, systemdImage, false); err != nil { |
| 62 | return err |
| 63 | } |
| 64 | |
| 65 | // TODO: remove |
| 66 | if sd.Root { |
| 67 | os.Setenv("ROOT", "true") |
| 68 | } else { |
| 69 | os.Setenv("ROOT", "false") |
| 70 | } |
| 71 | s := specgen.NewSpecGenerator(systemdImage, false) |
| 72 | runMounttmp := "/run" |
| 73 | runMountsd := "/run/systemd" |
| 74 | runMountc := "/sys/fs/cgroup" |
| 75 | xdg := "" |
| 76 | if !sd.Root { |
| 77 | // need to document this for non-root usage |
| 78 | // can't use user.Current because always root in fetchit container |
| 79 | xdg = os.Getenv("XDG_RUNTIME_DIR") |
| 80 | if xdg == "" { |
| 81 | xdg = "/run/user/1000" |
| 82 | } |
| 83 | runMountsd = xdg + "/systemd" |
| 84 | } |
| 85 | s.Privileged = true |
| 86 | s.PidNS = specgen.Namespace{ |
| 87 | NSMode: "host", |
| 88 | Value: "", |
| 89 | } |
| 90 | if action == "autoupdate" { |
| 91 | s.Mounts = []specs.Mount{{Source: podmanServicePath, Destination: podmanServicePath, Type: define.TypeBind, Options: []string{"rw"}}, {Source: dest, Destination: dest, Type: define.TypeBind, Options: []string{"rw"}}, {Source: runMounttmp, Destination: runMounttmp, Type: define.TypeTmpfs, Options: []string{"rw"}}, {Source: runMountc, Destination: runMountc, Type: define.TypeBind, Options: []string{"ro"}}, {Source: runMountsd, Destination: runMountsd, Type: define.TypeBind, Options: []string{"rw"}}} |
| 92 | } else { |
| 93 | s.Mounts = []specs.Mount{{Source: dest, Destination: dest, Type: define.TypeBind, Options: []string{"rw"}}, {Source: runMounttmp, Destination: runMounttmp, Type: define.TypeTmpfs, Options: []string{"rw"}}, {Source: runMountc, Destination: runMountc, Type: define.TypeBind, Options: []string{"ro"}}, {Source: runMountsd, Destination: runMountsd, Type: define.TypeBind, Options: []string{"rw"}}} |
| 94 | } |
| 95 | s.Name = "systemd-" + act + "-" + service + "-" + mo.Target.Name |
| 96 | envMap := make(map[string]string) |
| 97 | envMap["ROOT"] = strconv.FormatBool(sd.Root) |
| 98 | envMap["SERVICE"] = service |
| 99 | envMap["ACTION"] = act |
| 100 | envMap["HOME"] = os.Getenv("HOME") |
| 101 | if !sd.Root { |
| 102 | envMap["XDG_RUNTIME_DIR"] = xdg |
| 103 | } |
| 104 | s.Env = envMap |
| 105 | createResponse, err := createAndStartContainer(mo.Conn, s) |
| 106 | if err != nil { |
| 107 | return err |
| 108 | } |
| 109 | |
| 110 | err = waitAndRemoveContainer(mo.Conn, createResponse.ID) |
| 111 | if err != nil { |
no test coverage detected