Cleanup data storage locations for daemon
This commit is contained in:
@@ -22,6 +22,7 @@ var (
|
||||
configureArgs struct {
|
||||
PanelURL string
|
||||
Token string
|
||||
ConfigPath string
|
||||
Node string
|
||||
Override bool
|
||||
AllowInsecure bool
|
||||
@@ -40,6 +41,7 @@ func init() {
|
||||
configureCmd.PersistentFlags().StringVarP(&configureArgs.PanelURL, "panel-url", "p", "", "The base URL for this daemon's panel")
|
||||
configureCmd.PersistentFlags().StringVarP(&configureArgs.Token, "token", "t", "", "The API key to use for fetching node information")
|
||||
configureCmd.PersistentFlags().StringVarP(&configureArgs.Node, "node", "n", "", "The ID of the node which will be connected to this daemon")
|
||||
configureCmd.PersistentFlags().StringVarP(&configureArgs.ConfigPath, "config-path", "c", config.DefaultLocation, "The path where the configuration file should be made")
|
||||
configureCmd.PersistentFlags().BoolVar(&configureArgs.Override, "override", false, "Set to true to override an existing configuration for this node")
|
||||
configureCmd.PersistentFlags().BoolVar(&configureArgs.AllowInsecure, "allow-insecure", false, "Set to true to disable certificate checking")
|
||||
}
|
||||
@@ -51,7 +53,7 @@ func configureCmdRun(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := os.Stat("config.yml"); err == nil && !configureArgs.Override {
|
||||
if _, err := os.Stat(configureArgs.ConfigPath); err == nil && !configureArgs.Override {
|
||||
survey.AskOne(&survey.Confirm{Message: "Override existing configuration file"}, &configureArgs.Override)
|
||||
if !configureArgs.Override {
|
||||
fmt.Println("Aborting process; a configuration file already exists for this node.")
|
||||
|
||||
34
cmd/root.go
34
cmd/root.go
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user