Correctly handle migrations to a VHD setup
This commit is contained in:
parent
265f8a6b39
commit
d8a7bf2dde
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
|
@ -32,7 +31,7 @@ func newMigrateVHDCommand() *cobra.Command {
|
||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
client := remote.NewFromConfig(config.Get())
|
client := remote.NewFromConfig(config.Get())
|
||||||
manager, err := server.NewManager(cmd.Context(), client)
|
manager, err := server.NewManager(cmd.Context(), client, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithField("error", err).Fatal("failed to create new server manager")
|
log.WithField("error", err).Fatal("failed to create new server manager")
|
||||||
}
|
}
|
||||||
|
@ -48,11 +47,6 @@ func newMigrateVHDCommand() *cobra.Command {
|
||||||
|
|
||||||
// Run executes the migration command.
|
// Run executes the migration command.
|
||||||
func (m *MigrateVHDCommand) Run(ctx context.Context) error {
|
func (m *MigrateVHDCommand) Run(ctx context.Context) error {
|
||||||
root := filepath.Join(config.Get().System.Data, ".disks")
|
|
||||||
if err := os.MkdirAll(root, 0600); err != nil {
|
|
||||||
return errors.Wrap(err, "failed to create root directory for virtual disks")
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, s := range m.manager.All() {
|
for _, s := range m.manager.All() {
|
||||||
s.Log().Debug("starting migration of server contents to virtual disk...")
|
s.Log().Debug("starting migration of server contents to virtual disk...")
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,7 @@ func rootCmdRun(cmd *cobra.Command, _ []string) {
|
||||||
log.WithField("error", err).Fatal("failed to initialize database")
|
log.WithField("error", err).Fatal("failed to initialize database")
|
||||||
}
|
}
|
||||||
|
|
||||||
manager, err := server.NewManager(cmd.Context(), pclient)
|
manager, err := server.NewManager(cmd.Context(), pclient, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithField("error", err).Fatal("failed to load server configurations")
|
log.WithField("error", err).Fatal("failed to load server configurations")
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
|
@ -182,6 +183,10 @@ func (d *Disk) Allocate(ctx context.Context) error {
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return errors.Wrap(err, "vhd: failed to check for existence of root disk")
|
return errors.Wrap(err, "vhd: failed to check for existence of root disk")
|
||||||
}
|
}
|
||||||
|
trim := path.Base(d.diskPath)
|
||||||
|
if err := os.MkdirAll(strings.TrimSuffix(d.diskPath, trim), 0600); err != nil {
|
||||||
|
return errors.Wrap(err, "vhd: failed to create base vhd disk directory")
|
||||||
|
}
|
||||||
// We use 1024 as the multiplier for all of the disk space logic within the
|
// We use 1024 as the multiplier for all of the disk space logic within the
|
||||||
// application. Passing "K" (/1024) is the same as "KiB" for fallocate, but
|
// application. Passing "K" (/1024) is the same as "KiB" for fallocate, but
|
||||||
// is different than "KB" (/1000).
|
// is different than "KB" (/1000).
|
||||||
|
|
|
@ -22,16 +22,18 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Manager struct {
|
type Manager struct {
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
client remote.Client
|
client remote.Client
|
||||||
servers []*Server
|
skipVhdInitialization bool
|
||||||
|
servers []*Server
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewManager returns a new server manager instance. This will boot up all the
|
// NewManager returns a new server manager instance. This will boot up all the
|
||||||
// servers that are currently present on the filesystem and set them into the
|
// servers that are currently present on the filesystem and set them into the
|
||||||
// manager.
|
// manager.
|
||||||
func NewManager(ctx context.Context, client remote.Client) (*Manager, error) {
|
func NewManager(ctx context.Context, client remote.Client, skipVhdInit bool) (*Manager, error) {
|
||||||
m := NewEmptyManager(client)
|
m := NewEmptyManager(client)
|
||||||
|
m.skipVhdInitialization = skipVhdInit
|
||||||
if err := m.init(ctx); err != nil {
|
if err := m.init(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -198,7 +200,7 @@ func (m *Manager) InitServer(ctx context.Context, data remote.ServerConfiguratio
|
||||||
s.fs = filesystem.New(s.Id(), s.DiskSpace(), s.Config().Egg.FileDenylist)
|
s.fs = filesystem.New(s.Id(), s.DiskSpace(), s.Config().Egg.FileDenylist)
|
||||||
// If this is a virtuakl filesystem we need to go ahead and mount the disk
|
// If this is a virtuakl filesystem we need to go ahead and mount the disk
|
||||||
// so that everything is accessible.
|
// so that everything is accessible.
|
||||||
if s.fs.IsVirtual() {
|
if s.fs.IsVirtual() && !m.skipVhdInitialization {
|
||||||
log.WithField("server", s.Id()).Info("mounting virtual disk for server")
|
log.WithField("server", s.Id()).Info("mounting virtual disk for server")
|
||||||
if err := s.fs.MountDisk(ctx); err != nil {
|
if err := s.fs.MountDisk(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue
Block a user