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

@@ -5,6 +5,8 @@ import (
"fmt"
"net/http"
"os"
"path"
"strings"
"github.com/pkg/errors"
"github.com/pkg/profile"
@@ -19,7 +21,7 @@ import (
"go.uber.org/zap"
)
var configPath = "config.yml"
var configPath = config.DefaultLocation
var debug = false
var shouldRunProfiler = false
@@ -31,20 +33,41 @@ var root = &cobra.Command{
}
func init() {
root.PersistentFlags().StringVar(&configPath, "config", "config.yml", "set the location for the configuration file")
root.PersistentFlags().StringVar(&configPath, "config", config.DefaultLocation, "set the location for the configuration file")
root.PersistentFlags().BoolVar(&debug, "debug", false, "pass in order to run wings in debug mode")
root.PersistentFlags().BoolVar(&shouldRunProfiler, "profile", false, "pass in order to profile wings")
root.AddCommand(configureCmd)
}
// Get the configuration path based on the arguments provided.
func readConfiguration() (*config.Configuration, error) {
var p = configPath
if !strings.HasPrefix(p, "/") {
d, err := os.Getwd()
if err != nil {
return nil, err
}
p = path.Clean(path.Join(d, configPath))
}
if s, err := os.Stat(p); err != nil {
return nil, errors.WithStack(err)
} else if s.IsDir() {
return nil, errors.New("cannot use directory as configuration file path")
}
return config.ReadConfiguration(p)
}
func rootCmdRun(*cobra.Command, []string) {
// Profile wings in production!!!!
if shouldRunProfiler {
defer profile.Start().Stop()
}
c, err := config.ReadConfiguration(configPath)
c, err := readConfiguration()
if err != nil {
panic(err)
}
@@ -71,6 +94,11 @@ func rootCmdRun(*cobra.Command, []string) {
config.Set(c)
config.SetDebugViaFlag(debug)
if err := c.System.ConfigureDirectories(); err != nil {
zap.S().Panicw("failed to configure system directories for pterodactyl", zap.Error(err))
return
}
zap.S().Infof("checking for pterodactyl system user \"%s\"", c.System.Username)
if su, err := c.EnsurePterodactylUser(); err != nil {
zap.S().Panicw("failed to create pterodactyl system user", zap.Error(err))