[WIP] working download and replace.
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
package updates
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/safing/portmaster/base/api"
|
||||
"github.com/safing/portmaster/base/config"
|
||||
@@ -14,10 +12,10 @@ import (
|
||||
"github.com/safing/portmaster/service/updates/registry"
|
||||
)
|
||||
|
||||
var applyUpdates bool
|
||||
var autoUpdate bool
|
||||
|
||||
func init() {
|
||||
flag.BoolVar(&applyUpdates, "update", false, "apply downloaded updates")
|
||||
flag.BoolVar(&autoUpdate, "auto-update", false, "auto apply downloaded updates")
|
||||
}
|
||||
|
||||
// Updates provides access to released artifacts.
|
||||
@@ -25,9 +23,8 @@ type Updates struct {
|
||||
m *mgr.Manager
|
||||
states *mgr.StateMgr
|
||||
|
||||
updateBinaryWorkerMgr *mgr.WorkerMgr
|
||||
updateIntelWorkerMgr *mgr.WorkerMgr
|
||||
restartWorkerMgr *mgr.WorkerMgr
|
||||
updateCheckWorkerMgr *mgr.WorkerMgr
|
||||
upgraderWorkerMgr *mgr.WorkerMgr
|
||||
|
||||
EventResourcesUpdated *mgr.EventMgr[struct{}]
|
||||
EventVersionsUpdated *mgr.EventMgr[struct{}]
|
||||
@@ -37,15 +34,9 @@ type Updates struct {
|
||||
instance instance
|
||||
}
|
||||
|
||||
var shimLoaded atomic.Bool
|
||||
|
||||
// New returns a new UI module.
|
||||
func New(instance instance) (*Updates, error) {
|
||||
if !shimLoaded.CompareAndSwap(false, true) {
|
||||
return nil, errors.New("only one instance allowed")
|
||||
}
|
||||
|
||||
m := mgr.New("Updates")
|
||||
// New returns a new Updates module.
|
||||
func New(instance instance, name string, index registry.UpdateIndex) (*Updates, error) {
|
||||
m := mgr.New(name)
|
||||
module := &Updates{
|
||||
m: m,
|
||||
states: m.NewStateMgr(),
|
||||
@@ -57,63 +48,47 @@ func New(instance instance) (*Updates, error) {
|
||||
}
|
||||
|
||||
// Events
|
||||
module.updateBinaryWorkerMgr = m.NewWorkerMgr("binary updater", module.checkForBinaryUpdates, nil)
|
||||
module.updateIntelWorkerMgr = m.NewWorkerMgr("intel updater", module.checkForIntelUpdates, nil)
|
||||
module.restartWorkerMgr = m.NewWorkerMgr("automatic restart", automaticRestart, nil)
|
||||
module.updateCheckWorkerMgr = m.NewWorkerMgr("update checker", module.checkForUpdates, nil)
|
||||
module.updateCheckWorkerMgr.Repeat(30 * time.Second)
|
||||
module.upgraderWorkerMgr = m.NewWorkerMgr("upgrader", func(w *mgr.WorkerCtx) error {
|
||||
err := module.registry.ApplyUpdates()
|
||||
if err != nil {
|
||||
// TODO(vladimir): Send notification to UI
|
||||
log.Errorf("updates: failed to apply updates: %s", err)
|
||||
} else {
|
||||
module.instance.Restart()
|
||||
}
|
||||
return nil
|
||||
}, nil)
|
||||
|
||||
binIndex := registry.UpdateIndex{
|
||||
Directory: "/usr/lib/portmaster",
|
||||
DownloadDirectory: "/var/lib/portmaster/new_bin",
|
||||
Ignore: []string{"databases", "intel", "config.json"},
|
||||
IndexURLs: []string{"http://localhost:8000/test-binary.json"},
|
||||
IndexFile: "bin-index.json",
|
||||
AutoApply: false,
|
||||
}
|
||||
|
||||
intelIndex := registry.UpdateIndex{
|
||||
Directory: "/var/lib/portmaster/intel",
|
||||
DownloadDirectory: "/var/lib/portmaster/new_intel",
|
||||
IndexURLs: []string{"http://localhost:8000/test-intel.json"},
|
||||
IndexFile: "intel-index.json",
|
||||
AutoApply: true,
|
||||
}
|
||||
module.registry = registry.New(binIndex, intelIndex)
|
||||
module.registry = registry.New(index)
|
||||
_ = module.registry.Initialize()
|
||||
|
||||
return module, nil
|
||||
}
|
||||
|
||||
func (u *Updates) checkForBinaryUpdates(_ *mgr.WorkerCtx) error {
|
||||
hasUpdates, err := u.registry.CheckForBinaryUpdates()
|
||||
func (u *Updates) checkForUpdates(_ *mgr.WorkerCtx) error {
|
||||
hasUpdates, err := u.registry.CheckForUpdates()
|
||||
if err != nil {
|
||||
log.Errorf("updates: failed to check for binary updates: %s", err)
|
||||
log.Errorf("updates: failed to check for updates: %s", err)
|
||||
}
|
||||
if hasUpdates {
|
||||
log.Infof("updates: there is updates available in the binary bundle")
|
||||
err = u.registry.DownloadBinaryUpdates()
|
||||
log.Infof("updates: there is updates available")
|
||||
err = u.registry.DownloadUpdates()
|
||||
if err != nil {
|
||||
log.Errorf("updates: failed to download bundle: %s", err)
|
||||
} else if autoUpdate {
|
||||
u.ApplyUpdates()
|
||||
}
|
||||
} else {
|
||||
log.Infof("updates: no new binary updates")
|
||||
log.Infof("updates: no new updates")
|
||||
u.EventResourcesUpdated.Submit(struct{}{})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *Updates) checkForIntelUpdates(_ *mgr.WorkerCtx) error {
|
||||
hasUpdates, err := u.registry.CheckForIntelUpdates()
|
||||
if err != nil {
|
||||
log.Errorf("updates: failed to check for intel updates: %s", err)
|
||||
}
|
||||
if hasUpdates {
|
||||
log.Infof("updates: there is updates available in the intel bundle")
|
||||
err = u.registry.DownloadIntelUpdates()
|
||||
if err != nil {
|
||||
log.Errorf("updates: failed to download bundle: %s", err)
|
||||
}
|
||||
} else {
|
||||
log.Infof("updates: no new intel data updates")
|
||||
}
|
||||
return nil
|
||||
func (u *Updates) ApplyUpdates() {
|
||||
u.upgraderWorkerMgr.Go()
|
||||
}
|
||||
|
||||
// States returns the state manager.
|
||||
@@ -128,29 +103,7 @@ func (u *Updates) Manager() *mgr.Manager {
|
||||
|
||||
// Start starts the module.
|
||||
func (u *Updates) Start() error {
|
||||
// initConfig()
|
||||
|
||||
if applyUpdates {
|
||||
err := u.registry.ApplyBinaryUpdates()
|
||||
if err != nil {
|
||||
log.Errorf("updates: failed to apply binary updates: %s", err)
|
||||
}
|
||||
err = u.registry.ApplyIntelUpdates()
|
||||
if err != nil {
|
||||
log.Errorf("updates: failed to apply intel updates: %s", err)
|
||||
}
|
||||
u.instance.Restart()
|
||||
return nil
|
||||
}
|
||||
|
||||
err := u.registry.Initialize()
|
||||
if err != nil {
|
||||
// TODO(vladimir): Find a better way to handle this error. The service will stop if parsing of the bundle files fails.
|
||||
return fmt.Errorf("failed to initialize registry: %w", err)
|
||||
}
|
||||
|
||||
u.updateBinaryWorkerMgr.Go()
|
||||
u.updateIntelWorkerMgr.Go()
|
||||
u.updateCheckWorkerMgr.Go()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -17,12 +17,6 @@ import (
|
||||
"github.com/safing/portmaster/base/log"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultFileMode = os.FileMode(0o0644)
|
||||
executableFileMode = os.FileMode(0o0744)
|
||||
defaultDirMode = os.FileMode(0o0755)
|
||||
)
|
||||
|
||||
const MaxUnpackSize = 1 << 30 // 2^30 == 1GB
|
||||
|
||||
type Artifact struct {
|
||||
@@ -35,18 +29,17 @@ type Artifact struct {
|
||||
}
|
||||
|
||||
type Bundle struct {
|
||||
dir string
|
||||
Name string `json:"Bundle"`
|
||||
Version string `json:"Version"`
|
||||
Published time.Time `json:"Published"`
|
||||
Artifacts []Artifact `json:"Artifacts"`
|
||||
}
|
||||
|
||||
func (bundle Bundle) downloadAndVerify() {
|
||||
func (bundle Bundle) downloadAndVerify(dir string) {
|
||||
client := http.Client{}
|
||||
for _, artifact := range bundle.Artifacts {
|
||||
|
||||
filePath := fmt.Sprintf("%s/%s", bundle.dir, artifact.Filename)
|
||||
filePath := fmt.Sprintf("%s/%s", dir, artifact.Filename)
|
||||
// TODO(vladimir): is this needed?
|
||||
_ = os.MkdirAll(filepath.Dir(filePath), defaultDirMode)
|
||||
|
||||
@@ -66,9 +59,9 @@ func (bundle Bundle) downloadAndVerify() {
|
||||
}
|
||||
|
||||
// Verify checks if the files are present int the dataDir and have the correct hash.
|
||||
func (bundle Bundle) Verify() error {
|
||||
func (bundle Bundle) Verify(dir string) error {
|
||||
for _, artifact := range bundle.Artifacts {
|
||||
artifactPath := fmt.Sprintf("%s/%s", bundle.dir, artifact.Filename)
|
||||
artifactPath := fmt.Sprintf("%s/%s", dir, artifact.Filename)
|
||||
file, err := os.Open(artifactPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open file %s: %w", artifactPath, err)
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
type UpdateIndex struct {
|
||||
Directory string
|
||||
DownloadDirectory string
|
||||
PurgeDirectory string
|
||||
Ignore []string
|
||||
IndexURLs []string
|
||||
IndexFile string
|
||||
@@ -23,7 +24,7 @@ func (ui *UpdateIndex) downloadIndexFile() (err error) {
|
||||
for _, url := range ui.IndexURLs {
|
||||
err = ui.downloadIndexFileFromURL(url)
|
||||
if err != nil {
|
||||
log.Warningf("updates: %s", err)
|
||||
log.Warningf("updates: failed while downloading index file %s", err)
|
||||
continue
|
||||
}
|
||||
// Downloading was successful.
|
||||
@@ -37,7 +38,7 @@ func (ui *UpdateIndex) downloadIndexFileFromURL(url string) error {
|
||||
client := http.Client{}
|
||||
resp, err := client.Get(url)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed a get request to %s: %w", url, err)
|
||||
return fmt.Errorf("failed GET request to %s: %w", url, err)
|
||||
}
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
filePath := fmt.Sprintf("%s/%s", ui.DownloadDirectory, ui.IndexFile)
|
||||
|
||||
@@ -14,6 +14,12 @@ import (
|
||||
|
||||
var ErrNotFound error = errors.New("file not found")
|
||||
|
||||
const (
|
||||
defaultFileMode = os.FileMode(0o0644)
|
||||
executableFileMode = os.FileMode(0o0744)
|
||||
defaultDirMode = os.FileMode(0o0755)
|
||||
)
|
||||
|
||||
type File struct {
|
||||
id string
|
||||
path string
|
||||
@@ -32,24 +38,19 @@ func (f *File) Version() string {
|
||||
}
|
||||
|
||||
type Registry struct {
|
||||
binaryUpdateIndex UpdateIndex
|
||||
intelUpdateIndex UpdateIndex
|
||||
updateIndex UpdateIndex
|
||||
|
||||
binaryBundle *Bundle
|
||||
intelBundle *Bundle
|
||||
|
||||
binaryUpdateBundle *Bundle
|
||||
intelUpdateBundle *Bundle
|
||||
bundle *Bundle
|
||||
updateBundle *Bundle
|
||||
|
||||
files map[string]File
|
||||
}
|
||||
|
||||
// New create new Registry.
|
||||
func New(binIndex UpdateIndex, intelIndex UpdateIndex) Registry {
|
||||
func New(index UpdateIndex) Registry {
|
||||
return Registry{
|
||||
binaryUpdateIndex: binIndex,
|
||||
intelUpdateIndex: intelIndex,
|
||||
files: make(map[string]File),
|
||||
updateIndex: index,
|
||||
files: make(map[string]File),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,26 +59,20 @@ func (reg *Registry) Initialize() error {
|
||||
var err error
|
||||
|
||||
// Parse current installed binary bundle.
|
||||
reg.binaryBundle, err = parseBundle(reg.binaryUpdateIndex.Directory, reg.binaryUpdateIndex.IndexFile)
|
||||
reg.bundle, err = parseBundle(reg.updateIndex.Directory, reg.updateIndex.IndexFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse binary bundle: %w", err)
|
||||
}
|
||||
// Parse current installed intel bundle.
|
||||
reg.intelBundle, err = parseBundle(reg.intelUpdateIndex.Directory, reg.intelUpdateIndex.IndexFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse intel bundle: %w", err)
|
||||
}
|
||||
|
||||
// Add bundle artifacts to registry.
|
||||
reg.processBundle(reg.binaryBundle)
|
||||
reg.processBundle(reg.intelBundle)
|
||||
reg.processBundle(reg.bundle)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (reg *Registry) processBundle(bundle *Bundle) {
|
||||
for _, artifact := range bundle.Artifacts {
|
||||
artifactPath := fmt.Sprintf("%s/%s", bundle.dir, artifact.Filename)
|
||||
artifactPath := fmt.Sprintf("%s/%s", reg.updateIndex.Directory, artifact.Filename)
|
||||
reg.files[artifact.Filename] = File{id: artifact.Filename, path: artifactPath}
|
||||
}
|
||||
}
|
||||
@@ -89,112 +84,84 @@ func (reg *Registry) GetFile(id string) (*File, error) {
|
||||
return &file, nil
|
||||
} else {
|
||||
log.Errorf("updates: requested file id not found: %s", id)
|
||||
for _, file := range reg.files {
|
||||
log.Debugf("File: %s", file)
|
||||
}
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
}
|
||||
|
||||
// CheckForBinaryUpdates checks if there is a new binary bundle updates.
|
||||
func (reg *Registry) CheckForBinaryUpdates() (bool, error) {
|
||||
err := reg.binaryUpdateIndex.downloadIndexFile()
|
||||
// CheckForUpdates checks if there is a new binary bundle updates.
|
||||
func (reg *Registry) CheckForUpdates() (bool, error) {
|
||||
err := reg.updateIndex.downloadIndexFile()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
reg.binaryUpdateBundle, err = parseBundle(reg.binaryUpdateIndex.DownloadDirectory, reg.binaryUpdateIndex.IndexFile)
|
||||
reg.updateBundle, err = parseBundle(reg.updateIndex.DownloadDirectory, reg.updateIndex.IndexFile)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to parse bundle file: %w", err)
|
||||
return false, err
|
||||
}
|
||||
|
||||
// TODO(vladimir): Make a better check.
|
||||
if reg.binaryBundle.Version != reg.binaryUpdateBundle.Version {
|
||||
if reg.bundle.Version != reg.updateBundle.Version {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// DownloadBinaryUpdates downloads available binary updates.
|
||||
func (reg *Registry) DownloadBinaryUpdates() error {
|
||||
if reg.binaryUpdateBundle == nil {
|
||||
// DownloadUpdates downloads available binary updates.
|
||||
func (reg *Registry) DownloadUpdates() error {
|
||||
if reg.updateBundle == nil {
|
||||
// CheckForBinaryUpdates needs to be called before this.
|
||||
return fmt.Errorf("no valid update bundle found")
|
||||
}
|
||||
_ = deleteUnfinishedDownloads(reg.binaryBundle.dir)
|
||||
reg.binaryUpdateBundle.downloadAndVerify()
|
||||
_ = deleteUnfinishedDownloads(reg.updateIndex.DownloadDirectory)
|
||||
reg.updateBundle.downloadAndVerify(reg.updateIndex.DownloadDirectory)
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckForIntelUpdates checks if there is a new intel data bundle updates.
|
||||
func (reg *Registry) CheckForIntelUpdates() (bool, error) {
|
||||
err := reg.intelUpdateIndex.downloadIndexFile()
|
||||
// ApplyUpdates removes the current binary folder and replaces it with the downloaded one.
|
||||
func (reg *Registry) ApplyUpdates() error {
|
||||
// Create purge dir.
|
||||
err := os.MkdirAll(filepath.Dir(reg.updateIndex.PurgeDirectory), defaultDirMode)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return fmt.Errorf("failed to create directory: %w", err)
|
||||
}
|
||||
|
||||
reg.intelUpdateBundle, err = parseBundle(reg.intelUpdateIndex.DownloadDirectory, reg.intelUpdateIndex.IndexFile)
|
||||
// Read all files in the current version folder.
|
||||
files, err := os.ReadDir(reg.updateIndex.Directory)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to parse bundle file: %w", err)
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO(vladimir): Make a better check.
|
||||
if reg.intelBundle.Version != reg.intelUpdateBundle.Version {
|
||||
return true, nil
|
||||
// Move current version files into purge folder.
|
||||
for _, file := range files {
|
||||
filepath := fmt.Sprintf("%s/%s", reg.updateIndex.Directory, file.Name())
|
||||
purgePath := fmt.Sprintf("%s/%s", reg.updateIndex.PurgeDirectory, file.Name())
|
||||
err := os.Rename(filepath, purgePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to move file %s: %w", filepath, err)
|
||||
}
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// DownloadIntelUpdates downloads available intel data updates.
|
||||
func (reg *Registry) DownloadIntelUpdates() error {
|
||||
if reg.intelUpdateBundle == nil {
|
||||
// CheckForIntelUpdates needs to be called before this.
|
||||
return fmt.Errorf("no valid update bundle found")
|
||||
}
|
||||
_ = deleteUnfinishedDownloads(reg.intelBundle.dir)
|
||||
reg.intelUpdateBundle.downloadAndVerify()
|
||||
return nil
|
||||
}
|
||||
|
||||
// ApplyBinaryUpdates removes the current binary folder and replaces it with the downloaded one.
|
||||
func (reg *Registry) ApplyBinaryUpdates() error {
|
||||
bundle, err := parseBundle(reg.binaryUpdateIndex.DownloadDirectory, reg.binaryUpdateIndex.IndexFile)
|
||||
// Move the new index file
|
||||
indexFile := fmt.Sprintf("%s/%s", reg.updateIndex.DownloadDirectory, reg.updateIndex.IndexFile)
|
||||
newIndexFile := fmt.Sprintf("%s/%s", reg.updateIndex.Directory, reg.updateIndex.IndexFile)
|
||||
err = os.Rename(indexFile, newIndexFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse index file: %w", err)
|
||||
}
|
||||
err = bundle.Verify()
|
||||
if err != nil {
|
||||
return fmt.Errorf("binary bundle is not valid: %w", err)
|
||||
return fmt.Errorf("failed to move index file %s: %w", indexFile, err)
|
||||
}
|
||||
|
||||
err = os.RemoveAll(reg.binaryUpdateIndex.Directory)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to remove dir: %w", err)
|
||||
}
|
||||
err = os.Rename(reg.binaryUpdateIndex.DownloadDirectory, reg.binaryUpdateIndex.Directory)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to move dir: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ApplyIntelUpdates removes the current intel folder and replaces it with the downloaded one.
|
||||
func (reg *Registry) ApplyIntelUpdates() error {
|
||||
bundle, err := parseBundle(reg.intelUpdateIndex.DownloadDirectory, reg.intelUpdateIndex.IndexFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse index file: %w", err)
|
||||
}
|
||||
err = bundle.Verify()
|
||||
if err != nil {
|
||||
return fmt.Errorf("binary bundle is not valid: %w", err)
|
||||
}
|
||||
|
||||
err = os.RemoveAll(reg.intelUpdateIndex.Directory)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to remove dir: %w", err)
|
||||
}
|
||||
err = os.Rename(reg.intelUpdateIndex.DownloadDirectory, reg.intelUpdateIndex.Directory)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to move dir: %w", err)
|
||||
// Move downloaded files to the current version folder.
|
||||
for _, artifact := range reg.bundle.Artifacts {
|
||||
fromFilepath := fmt.Sprintf("%s/%s", reg.updateIndex.DownloadDirectory, artifact.Filename)
|
||||
toFilepath := fmt.Sprintf("%s/%s", reg.updateIndex.Directory, artifact.Filename)
|
||||
err = os.Rename(fromFilepath, toFilepath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to move file %s: %w", fromFilepath, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -220,8 +187,6 @@ func parseBundle(dir string, indexFile string) (*Bundle, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bundle.dir = dir
|
||||
|
||||
return &bundle, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
package updates
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/tevino/abool"
|
||||
|
||||
"github.com/safing/portmaster/base/log"
|
||||
"github.com/safing/portmaster/service/mgr"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -86,50 +83,3 @@ func RestartNow() {
|
||||
restartPending.Set()
|
||||
// module.restartWorkerMgr.Go()
|
||||
}
|
||||
|
||||
func automaticRestart(w *mgr.WorkerCtx) error {
|
||||
// Check if the restart is still scheduled.
|
||||
if restartPending.IsNotSet() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Trigger restart.
|
||||
if restartTriggered.SetToIf(false, true) {
|
||||
log.Warning("updates: initiating (automatic) restart")
|
||||
|
||||
// Check if we should reboot instead.
|
||||
var rebooting bool
|
||||
if RebootOnRestart {
|
||||
// Trigger system reboot and record success.
|
||||
rebooting = triggerSystemReboot()
|
||||
if !rebooting {
|
||||
log.Warningf("updates: rebooting failed, only restarting service instead")
|
||||
}
|
||||
}
|
||||
|
||||
// Set restart exit code.
|
||||
// if !rebooting {
|
||||
// module.instance.Restart()
|
||||
// } else {
|
||||
// module.instance.Shutdown()
|
||||
// }
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func triggerSystemReboot() (success bool) {
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
err := exec.Command("systemctl", "reboot").Run()
|
||||
if err != nil {
|
||||
log.Errorf("updates: triggering reboot with systemctl failed: %s", err)
|
||||
return false
|
||||
}
|
||||
default:
|
||||
log.Warningf("updates: rebooting is not support on %s", runtime.GOOS)
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user