2017-06-29 10:21:59 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2017-10-01 18:42:17 +00:00
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
2018-02-20 20:25:31 +00:00
|
|
|
"github.com/pterodactyl/wings/api"
|
|
|
|
"github.com/pterodactyl/wings/config"
|
|
|
|
"github.com/pterodactyl/wings/constants"
|
|
|
|
"github.com/pterodactyl/wings/control"
|
|
|
|
"github.com/pterodactyl/wings/utils"
|
2017-06-29 10:21:59 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2017-07-06 18:51:27 +00:00
|
|
|
// RootCommand is the root command of wings
|
2017-06-29 10:21:59 +00:00
|
|
|
var RootCommand = &cobra.Command{
|
2018-05-16 08:00:07 +00:00
|
|
|
Use: "wings",
|
|
|
|
Short: "Wings is the next generation server control daemon for Pterodactyl",
|
|
|
|
Long: "Wings is the next generation server control daemon for Pterodactyl",
|
|
|
|
Run: run,
|
|
|
|
Version: constants.Version,
|
2017-06-29 10:21:59 +00:00
|
|
|
}
|
|
|
|
|
2017-08-31 21:59:35 +00:00
|
|
|
var configPath string
|
2017-06-29 10:21:59 +00:00
|
|
|
|
2017-08-31 21:59:35 +00:00
|
|
|
func init() {
|
2017-09-30 22:25:04 +00:00
|
|
|
RootCommand.Flags().StringVarP(&configPath, "config", "c", "./config.yml", "Allows to set the path of the configuration file.")
|
2017-06-29 10:21:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-06 18:51:27 +00:00
|
|
|
// Execute registers the RootCommand
|
2017-06-29 10:21:59 +00:00
|
|
|
func Execute() {
|
|
|
|
RootCommand.Execute()
|
|
|
|
}
|
|
|
|
|
|
|
|
func run(cmd *cobra.Command, args []string) {
|
2017-10-09 19:01:24 +00:00
|
|
|
utils.InitLogging()
|
2017-10-01 18:42:17 +00:00
|
|
|
log.Info("Loading configuration...")
|
2017-08-31 21:59:35 +00:00
|
|
|
if err := config.LoadConfiguration(configPath); err != nil {
|
2018-05-16 08:00:07 +00:00
|
|
|
log.WithError(err).Fatal("Could not locate a suitable config.yml file. Aborting startup.")
|
|
|
|
log.Exit(1)
|
2017-06-29 10:21:59 +00:00
|
|
|
}
|
2017-10-09 19:01:24 +00:00
|
|
|
utils.ConfigureLogging()
|
2017-06-29 10:21:59 +00:00
|
|
|
|
2017-07-06 17:01:08 +00:00
|
|
|
log.Info(` ____`)
|
|
|
|
log.Info(`__ Pterodactyl _____/___/_______ _______ ______`)
|
|
|
|
log.Info(`\_____\ \/\/ / / / __ / ___/`)
|
|
|
|
log.Info(` \___\ / / / / /_/ /___ /`)
|
|
|
|
log.Info(` \___/\___/___/___/___/___ /______/`)
|
2017-07-06 18:51:27 +00:00
|
|
|
log.Info(` /_______/ v` + constants.Version)
|
2017-07-06 17:01:08 +00:00
|
|
|
log.Info()
|
2017-06-29 10:21:59 +00:00
|
|
|
|
2017-07-06 17:01:08 +00:00
|
|
|
log.Info("Configuration loaded successfully.")
|
2017-06-29 10:21:59 +00:00
|
|
|
|
2018-05-16 08:00:07 +00:00
|
|
|
log.Info("Loading configured servers.")
|
2017-10-01 18:42:17 +00:00
|
|
|
if err := control.LoadServerConfigurations(filepath.Join(viper.GetString(config.DataPath), constants.ServersPath)); err != nil {
|
|
|
|
log.WithError(err).Error("Failed to load configured servers.")
|
|
|
|
}
|
2018-05-16 08:00:07 +00:00
|
|
|
if amount := len(control.GetServers()); amount > 0 {
|
|
|
|
log.Info("Loaded " + strconv.Itoa(amount) + " server(s).")
|
2017-10-01 18:42:17 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 08:00:07 +00:00
|
|
|
log.Info("Starting API server.")
|
|
|
|
api := &api.InternalAPI{}
|
2017-06-29 10:21:59 +00:00
|
|
|
api.Listen()
|
|
|
|
}
|