2020-05-24 02:57:49 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-06-25 10:19:08 +02:00
|
|
|
"flag"
|
2021-04-12 04:43:29 +02:00
|
|
|
"os"
|
2021-02-19 08:05:52 +01:00
|
|
|
"strconv"
|
2020-06-24 21:55:49 +02:00
|
|
|
|
2020-11-07 00:12:35 +01:00
|
|
|
"github.com/markbates/pkger"
|
2020-10-30 02:17:04 +01:00
|
|
|
"github.com/owncast/owncast/logging"
|
2020-05-24 02:57:49 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
2020-06-03 02:35:49 +02:00
|
|
|
|
2020-10-05 19:07:09 +02:00
|
|
|
"github.com/owncast/owncast/config"
|
|
|
|
"github.com/owncast/owncast/core"
|
2020-10-26 16:55:31 +01:00
|
|
|
"github.com/owncast/owncast/core/data"
|
2020-10-05 19:07:09 +02:00
|
|
|
"github.com/owncast/owncast/metrics"
|
|
|
|
"github.com/owncast/owncast/router"
|
2021-02-19 08:05:52 +01:00
|
|
|
"github.com/owncast/owncast/utils"
|
2020-06-23 03:11:56 +02:00
|
|
|
)
|
2020-05-30 03:08:33 +02:00
|
|
|
|
2020-06-01 21:15:07 +02:00
|
|
|
func main() {
|
2020-07-07 06:27:31 +02:00
|
|
|
|
2020-11-07 00:12:35 +01:00
|
|
|
// Enable bundling of admin assets
|
2020-11-15 03:39:53 +01:00
|
|
|
_ = pkger.Include("/admin")
|
2020-06-11 22:33:20 +02:00
|
|
|
|
2020-10-26 16:55:31 +01:00
|
|
|
dbFile := flag.String("database", "", "Path to the database file.")
|
2021-05-23 01:29:49 +02:00
|
|
|
logDirectory := flag.String("logdir", "", "Directory where logs will be written to")
|
2021-06-14 00:28:59 +02:00
|
|
|
backupDirectory := flag.String("backupdir", "", "Directory where backups will be written to")
|
2020-06-25 10:25:28 +02:00
|
|
|
enableDebugOptions := flag.Bool("enableDebugFeatures", false, "Enable additional debugging options.")
|
2020-07-07 06:27:31 +02:00
|
|
|
enableVerboseLogging := flag.Bool("enableVerboseLogging", false, "Enable additional logging.")
|
2021-02-19 08:05:52 +01: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-25 01:13:49 +02:00
|
|
|
webServerIPOverride := flag.String("webserverip", "", "Force web server to listen on this IP address")
|
2021-05-22 03:11:15 +02:00
|
|
|
rtmpPortOverride := flag.Int("rtmpport", 0, "Set listen port for the RTMP server")
|
2020-06-25 10:25:28 +02:00
|
|
|
|
2020-06-25 10:19:08 +02:00
|
|
|
flag.Parse()
|
2020-06-11 22:33:20 +02:00
|
|
|
|
2021-05-23 01:29:49 +02:00
|
|
|
if *logDirectory != "" {
|
|
|
|
config.LogDirectory = *logDirectory
|
|
|
|
}
|
|
|
|
|
2021-05-23 04:25:33 +02:00
|
|
|
configureLogging(*enableDebugOptions, *enableVerboseLogging)
|
|
|
|
log.Infoln(config.GetReleaseString())
|
|
|
|
|
2021-06-14 00:28:59 +02:00
|
|
|
if *backupDirectory != "" {
|
|
|
|
config.BackupDirectory = *backupDirectory
|
|
|
|
}
|
|
|
|
|
2021-04-12 04:43:29 +02:00
|
|
|
// Create the data directory if needed
|
|
|
|
if !utils.DoesFileExists("data") {
|
|
|
|
os.Mkdir("./data", 0700)
|
|
|
|
}
|
|
|
|
|
2021-02-19 08:05:52 +01: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 09:27:54 +02:00
|
|
|
|
2020-10-26 16:55:31 +01:00
|
|
|
if *dbFile != "" {
|
2021-02-19 08:05:52 +01:00
|
|
|
config.DatabaseFilePath = *dbFile
|
2020-07-16 02:20:47 +02:00
|
|
|
}
|
|
|
|
|
2020-08-27 17:50:27 +02:00
|
|
|
go metrics.Start()
|
2020-08-27 09:37:32 +02:00
|
|
|
|
2021-02-19 08:05:52 +01:00
|
|
|
err := data.SetupPersistence(config.DatabaseFilePath)
|
2020-11-19 01:49:54 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln("failed to open database", err)
|
|
|
|
}
|
2020-10-26 16:55:31 +01:00
|
|
|
|
2021-02-19 08:05:52 +01: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 01:37:08 +01:00
|
|
|
log.Println("Saving new web server port number to", portNumber)
|
|
|
|
data.SetHTTPPortNumber(float64(portNumber))
|
2021-02-19 08:05:52 +01:00
|
|
|
}
|
2021-03-28 01:37:08 +01:00
|
|
|
config.WebServerPort = data.GetHTTPPortNumber()
|
|
|
|
|
2021-05-25 01:13:49 +02:00
|
|
|
// Set the web server ip
|
|
|
|
if *webServerIPOverride != "" {
|
|
|
|
log.Println("Saving new web server listen IP address to", *webServerIPOverride)
|
|
|
|
data.SetHTTPListenAddress(string(*webServerIPOverride))
|
|
|
|
}
|
|
|
|
config.WebServerIP = data.GetHTTPListenAddress()
|
|
|
|
|
2021-05-22 03:11:15 +02: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 20:23:15 +01:00
|
|
|
// starts the core
|
|
|
|
if err := core.Start(); err != nil {
|
|
|
|
log.Fatalln("failed to start the core package", err)
|
|
|
|
}
|
|
|
|
|
2020-06-23 03:11:56 +02:00
|
|
|
if err := router.Start(); err != nil {
|
2020-11-15 03:39:53 +01:00
|
|
|
log.Fatalln("failed to start/run the router", err)
|
2020-06-16 01:27:58 +02:00
|
|
|
}
|
2020-11-04 02:34:25 +01:00
|
|
|
}
|
|
|
|
|
2021-05-23 04:25:33 +02:00
|
|
|
func configureLogging(enableDebugFeatures bool, enableVerboseLogging bool) {
|
|
|
|
logging.Setup(enableDebugFeatures, enableVerboseLogging)
|
2020-07-07 06:27:31 +02:00
|
|
|
log.SetFormatter(&log.TextFormatter{
|
|
|
|
FullTimestamp: true,
|
|
|
|
})
|
|
|
|
}
|