2020-05-24 03:57:49 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-06-25 11:19:08 +03:00
|
|
|
"flag"
|
2021-04-12 05:43:29 +03:00
|
|
|
"os"
|
2021-02-19 10:05:52 +03:00
|
|
|
"strconv"
|
|
|
|
"time"
|
2020-06-24 22:55:49 +03:00
|
|
|
|
2020-11-07 02:12:35 +03:00
|
|
|
"github.com/markbates/pkger"
|
2020-10-30 04:17:04 +03:00
|
|
|
"github.com/owncast/owncast/logging"
|
2020-05-24 03:57:49 +03:00
|
|
|
log "github.com/sirupsen/logrus"
|
2020-06-03 03:35:49 +03:00
|
|
|
|
2020-10-05 20:07:09 +03:00
|
|
|
"github.com/owncast/owncast/config"
|
|
|
|
"github.com/owncast/owncast/core"
|
2020-10-26 18:55:31 +03:00
|
|
|
"github.com/owncast/owncast/core/data"
|
2020-10-05 20:07:09 +03:00
|
|
|
"github.com/owncast/owncast/metrics"
|
|
|
|
"github.com/owncast/owncast/router"
|
2021-02-19 10:05:52 +03:00
|
|
|
"github.com/owncast/owncast/utils"
|
2020-06-23 04:11:56 +03:00
|
|
|
)
|
2020-05-30 04:08:33 +03:00
|
|
|
|
2020-11-13 02:14:59 +03:00
|
|
|
// the following are injected at build-time.
|
2020-06-24 22:55:49 +03:00
|
|
|
var (
|
2020-11-13 02:14:59 +03:00
|
|
|
// GitCommit is the commit which this version of owncast is running.
|
2021-02-19 10:05:52 +03:00
|
|
|
GitCommit = ""
|
2020-11-13 02:14:59 +03:00
|
|
|
// BuildVersion is the version.
|
2021-02-19 10:05:52 +03:00
|
|
|
BuildVersion = config.StaticVersionNumber
|
|
|
|
// BuildPlatform is the type of build.
|
2021-03-08 07:29:44 +03:00
|
|
|
BuildPlatform = ""
|
2020-06-24 22:55:49 +03:00
|
|
|
)
|
|
|
|
|
2020-06-01 22:15:07 +03:00
|
|
|
func main() {
|
2020-07-07 07:27:31 +03:00
|
|
|
|
2020-11-07 02:12:35 +03:00
|
|
|
// Enable bundling of admin assets
|
2020-11-15 05:39:53 +03:00
|
|
|
_ = pkger.Include("/admin")
|
2020-06-11 23:33:20 +03:00
|
|
|
|
2021-02-19 10:05:52 +03:00
|
|
|
configFile := flag.String("configFile", "config.yaml", "Config file path to migrate to the new database")
|
2020-10-26 18:55:31 +03:00
|
|
|
dbFile := flag.String("database", "", "Path to the database file.")
|
2021-05-23 02:29:49 +03:00
|
|
|
logDirectory := flag.String("logdir", "", "Directory where logs will be written to")
|
2020-06-25 11:25:28 +03:00
|
|
|
enableDebugOptions := flag.Bool("enableDebugFeatures", false, "Enable additional debugging options.")
|
2020-07-07 07:27:31 +03:00
|
|
|
enableVerboseLogging := flag.Bool("enableVerboseLogging", false, "Enable additional logging.")
|
2021-02-19 10:05:52 +03:00
|
|
|
restoreDatabaseFile := flag.String("restoreDatabase", "", "Restore an Owncast database backup")
|
|
|
|
newStreamKey := flag.String("streamkey", "", "Set your stream key/admin password")
|
|
|
|
webServerPortOverride := flag.String("webserverport", "", "Force the web server to listen on a specific port")
|
2021-05-22 04:11:15 +03:00
|
|
|
rtmpPortOverride := flag.Int("rtmpport", 0, "Set listen port for the RTMP server")
|
2020-06-25 11:25:28 +03:00
|
|
|
|
2020-06-25 11:19:08 +03:00
|
|
|
flag.Parse()
|
2020-06-11 23:33:20 +03:00
|
|
|
|
2021-02-19 10:05:52 +03:00
|
|
|
config.ConfigFilePath = *configFile
|
|
|
|
config.VersionNumber = BuildVersion
|
|
|
|
if GitCommit != "" {
|
|
|
|
config.GitCommit = GitCommit
|
|
|
|
} else {
|
|
|
|
config.GitCommit = time.Now().Format("20060102")
|
|
|
|
}
|
2021-03-16 02:58:26 +03:00
|
|
|
if BuildPlatform != "" {
|
|
|
|
config.BuildPlatform = BuildPlatform
|
|
|
|
}
|
2021-02-19 10:05:52 +03:00
|
|
|
|
2021-05-23 02:29:49 +03:00
|
|
|
if *logDirectory != "" {
|
|
|
|
config.LogDirectory = *logDirectory
|
|
|
|
}
|
|
|
|
|
2021-05-23 05:25:33 +03:00
|
|
|
configureLogging(*enableDebugOptions, *enableVerboseLogging)
|
|
|
|
log.Infoln(config.GetReleaseString())
|
|
|
|
|
2021-04-12 05:43:29 +03:00
|
|
|
// Create the data directory if needed
|
|
|
|
if !utils.DoesFileExists("data") {
|
|
|
|
os.Mkdir("./data", 0700)
|
|
|
|
}
|
|
|
|
|
2021-02-19 10:05:52 +03:00
|
|
|
// Allows a user to restore a specific database backup
|
|
|
|
if *restoreDatabaseFile != "" {
|
|
|
|
databaseFile := config.DatabaseFilePath
|
|
|
|
if *dbFile != "" {
|
|
|
|
databaseFile = *dbFile
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := utils.Restore(*restoreDatabaseFile, databaseFile); err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("Database has been restored. Restart Owncast.")
|
|
|
|
log.Exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
config.EnableDebugFeatures = *enableDebugOptions
|
2020-06-02 10:27:54 +03:00
|
|
|
|
2020-10-26 18:55:31 +03:00
|
|
|
if *dbFile != "" {
|
2021-02-19 10:05:52 +03:00
|
|
|
config.DatabaseFilePath = *dbFile
|
2020-07-16 03:20:47 +03:00
|
|
|
}
|
|
|
|
|
2020-08-27 18:50:27 +03:00
|
|
|
go metrics.Start()
|
2020-08-27 10:37:32 +03:00
|
|
|
|
2021-02-19 10:05:52 +03:00
|
|
|
err := data.SetupPersistence(config.DatabaseFilePath)
|
2020-11-19 03:49:54 +03:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln("failed to open database", err)
|
|
|
|
}
|
2020-10-26 18:55:31 +03:00
|
|
|
|
2021-02-19 10:05:52 +03:00
|
|
|
if *newStreamKey != "" {
|
|
|
|
if err := data.SetStreamKey(*newStreamKey); err != nil {
|
|
|
|
log.Errorln("Error setting your stream key.", err)
|
|
|
|
} else {
|
|
|
|
log.Infoln("Stream key changed to", *newStreamKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the web server port
|
|
|
|
if *webServerPortOverride != "" {
|
|
|
|
portNumber, err := strconv.Atoi(*webServerPortOverride)
|
|
|
|
if err != nil {
|
|
|
|
log.Warnln(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-03-28 03:37:08 +03:00
|
|
|
log.Println("Saving new web server port number to", portNumber)
|
|
|
|
data.SetHTTPPortNumber(float64(portNumber))
|
2021-02-19 10:05:52 +03:00
|
|
|
}
|
|
|
|
|
2021-03-28 03:37:08 +03:00
|
|
|
config.WebServerPort = data.GetHTTPPortNumber()
|
|
|
|
|
2021-05-22 04:11:15 +03:00
|
|
|
// Set the rtmp server port
|
|
|
|
if *rtmpPortOverride > 0 {
|
|
|
|
log.Println("Saving new RTMP server port number to", *rtmpPortOverride)
|
|
|
|
data.SetRTMPPortNumber(float64(*rtmpPortOverride))
|
|
|
|
}
|
|
|
|
|
2021-02-26 22:23:15 +03:00
|
|
|
// starts the core
|
|
|
|
if err := core.Start(); err != nil {
|
|
|
|
log.Fatalln("failed to start the core package", err)
|
|
|
|
}
|
|
|
|
|
2020-06-23 04:11:56 +03:00
|
|
|
if err := router.Start(); err != nil {
|
2020-11-15 05:39:53 +03:00
|
|
|
log.Fatalln("failed to start/run the router", err)
|
2020-06-16 02:27:58 +03:00
|
|
|
}
|
2020-11-04 04:34:25 +03:00
|
|
|
}
|
|
|
|
|
2021-05-23 05:25:33 +03:00
|
|
|
func configureLogging(enableDebugFeatures bool, enableVerboseLogging bool) {
|
|
|
|
logging.Setup(enableDebugFeatures, enableVerboseLogging)
|
2020-07-07 07:27:31 +03:00
|
|
|
log.SetFormatter(&log.TextFormatter{
|
|
|
|
FullTimestamp: true,
|
|
|
|
})
|
|
|
|
}
|