Cleanup data storage locations for daemon

This commit is contained in:
Dane Everitt
2020-04-17 14:27:06 -07:00
parent 4ff7bd2777
commit 4279fa510e
12 changed files with 180 additions and 69 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/docker/docker/client"
"github.com/pkg/errors"
"github.com/pterodactyl/wings/api"
"github.com/pterodactyl/wings/config"
"go.uber.org/zap"
"io"
"io/ioutil"
@@ -231,6 +232,11 @@ func (ip *InstallationProcess) BeforeExecute() (string, error) {
return fileName, nil
}
// Returns the log path for the installation process.
func (ip *InstallationProcess) GetLogPath() string {
return filepath.Join(config.Get().System.GetInstallLogPath(), ip.Server.Uuid+".log")
}
// Cleans up after the execution of the installation process. This grabs the logs from the
// process to store in the server configuration directory, and then destroys the associated
// installation container.
@@ -248,7 +254,7 @@ func (ip *InstallationProcess) AfterExecute(containerId string) error {
return errors.WithStack(err)
}
f, err := os.OpenFile(filepath.Join("data/install_logs/", ip.Server.Uuid+".log"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
f, err := os.OpenFile(ip.GetLogPath(), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return errors.WithStack(err)
}

View File

@@ -230,7 +230,6 @@ func FromConfiguration(data *api.ServerConfigurationResponse) (*Server, error) {
s.Resources = ResourceUsage{}
// Forces the configuration to be synced with the panel.
zap.S().Debugw("syncing config with panel", zap.String("server", s.Uuid))
if err := s.SyncWithConfiguration(data); err != nil {
return nil, err
}

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"github.com/pkg/errors"
"github.com/pterodactyl/wings/config"
"go.uber.org/zap"
"io"
"io/ioutil"
@@ -11,8 +12,6 @@ import (
"sync"
)
const stateFileLocation = "data/.states.json"
var stateMutex sync.Mutex
// Returns the state of the servers.
@@ -22,7 +21,7 @@ func getServerStates() (map[string]string, error) {
defer stateMutex.Unlock()
// Open the states file.
f, err := os.OpenFile(stateFileLocation, os.O_RDONLY|os.O_CREATE, 0644)
f, err := os.OpenFile(config.Get().System.GetStatesPath(), os.O_RDONLY|os.O_CREATE, 0644)
if err != nil {
return nil, errors.WithStack(err)
}
@@ -55,7 +54,7 @@ func saveServerStates() error {
defer stateMutex.Unlock()
// Write the data to the file
if err := ioutil.WriteFile(stateFileLocation, data, 0644); err != nil {
if err := ioutil.WriteFile(config.Get().System.GetStatesPath(), data, 0644); err != nil {
return errors.WithStack(err)
}
@@ -141,4 +140,4 @@ func (s *Server) GetState() string {
// not the response from Docker.
func (s *Server) IsRunning() bool {
return s.GetState() == ProcessRunningState || s.GetState() == ProcessStartingState
}
}

View File

@@ -52,11 +52,6 @@ func (s *Server) UpdateDataStructure(data []byte, background bool) error {
}
} else {
s.Suspended = v
if s.Suspended {
zap.S().Debugw("server has been suspended", zap.String("server", s.Uuid))
} else {
zap.S().Debugw("server has been unsuspended", zap.String("server", s.Uuid))
}
}
// Environment and Mappings should be treated as a full update at all times, never a