Get wings booting again

This commit is contained in:
Dane Everitt 2021-01-14 20:32:38 -08:00
parent 05c04c4350
commit c2cfaf44b5
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
3 changed files with 75 additions and 74 deletions

View File

@ -15,14 +15,15 @@ import (
"strings"
"time"
"github.com/pterodactyl/wings/environment"
"github.com/AlecAivazis/survey/v2"
"github.com/AlecAivazis/survey/v2/terminal"
"github.com/apex/log"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/parsers/kernel"
"github.com/docker/docker/pkg/parsers/operatingsystem"
"github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/environment"
"github.com/pterodactyl/wings/loggers/cli"
"github.com/pterodactyl/wings/system"
"github.com/spf13/cobra"
)
@ -40,15 +41,21 @@ var (
}
)
var diagnosticsCmd = &cobra.Command{
func newDiagnosticsCommand() *cobra.Command {
command := &cobra.Command{
Use: "diagnostics",
Short: "Collect diagnostics information.",
Short: "Collect and report information about this Wings instance to assist in debugging.",
PreRun: func(cmd *cobra.Command, args []string) {
initConfig()
log.SetHandler(cli.Default)
},
Run: diagnosticsCmdRun,
}
}
func init() {
diagnosticsCmd.PersistentFlags().StringVar(&diagnosticsArgs.HastebinURL, "hastebin-url", DefaultHastebinUrl, "The url of the hastebin instance to use.")
diagnosticsCmd.PersistentFlags().IntVar(&diagnosticsArgs.LogLines, "log-lines", DefaultLogLines, "The number of log lines to include in the report")
command.Flags().StringVar(&diagnosticsArgs.HastebinURL, "hastebin-url", DefaultHastebinUrl, "the url of the hastebin instance to use")
command.Flags().IntVar(&diagnosticsArgs.LogLines, "log-lines", DefaultLogLines, "the number of log lines to include in the report")
return command
}
// diagnosticsCmdRun collects diagnostics about wings, it's configuration and the node.
@ -85,7 +92,6 @@ func diagnosticsCmdRun(cmd *cobra.Command, args []string) {
}
dockerVersion, dockerInfo, dockerErr := getDockerInfo()
_ = dockerInfo
output := &strings.Builder{}
fmt.Fprintln(output, "Pterodactyl Wings - Diagnostics Report")
@ -102,8 +108,10 @@ func diagnosticsCmdRun(cmd *cobra.Command, args []string) {
}
printHeader(output, "Wings Configuration")
cfg, err := config.FromFile(config.DefaultLocation)
if cfg != nil {
if err := config.FromFile(config.DefaultLocation); err != nil {
}
cfg := config.Get()
fmt.Fprintln(output, " Panel Location:", redact(cfg.PanelLocation))
fmt.Fprintln(output, "")
fmt.Fprintln(output, " Internal Webserver:", redact(cfg.Api.Host), ":", cfg.Api.Port)
@ -123,11 +131,9 @@ func diagnosticsCmdRun(cmd *cobra.Command, args []string) {
fmt.Fprintln(output, " Username:", cfg.System.Username)
fmt.Fprintln(output, " Server Time:", time.Now().Format(time.RFC1123Z))
fmt.Fprintln(output, " Debug Mode:", cfg.Debug)
} else {
fmt.Println("Failed to load configuration.", err)
}
printHeader(output, "Docker: Info")
if dockerErr == nil {
fmt.Fprintln(output, "Server Version:", dockerInfo.ServerVersion)
fmt.Fprintln(output, "Storage Driver:", dockerInfo.Driver)
if dockerInfo.DriverStatus != nil {
@ -147,6 +153,9 @@ func diagnosticsCmdRun(cmd *cobra.Command, args []string) {
fmt.Fprintln(output, w)
}
}
} else {
fmt.Fprintln(output, dockerErr.Error())
}
printHeader(output, "Docker: Running Containers")
c := exec.Command("docker", "ps")
@ -180,23 +189,23 @@ func diagnosticsCmdRun(cmd *cobra.Command, args []string) {
survey.AskOne(&survey.Confirm{Message: "Upload to " + diagnosticsArgs.HastebinURL + "?", Default: false}, &upload)
}
if upload {
url, err := uploadToHastebin(diagnosticsArgs.HastebinURL, output.String())
u, err := uploadToHastebin(diagnosticsArgs.HastebinURL, output.String())
if err == nil {
fmt.Println("Your report is available here: ", url)
fmt.Println("Your report is available here: ", u)
}
}
}
func getDockerInfo() (types.Version, types.Info, error) {
cli, err := environment.Docker()
client, err := environment.Docker()
if err != nil {
return types.Version{}, types.Info{}, err
}
dockerVersion, err := cli.ServerVersion(context.Background())
dockerVersion, err := client.ServerVersion(context.Background())
if err != nil {
return types.Version{}, types.Info{}, err
}
dockerInfo, err := cli.Info(context.Background())
dockerInfo, err := client.Info(context.Background())
if err != nil {
return types.Version{}, types.Info{}, err
}

View File

@ -78,7 +78,7 @@ func init() {
rootCommand.AddCommand(versionCommand)
rootCommand.AddCommand(configureCmd)
rootCommand.AddCommand(diagnosticsCmd)
rootCommand.AddCommand(newDiagnosticsCommand())
}
func rootCmdRun(cmd *cobra.Command, _ []string) {

View File

@ -72,37 +72,29 @@ func postCreateServer(c *gin.Context) {
c.Status(http.StatusAccepted)
}
// Updates the running configuration for this daemon instance.
// Updates the running configuration for this Wings instance.
func postUpdateConfiguration(c *gin.Context) {
// A backup of the configuration for error purposes.
ccopy := *config.Get()
// A copy of the configuration we're using to bind the data received into.
cfg := *config.Get()
// BindJSON sends 400 if the request fails, all we need to do is return
cfg := config.Get()
if err := c.BindJSON(&cfg); err != nil {
return
}
// Keep the SSL certificates the same since the Panel will send through Lets Encrypt
// default locations. However, if we picked a different location manually we don't
// want to override that.
//
// If you pass through manual locations in the API call this logic will be skipped.
if strings.HasPrefix(cfg.Api.Ssl.KeyFile, "/etc/letsencrypt/live/") {
cfg.Api.Ssl.KeyFile = strings.ToLower(ccopy.Api.Ssl.KeyFile)
cfg.Api.Ssl.CertificateFile = strings.ToLower(ccopy.Api.Ssl.CertificateFile)
cfg.Api.Ssl.KeyFile = strings.ToLower(config.Get().Api.Ssl.KeyFile)
cfg.Api.Ssl.CertificateFile = strings.ToLower(config.Get().Api.Ssl.CertificateFile)
}
config.Set(&cfg)
if err := config.Get().WriteToDisk(); err != nil {
// If there was an error writing to the disk, revert back to the configuration we had
// before this code was run.
config.Set(&ccopy)
NewTrackedError(err).Abort(c)
// Try to write this new configuration to the disk before updating our global
// state with it.
if err := config.WriteToDisk(cfg); err != nil {
WithError(c, err)
return
}
// Since we wrote it to the disk successfully now update the global configuration
// state to use this new configuration struct.
config.Set(cfg)
c.Status(http.StatusNoContent)
}