]> git.example.dev Git - binbsis50-sm.git/commitdiff
perhaps jank server restart implemented
author2weiEmu <saalbach.robert@outlook.de>
Thu, 21 May 2026 14:34:38 +0000 (16:34 +0200)
committer2weiEmu <saalbach.robert@outlook.de>
Thu, 21 May 2026 14:34:38 +0000 (16:34 +0200)
Makefile
main.go
pkg/dbhandling/dbhandling.go
pkg/dbhandling/filesapi_test.go
pkg/dbhandling/roomsapi_test.go
pkg/dbhandling/songsapi.go
pkg/dbhandling/songsapi_test.go

index 283906dd85cfa1aecbed6683e78f65e8ff4bf5ea..136085f592e8709cb8e24cf8173a6dab6ca40c21 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ default: .
        python3 ./testing/dummy_testing_data.py
        # now we can run the main app with the right arguments
        go build .
-       ./songmanager -port 8000 -binb_location="" -songs_location="./testing/songs/" -redis_location="localhost:6379" -container_name=""
+       sudo ./songmanager -port 8000 -binb_location="" -songs_location="./testing/songs/" -redis_location="localhost:6379" -container_name="sis50binb:latest"
 
 test:
        sudo docker stop redis || true
diff --git a/main.go b/main.go
index cbdb269949024030c417e92627ef8d2e63d68cbd..b81cb5ff2e34b817de5a3873a405c46b0e9891f0 100644 (file)
--- a/main.go
+++ b/main.go
@@ -39,7 +39,7 @@ func main() {
        mainLogger.Println("Given container_name:", *paramContainerName)
        
 
-       DBwrapper := dbhandling.NewDbWrapper(*paramRedisLocation, *paramSongsLocation)
+       DBwrapper := dbhandling.NewDbWrapper(*paramRedisLocation, *paramSongsLocation, *paramContainerName, *paramBinbLocation)
 
 
        // Setting up the routing
@@ -71,6 +71,8 @@ func main() {
        mux.HandleFunc("DELETE /api/files/delete/{name}", DBwrapper.FilesDeleteByName)
        mux.HandleFunc("PUT /api/files/rename/{name}/{newname}", DBwrapper.FilesRenameByName)
 
+       mux.HandleFunc("GET /rebootapp", DBwrapper.SongsRestart)
+
        listenPort := ":" + strconv.Itoa(*paramPort)
 
        fmt.Println("Starting server...")
index f45c69e68da6e61516c228d97afe28935e39c1ac..1b6e1f11cc00716d8c1115252de3991b2678b988 100644 (file)
@@ -44,9 +44,11 @@ type DBWrapper struct {
        RedisDb *redis.Client
        Ctx context.Context
        PathToSongs string
+       ImageName string
+       BinbLocation string
 }
 
-func NewDbWrapper(redisLocation string, songsLocation string) DBWrapper {
+func NewDbWrapper(redisLocation string, songsLocation string, imageName string, binbLocation string) DBWrapper {
        return DBWrapper {
                redis.NewClient(&redis.Options{
                        Addr: redisLocation,
@@ -56,6 +58,8 @@ func NewDbWrapper(redisLocation string, songsLocation string) DBWrapper {
                }),
                context.Background(),
                songsLocation,
+               imageName,
+               binbLocation,
        }
 }
 
index bee9ba9e00d37e9a4700c314f9b8e5a516ba1be7..6e13d2542880ca24c72c41471f3ca55da99482e3 100644 (file)
@@ -9,7 +9,7 @@ import (
 )
 
 func TestFilesGet(t *testing.T) {
-       wrapper := dbhandling.NewDbWrapper("localhost:6379", "../../testing/songs")
+       wrapper := dbhandling.NewDbWrapper("localhost:6379", "../../testing/songs", "", "")
 
        t.Run("FilesGet1", func(t *testing.T) {
                req := httptest.NewRequest(http.MethodGet, "/api/files/get", &EmptyReader{})
index e21ef742e33a2907ff9797e7fef261e32ecb91b6..a16ad42ce801b342ff9b692398737d09ea762d27 100644 (file)
@@ -14,7 +14,7 @@ import (
 
 func TestRoomsGet(t *testing.T) {
        r := httptest.NewRequest("GET", "/api/rooms/get/all", &EmptyReader{})
-       wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs")
+       wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs", "", "")
 
        // subtests
        t.Run("RoomsGet1", func(t *testing.T) {
@@ -34,7 +34,7 @@ func TestRoomsGet(t *testing.T) {
 }
 
 func TestRoomsGetByName(t *testing.T) {
-       wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs")
+       wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs", "", "")
 
        // subtests
        t.Run("RoomsGet1", func(t *testing.T) {
@@ -107,7 +107,7 @@ func (a *testAddReader) Read(p []byte) (int, error) {
 }
 
 func TestRoomsAddByNameAndId(t *testing.T) {
-       wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs")
+       wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs", "", "")
 
        t.Run("RoomsAddByNameAndId1", func(t *testing.T) {
                r := httptest.NewRequest(http.MethodPut, "/api/rooms/add/hits", &testAddReader{})
@@ -158,7 +158,7 @@ func (r *testRemoveReader) Read(p []byte) (int, error) {
 }
 
 func TestRoomsRemoveByNameAndId(t *testing.T) {
-       wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs")
+       wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs", "", "")
 
        t.Run("RoomsRemoveByNameAndId1", func(t *testing.T) {
                r := httptest.NewRequest(http.MethodPut, "/api/rooms/remove/hits", &testRemoveReader{})
@@ -194,7 +194,7 @@ func TestRoomsRemoveByNameAndId(t *testing.T) {
 }
 
 func TestRoomsDeleteByName(t *testing.T) {
-       wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs")
+       wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs", "", "")
 
        t.Run("RoomsDeleteByName-1", func(t *testing.T) { 
                r := httptest.NewRequest(http.MethodDelete, "/api/rooms/delete/rock", &EmptyReader{})
index 60e2ee0a220c1314ec3a33a38c677a8ba53aedfb..657a7532b8ed4b31ceca95bde6a1f4384aed4ab5 100644 (file)
@@ -3,6 +3,7 @@ package dbhandling
 import (
        "encoding/json"
        "net/http"
+       "os/exec"
        "strconv"
 )
 
@@ -214,3 +215,46 @@ func (dbw *DBWrapper) SongsDeleteById(w http.ResponseWriter, r *http.Request) {
        w.WriteHeader(http.StatusOK)
 
 }
+
+/**
+ * Function that will restart the main server that this song manager manges
+ * so that rooms etc. will all get updated
+ **/ 
+func (dbw *DBWrapper) SongsRestart(w http.ResponseWriter, r *http.Request) {
+       // ok to make this work, we have to do it as follows:
+       // we have to stop the container, and get rid of it
+       // then re-run the image.
+
+       // for that we have to know the name of the image (ik it says container name in the thing)
+
+       // sudo docker ps -aqf ancestor=sis50binb:latest // GET THE ID
+       // sudo docker stop $ID
+       // sudo docker rm $ID
+       // ./launch.sh // this might always be present
+       out, err := exec.Command("/bin/sh", "-c", "sudo docker ps -aqf ancestor=sis50binb:latest").Output()
+       if err != nil {
+               w.WriteHeader(http.StatusInternalServerError)
+               return
+       }
+
+       id := string(out)
+       err = exec.Command("/bin/sh", "-c", "sudo docker stop", id).Run()
+       if err != nil {
+               w.WriteHeader(http.StatusInternalServerError)
+               return
+       }
+       err = exec.Command("/bin/sh", "-c", "sudo docker rm", id).Run()
+       if err != nil {
+               w.WriteHeader(http.StatusInternalServerError)
+               return
+       }
+
+       err = exec.Command("/bin/sh", "-c", "sudo", dbw.BinbLocation + "./launch.sh").Run()
+       if err != nil {
+               w.WriteHeader(http.StatusInternalServerError)
+               return
+       }
+
+       w.WriteHeader(http.StatusOK)
+
+}
index 7108c428f3360bda078ddc3ab785adbd6ee6d7c3..6ef3ef557e38dbd21937fbd6fd403039835e9cf4 100644 (file)
@@ -44,7 +44,7 @@ func (c *CreateReader) Read(p []byte) (int, error) {
 func TestGetSongs(t *testing.T) {
        // setup some fake requests
        r := httptest.NewRequest("GET", "/api/songs/get", &EmptyReader{})
-       wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs")
+       wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs", "", "")
 
        // subtests
        t.Run("SongsGet1", func(t *testing.T) {
@@ -67,7 +67,7 @@ func TestGetSongs(t *testing.T) {
 func TestSongsCreate(t *testing.T) {
        // setup fake requests and readers
        r := httptest.NewRequest("POST", "/api/songs/create", &CreateReader{})
-       wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs")
+       wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs", "", "")
 
        t.Run("SongsCreate1", func(t *testing.T) {
                recorder := httptest.NewRecorder()