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"
|
2020-06-24 22:55:49 +03:00
|
|
|
|
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
|
|
|
|
2022-02-01 00:23:50 +03:00
|
|
|
var (
|
|
|
|
dbFile = flag.String("database", "", "Path to the database file.")
|
|
|
|
logDirectory = flag.String("logdir", "", "Directory where logs will be written to")
|
|
|
|
backupDirectory = flag.String("backupdir", "", "Directory where backups will be written to")
|
|
|
|
enableDebugOptions = flag.Bool("enableDebugFeatures", false, "Enable additional debugging options.")
|
|
|
|
enableVerboseLogging = flag.Bool("enableVerboseLogging", false, "Enable additional logging.")
|
|
|
|
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")
|
|
|
|
webServerIPOverride = flag.String("webserverip", "", "Force web server to listen on this IP address")
|
|
|
|
rtmpPortOverride = flag.Int("rtmpport", 0, "Set listen port for the RTMP server")
|
|
|
|
)
|
2020-06-25 11:25:28 +03:00
|
|
|
|
2021-10-25 10:38:09 +03:00
|
|
|
func main() {
|
2020-06-25 11:19:08 +03:00
|
|
|
flag.Parse()
|
2020-06-11 23:33:20 +03:00
|
|
|
|
2021-05-23 02:29:49 +03:00
|
|
|
if *logDirectory != "" {
|
|
|
|
config.LogDirectory = *logDirectory
|
|
|
|
}
|
|
|
|
|
2021-06-14 01:28:59 +03:00
|
|
|
if *backupDirectory != "" {
|
|
|
|
config.BackupDirectory = *backupDirectory
|
|
|
|
}
|
|
|
|
|
2021-04-12 05:43:29 +03:00
|
|
|
// Create the data directory if needed
|
|
|
|
if !utils.DoesFileExists("data") {
|
2021-06-29 20:21:00 +03:00
|
|
|
if err := os.Mkdir("./data", 0700); err != nil {
|
|
|
|
log.Fatalln("Cannot create data directory", err)
|
|
|
|
}
|
2021-04-12 05:43:29 +03:00
|
|
|
}
|
|
|
|
|
2021-07-12 03:08:51 +03:00
|
|
|
configureLogging(*enableDebugOptions, *enableVerboseLogging)
|
2021-07-20 05:22:29 +03:00
|
|
|
log.Infoln(config.GetReleaseString())
|
2021-07-12 03:08:51 +03:00
|
|
|
|
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-07-09 21:16:44 +03:00
|
|
|
if err := data.SetupPersistence(config.DatabaseFilePath); err != nil {
|
2020-11-19 03:49:54 +03:00
|
|
|
log.Fatalln("failed to open database", err)
|
|
|
|
}
|
2020-10-26 18:55:31 +03:00
|
|
|
|
2021-10-25 09:09:30 +03:00
|
|
|
handleCommandLineFlags()
|
|
|
|
|
|
|
|
// starts the core
|
|
|
|
if err := core.Start(); err != nil {
|
|
|
|
log.Fatalln("failed to start the core package", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := router.Start(); err != nil {
|
|
|
|
log.Fatalln("failed to start/run the router", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleCommandLineFlags() {
|
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)
|
2021-08-28 20:39:42 +03:00
|
|
|
log.Exit(1)
|
2021-02-19 10:05:52 +03:00
|
|
|
} else {
|
2022-02-01 00:23:50 +03:00
|
|
|
log.Infoln("Stream key changed")
|
2021-02-19 10:05:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
2021-07-20 09:37:06 +03:00
|
|
|
if err := data.SetHTTPPortNumber(float64(portNumber)); err != nil {
|
|
|
|
log.Errorln(err)
|
|
|
|
}
|
2021-02-19 10:05:52 +03:00
|
|
|
}
|
2021-03-28 03:37:08 +03:00
|
|
|
config.WebServerPort = data.GetHTTPPortNumber()
|
|
|
|
|
2021-05-25 02:13:49 +03:00
|
|
|
// Set the web server ip
|
|
|
|
if *webServerIPOverride != "" {
|
|
|
|
log.Println("Saving new web server listen IP address to", *webServerIPOverride)
|
2021-07-20 09:37:06 +03:00
|
|
|
if err := data.SetHTTPListenAddress(*webServerIPOverride); err != nil {
|
|
|
|
log.Errorln(err)
|
|
|
|
}
|
2021-05-25 02:13:49 +03:00
|
|
|
}
|
|
|
|
config.WebServerIP = data.GetHTTPListenAddress()
|
|
|
|
|
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)
|
2021-07-20 09:37:06 +03:00
|
|
|
if err := data.SetRTMPPortNumber(float64(*rtmpPortOverride)); err != nil {
|
|
|
|
log.Errorln(err)
|
|
|
|
}
|
2021-05-22 04:11:15 +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,
|
|
|
|
})
|
|
|
|
}
|