Add configurable ArchiveDirectory

This commit is contained in:
Matthew Penner 2020-04-04 00:17:32 -06:00
parent 3dba11ac6f
commit c096d8802f
4 changed files with 32 additions and 5 deletions

View File

@ -66,6 +66,9 @@ type SystemConfiguration struct {
// Directory where the server data is stored at.
Data string `default:"/srv/daemon-data" yaml:"data"`
// Directory where server archives for transferring will be stored.
ArchiveDirectory string `default:"/srv/daemon-data/.archives" yaml:"archive_directory"`
// The user that should own all of the server files, and be used for containers.
Username string `default:"pterodactyl" yaml:"username"`

View File

@ -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())
}

View File

@ -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)

View File

@ -144,6 +144,11 @@ func main() {
sftp.Initialize(c)
}
// Ensure the archive directory exists.
if err := os.MkdirAll(c.System.ArchiveDirectory, 0755); err != nil {
zap.S().Errorw("failed to create archive directory", zap.Error(err))
}
r := &Router{
token: c.AuthenticationToken,
upgrader: websocket.Upgrader{