Change default config location (again); support auto-locating and moving old configs

This commit is contained in:
Dane Everitt
2020-05-09 15:37:49 -07:00
parent 483b652087
commit fd83424ee2
3 changed files with 94 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ package cmd
import (
"crypto/tls"
"fmt"
"github.com/mitchellh/colorstring"
"net/http"
"os"
"path"
@@ -62,11 +63,22 @@ func readConfiguration() (*config.Configuration, error) {
}
func rootCmdRun(*cobra.Command, []string) {
// Profile wings in production!!!!
if shouldRunProfiler {
defer profile.Start().Stop()
}
// Only attempt configuration file relocation if a custom location has not
// been specified in the command startup.
if configPath == config.DefaultLocation {
if err := RelocateConfiguration(); err != nil {
if os.IsNotExist(err) {
exitWithConfigurationNotice()
}
panic(err)
}
}
c, err := readConfiguration()
if err != nil {
panic(err)
@@ -259,3 +271,23 @@ func printLogo() {
fmt.Println(`Copyright © 2018 - 2020 Dane Everitt & Contributors`)
fmt.Println()
}
func exitWithConfigurationNotice() {
fmt.Print(colorstring.Color(`
[_red_][white][bold]Error: Configuration File Not Found[reset]
Wings was not able to locate your configuration file, and therefore is not
able to complete its boot process.
Please ensure you have copied your instance configuration file into
the default location, or have provided the --config flag to use a
custom location.
Default Location: /etc/pterodactyl/config.yml
[yellow]This is not a bug with this software. Please do not make a bug report
for this issue, it will be closed.[reset]
`))
os.Exit(1)
}