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-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
|
|
|
|
2022-01-31 22:23:50 +01: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")
|
2022-11-29 06:32:11 +01:00
|
|
|
newAdminPassword = flag.String("adminpassword", "", "Set your admin password")
|
|
|
|
newStreamKey = flag.String("streamkey", "", "Set a temporary stream key for this session")
|
2022-01-31 22:23:50 +01:00
|
|
|
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 10:25:28 +02:00
|
|
|
|
2021-10-25 09:38:09 +02:00
|
|
|
func main() {
|
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-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") {
|
2022-11-23 07:08:25 +01:00
|
|
|
if err := os.Mkdir("./data", 0o700); err != nil {
|
2021-06-29 19:21:00 +02:00
|
|
|
log.Fatalln("Cannot create data directory", err)
|
|
|
|
}
|
2021-04-12 04:43:29 +02:00
|
|
|
}
|
2022-12-12 17:40:43 +01:00
|
|
|
// Set up emoji directory
|
|
|
|
if err := data.SetupEmojiDirectory(); err != nil {
|
|
|
|
log.Fatalln("Cannot set up emoji directory", err)
|
|
|
|
}
|
2021-04-12 04:43:29 +02:00
|
|
|
|
2022-03-08 01:30:40 +01:00
|
|
|
// Recreate the temp dir
|
|
|
|
if utils.DoesFileExists(config.TempDir) {
|
|
|
|
err := os.RemoveAll(config.TempDir)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln("Unable to remove temp dir!")
|
|
|
|
}
|
|
|
|
}
|
2022-11-23 07:08:25 +01:00
|
|
|
if err := os.Mkdir(config.TempDir, 0o700); err != nil {
|
2022-03-08 01:30:40 +01:00
|
|
|
log.Fatalln("Unable to create temp dir!", err)
|
|
|
|
}
|
|
|
|
|
2021-07-12 02:08:51 +02:00
|
|
|
configureLogging(*enableDebugOptions, *enableVerboseLogging)
|
2021-07-20 04:22:29 +02:00
|
|
|
log.Infoln(config.GetReleaseString())
|
2021-07-12 02:08:51 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-07-09 20:16:44 +02:00
|
|
|
if err := data.SetupPersistence(config.DatabaseFilePath); err != nil {
|
2020-11-19 01:49:54 +01:00
|
|
|
log.Fatalln("failed to open database", err)
|
|
|
|
}
|
2020-10-26 16:55:31 +01:00
|
|
|
|
2021-10-25 08:09:30 +02:00
|
|
|
handleCommandLineFlags()
|
|
|
|
|
|
|
|
// starts the core
|
|
|
|
if err := core.Start(); err != nil {
|
|
|
|
log.Fatalln("failed to start the core package", err)
|
|
|
|
}
|
|
|
|
|
2022-03-07 02:26:52 +01:00
|
|
|
go metrics.Start(core.GetStatus)
|
|
|
|
|
2021-10-25 08:09:30 +02:00
|
|
|
if err := router.Start(); err != nil {
|
|
|
|
log.Fatalln("failed to start/run the router", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleCommandLineFlags() {
|
2022-11-29 06:32:11 +01:00
|
|
|
if *newAdminPassword != "" {
|
|
|
|
if err := data.SetAdminPassword(*newAdminPassword); err != nil {
|
|
|
|
log.Errorln("Error setting your admin password.", err)
|
2021-08-28 19:39:42 +02:00
|
|
|
log.Exit(1)
|
2021-02-19 08:05:52 +01:00
|
|
|
} else {
|
2022-11-29 06:32:11 +01:00
|
|
|
log.Infoln("Admin password changed")
|
2021-02-19 08:05:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-29 06:32:11 +01:00
|
|
|
if *newStreamKey != "" {
|
|
|
|
log.Println("Temporary stream key is set for this session.")
|
|
|
|
config.TemporaryStreamKey = *newStreamKey
|
|
|
|
}
|
|
|
|
|
2021-02-19 08:05:52 +01:00
|
|
|
// 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)
|
2021-07-20 08:37:06 +02:00
|
|
|
if err := data.SetHTTPPortNumber(float64(portNumber)); err != nil {
|
|
|
|
log.Errorln(err)
|
|
|
|
}
|
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)
|
2021-07-20 08:37:06 +02:00
|
|
|
if err := data.SetHTTPListenAddress(*webServerIPOverride); err != nil {
|
|
|
|
log.Errorln(err)
|
|
|
|
}
|
2021-05-25 01:13:49 +02:00
|
|
|
}
|
|
|
|
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)
|
2021-07-20 08:37:06 +02:00
|
|
|
if err := data.SetRTMPPortNumber(float64(*rtmpPortOverride)); err != nil {
|
|
|
|
log.Errorln(err)
|
|
|
|
}
|
2021-05-22 03:11:15 +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,
|
|
|
|
})
|
|
|
|
}
|