2018-02-20 19:33:32 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"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"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
2018-02-20 20:00:09 +00:00
|
|
|
var configPath string
|
2018-02-20 19:33:32 +00:00
|
|
|
var RootCommand = &cobra.Command{
|
|
|
|
Use: "wings",
|
2018-02-20 20:00:09 +00:00
|
|
|
Short: "Wings is the next generation server control daemon for Pterodactyl",
|
|
|
|
Long: "Wings is the next generation server control daemon for Pterodactyl",
|
2018-02-20 19:33:32 +00:00
|
|
|
Run: run,
|
|
|
|
}
|
|
|
|
|
2018-02-20 20:00:09 +00:00
|
|
|
// Entrypoint of the application. Currently just boots up the cobra command
|
|
|
|
// and lets that handle everything else.
|
|
|
|
func main() {
|
2018-02-20 19:33:32 +00:00
|
|
|
RootCommand.Flags().StringVarP(&configPath, "config", "c", "./config.yml", "Allows to set the path of the configuration file.")
|
|
|
|
|
2018-02-20 20:00:09 +00:00
|
|
|
if err := RootCommand.Execute(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2018-02-20 19:33:32 +00:00
|
|
|
}
|
|
|
|
|
2018-02-20 20:00:09 +00:00
|
|
|
// Bootstraps the application and beging the process of running the API and
|
|
|
|
// server instances.
|
2018-02-20 19:33:32 +00:00
|
|
|
func run(cmd *cobra.Command, args []string) {
|
|
|
|
utils.InitLogging()
|
2018-02-20 20:00:09 +00:00
|
|
|
|
|
|
|
logrus.Info("Booting configuration file...")
|
2018-02-20 19:33:32 +00:00
|
|
|
if err := config.LoadConfiguration(configPath); err != nil {
|
2018-02-20 20:00:09 +00:00
|
|
|
logrus.WithError(err).Fatal("Could not locate a suitable config.yml file for this Daemon.")
|
2018-02-20 19:33:32 +00:00
|
|
|
}
|
2018-02-20 20:00:09 +00:00
|
|
|
|
|
|
|
logrus.Info("Configuration successfully loaded, booting application.")
|
2018-02-20 19:33:32 +00:00
|
|
|
utils.ConfigureLogging()
|
|
|
|
|
|
|
|
logrus.Info(` ____`)
|
|
|
|
logrus.Info(`__ Pterodactyl _____/___/_______ _______ ______`)
|
|
|
|
logrus.Info(`\_____\ \/\/ / / / __ / ___/`)
|
|
|
|
logrus.Info(` \___\ / / / / /_/ /___ /`)
|
|
|
|
logrus.Info(` \___/\___/___/___/___/___ /______/`)
|
|
|
|
logrus.Info(` /_______/ v` + constants.Version)
|
|
|
|
logrus.Info()
|
|
|
|
|
2018-02-20 20:00:09 +00:00
|
|
|
logrus.Info("Loading configured servers.")
|
2018-02-20 19:33:32 +00:00
|
|
|
if err := control.LoadServerConfigurations(filepath.Join(viper.GetString(config.DataPath), constants.ServersPath)); err != nil {
|
|
|
|
logrus.WithError(err).Error("Failed to load configured servers.")
|
|
|
|
}
|
2018-02-20 20:00:09 +00:00
|
|
|
|
2018-02-20 19:33:32 +00:00
|
|
|
if amount := len(control.GetServers()); amount == 1 {
|
2018-02-20 20:00:09 +00:00
|
|
|
logrus.Info("Found and loaded " + strconv.Itoa(amount) + " server(s).")
|
2018-02-20 19:33:32 +00:00
|
|
|
}
|
|
|
|
|
2018-02-20 20:00:09 +00:00
|
|
|
logrus.Info("Registering API server and booting.")
|
2018-02-20 21:20:57 +00:00
|
|
|
a := api.InternalAPI{}
|
2018-02-20 19:33:32 +00:00
|
|
|
a.Listen()
|
|
|
|
}
|