Add configurable ArchiveDirectory
This commit is contained in:
@@ -18,7 +18,7 @@ type Archiver struct {
|
||||
|
||||
// ArchivePath returns the path to the server's archive.
|
||||
func (a *Archiver) ArchivePath() string {
|
||||
return filepath.Join(config.Get().System.Data, ".archives", a.ArchiveName())
|
||||
return filepath.Join(config.Get().System.ArchiveDirectory, a.ArchiveName())
|
||||
}
|
||||
|
||||
// ArchiveName returns the name of the server's archive.
|
||||
@@ -35,12 +35,12 @@ func (a *Archiver) Exists() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Stat .
|
||||
// Stat stats the archive file.
|
||||
func (a *Archiver) Stat() (*Stat, error) {
|
||||
return a.Server.Filesystem.unsafeStat(a.ArchivePath())
|
||||
}
|
||||
|
||||
// Archive creates an archive of the server.
|
||||
// Archive creates an archive of the server and deletes the previous one.
|
||||
func (a *Archiver) Archive() error {
|
||||
path := a.Server.Filesystem.Path()
|
||||
|
||||
@@ -55,6 +55,18 @@ func (a *Archiver) Archive() error {
|
||||
files = append(files, filepath.Join(path, file.Name()))
|
||||
}
|
||||
|
||||
stat, err := a.Stat()
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
// Check if the file exists.
|
||||
if stat != nil {
|
||||
if err := os.Remove(a.ArchivePath()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return archiver.NewTarGz().Archive(files, a.ArchivePath())
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"github.com/imdario/mergo"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Merges data passed through in JSON form into the existing server object.
|
||||
@@ -101,12 +100,20 @@ func (s *Server) runBackgroundActions() {
|
||||
if server.Suspended && server.State != ProcessOfflineState {
|
||||
zap.S().Infow("server suspended with running process state, terminating now", zap.String("server", server.Uuid))
|
||||
|
||||
if err := server.Environment.Terminate(os.Kill); err != nil {
|
||||
/*if err := server.Environment.Terminate(os.Kill); err != nil {
|
||||
zap.S().Warnw(
|
||||
"failed to terminate server environment after seeing suspension",
|
||||
zap.String("server", server.Uuid),
|
||||
zap.Error(err),
|
||||
)
|
||||
}*/
|
||||
|
||||
if err := server.Environment.WaitForStop(10, true); err != nil {
|
||||
zap.S().Warnw(
|
||||
"failed to stop server environment after seeing suspension",
|
||||
zap.String("server", server.Uuid),
|
||||
zap.Error(err),
|
||||
)
|
||||
}
|
||||
}
|
||||
}(s)
|
||||
|
||||
Reference in New Issue
Block a user