mirror of
https://github.com/containers/podman.git
synced 2025-06-20 00:51:16 +08:00
Update WSL machine OS to enable user lingering
Also migrate old machines that were missing this setting Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
This commit is contained in:
@ -36,6 +36,7 @@ var (
|
|||||||
const (
|
const (
|
||||||
ErrorSuccessRebootInitiated = 1641
|
ErrorSuccessRebootInitiated = 1641
|
||||||
ErrorSuccessRebootRequired = 3010
|
ErrorSuccessRebootRequired = 3010
|
||||||
|
currentMachineVersion = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
const containersConf = `[containers]
|
const containersConf = `[containers]
|
||||||
@ -168,6 +169,8 @@ type MachineVM struct {
|
|||||||
Rootful bool
|
Rootful bool
|
||||||
// SSH identity, username, etc
|
// SSH identity, username, etc
|
||||||
machine.SSHConfig
|
machine.SSHConfig
|
||||||
|
// machine version
|
||||||
|
Version int
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExitCodeError struct {
|
type ExitCodeError struct {
|
||||||
@ -241,12 +244,29 @@ func readAndMigrate(configPath string, name string) (*MachineVM, error) {
|
|||||||
return vm, err
|
return vm, err
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(b, vm)
|
err = json.Unmarshal(b, vm)
|
||||||
if err == nil && vm.Created.IsZero() {
|
if err == nil && vm.Version < currentMachineVersion {
|
||||||
err = vm.migrate40(configPath)
|
err = vm.migrateMachine(configPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
return vm, err
|
return vm, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *MachineVM) migrateMachine(configPath string) error {
|
||||||
|
if v.Created.IsZero() {
|
||||||
|
if err := v.migrate40(configPath); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update older machines to use lingering
|
||||||
|
if err := enableUserLinger(v, toDist(v.Name)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
v.Version = currentMachineVersion
|
||||||
|
return v.writeConfig()
|
||||||
|
}
|
||||||
|
|
||||||
func (v *MachineVM) migrate40(configPath string) error {
|
func (v *MachineVM) migrate40(configPath string) error {
|
||||||
v.ConfigPath = configPath
|
v.ConfigPath = configPath
|
||||||
fi, err := os.Stat(configPath)
|
fi, err := os.Stat(configPath)
|
||||||
@ -255,7 +275,7 @@ func (v *MachineVM) migrate40(configPath string) error {
|
|||||||
}
|
}
|
||||||
v.Created = fi.ModTime()
|
v.Created = fi.ModTime()
|
||||||
v.LastUp = getLegacyLastStart(v)
|
v.LastUp = getLegacyLastStart(v)
|
||||||
return v.writeConfig()
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLegacyLastStart(vm *MachineVM) time.Time {
|
func getLegacyLastStart(vm *MachineVM) time.Time {
|
||||||
@ -284,6 +304,7 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) {
|
|||||||
sshDir := filepath.Join(homeDir, ".ssh")
|
sshDir := filepath.Join(homeDir, ".ssh")
|
||||||
v.IdentityPath = filepath.Join(sshDir, v.Name)
|
v.IdentityPath = filepath.Join(sshDir, v.Name)
|
||||||
v.Rootful = opts.Rootful
|
v.Rootful = opts.Rootful
|
||||||
|
v.Version = currentMachineVersion
|
||||||
|
|
||||||
if err := downloadDistro(v, opts); err != nil {
|
if err := downloadDistro(v, opts); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@ -486,6 +507,10 @@ func configureSystem(v *MachineVM, dist string) error {
|
|||||||
return errors.Wrap(err, "could not generate linger service for guest OS")
|
return errors.Wrap(err, "could not generate linger service for guest OS")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := enableUserLinger(v, dist); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if err := pipeCmdPassThrough("wsl", withUser(lingerSetup, user), "-d", dist, "sh"); err != nil {
|
if err := pipeCmdPassThrough("wsl", withUser(lingerSetup, user), "-d", dist, "sh"); err != nil {
|
||||||
return errors.Wrap(err, "could not configure systemd settomgs for guest OS")
|
return errors.Wrap(err, "could not configure systemd settomgs for guest OS")
|
||||||
}
|
}
|
||||||
@ -501,6 +526,15 @@ func configureSystem(v *MachineVM, dist string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func enableUserLinger(v *MachineVM, dist string) error {
|
||||||
|
lingerCmd := "mkdir -p /var/lib/systemd/linger; touch /var/lib/systemd/linger/" + v.RemoteUsername
|
||||||
|
if err := runCmdPassThrough("wsl", "-d", dist, "sh", "-c", lingerCmd); err != nil {
|
||||||
|
return errors.Wrap(err, "could not enable linger for remote user on guest OS")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func installScripts(dist string) error {
|
func installScripts(dist string) error {
|
||||||
if err := pipeCmdPassThrough("wsl", enterns, "-d", dist, "sh", "-c",
|
if err := pipeCmdPassThrough("wsl", enterns, "-d", dist, "sh", "-c",
|
||||||
"cat > /usr/local/bin/enterns; chmod 755 /usr/local/bin/enterns"); err != nil {
|
"cat > /usr/local/bin/enterns; chmod 755 /usr/local/bin/enterns"); err != nil {
|
||||||
|
Reference in New Issue
Block a user