-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
incus-osd: Add support for sysupdate
Signed-off-by: Stéphane Graber <[email protected]>
- Loading branch information
Showing
5 changed files
with
162 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package systemd | ||
|
||
var ( | ||
SystemExtensionsPath = "/var/lib/extensions" | ||
SystemUpdatesPath = "/var/lib/updates" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package systemd | ||
|
||
import ( | ||
"bufio" | ||
"context" | ||
"errors" | ||
"os" | ||
"strings" | ||
|
||
"github.com/lxc/incus/v6/shared/subprocess" | ||
) | ||
|
||
var ErrReleaseNotFound = errors.New("couldn't determine current OS release") | ||
|
||
// GetCurrentRelease returns the current IMAGE_VERSION from the os-release file. | ||
func GetCurrentRelease(_ context.Context) (string, error) { | ||
// Open the os-release file. | ||
fd, err := os.Open("/lib/os-release") | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
defer fd.Close() | ||
|
||
// Prepare reader. | ||
fdScan := bufio.NewScanner(fd) | ||
for fdScan.Scan() { | ||
line := fdScan.Text() | ||
fields := strings.SplitN(line, "=", 2) | ||
|
||
if len(fields) != 2 { | ||
continue | ||
} | ||
|
||
if fields[0] == "IMAGE_VERSION" { | ||
return strings.Trim(fields[1], "\""), nil | ||
} | ||
} | ||
|
||
return "", ErrReleaseNotFound | ||
} | ||
|
||
func ApplySystemUpdate(ctx context.Context, version string, reboot bool) error { | ||
// WORKAROUND: Start the boot.mount unit so /boot autofs is active before we create a new mount namespace. | ||
err := StartUnit(ctx, "boot.mount") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// WORKAROUND: Needed until systemd-sysupdate can be run with system extensions applied. | ||
cmd := "mount /dev/mapper/usr /usr && /usr/lib/systemd/systemd-sysupdate update " + version | ||
if reboot { | ||
cmd += "&& /usr/lib/systemd/systemd-sysupdate reboot" | ||
} | ||
|
||
_, err = subprocess.RunCommandContext(ctx, "unshare", "-m", "--", "sh", "-c", cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |