Browse Source

adding self-destruct endpoint for restarting the server from admin panel

develop
forest 2 months ago
parent
commit
5e5c7782ff
2 changed files with 21 additions and 0 deletions
  1. +18
    -0
      controllers/admin/disconnect.go
  2. +3
    -0
      router/router.go

+ 18
- 0
controllers/admin/disconnect.go View File

@ -1,7 +1,10 @@
package admin
import (
"log"
"net/http"
"os"
"time"
"github.com/owncast/owncast/controllers"
"github.com/owncast/owncast/core"
@ -19,3 +22,18 @@ func DisconnectInboundConnection(w http.ResponseWriter, r *http.Request) {
rtmp.Disconnect()
controllers.WriteSimpleResponse(w, true, "inbound stream disconnected")
}
// SelfDestruct will end the owncast process.
// Hopefully it's set up with a linux service or as an auto-restarting docker container!
func SelfDestruct(w http.ResponseWriter, r *http.Request) {
log.Println("Self-destruct initiated by admin panel. Disconnecting and exiting process in 1 second...")
rtmp.Disconnect()
core.SetStreamAsDisconnected()
go (func() {
time.Sleep(1)
log.Println("Byeeeeee 👋")
os.Exit(0)
})()
w.WriteHeader(http.StatusOK)
}

+ 3
- 0
router/router.go View File

@ -75,6 +75,9 @@ func Start() error {
// Disconnect inbound stream
http.HandleFunc("/api/admin/disconnect", middleware.RequireAdminAuth(admin.DisconnectInboundConnection))
// End the owncast process.
http.HandleFunc("/api/admin/selfdestruct", middleware.RequireAdminAuth(admin.SelfDestruct))
// Server config
http.HandleFunc("/api/admin/serverconfig", middleware.RequireAdminAuth(admin.GetServerConfig))


Loading…
Cancel
Save