Skip to content

Commit

Permalink
Fix Dockerfile so beta realease will be from beta branch
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelGoerentz committed Aug 13, 2024
1 parent ea5f408 commit 0dad202
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 59 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ARG BRANCH=main

# First stage. Building a binary
# -----------------------------------------------------------------------------
FROM golang:1.22-alpine AS builder
Expand All @@ -8,7 +10,7 @@ RUN git clone https://github.com/marcelGoerentz/Threadfin.git /src

WORKDIR /src

RUN git checkout main && git pull
RUN git checkout $BRANCH && git pull
RUN go mod tidy && go mod vendor
RUN go build threadfin.go

Expand Down
20 changes: 20 additions & 0 deletions src/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,7 @@ func thirdPartyBuffer(streamID int, playlistID string, useBackup bool, backupNum
}

var cmd = exec.Command(path, args...)
//writePIDtoDisc(string(cmd.Process.Pid))

debug = fmt.Sprintf("%s:%s %s", bufferType, path, args)
showDebug(debug, 1)
Expand Down Expand Up @@ -1347,3 +1348,22 @@ func terminateProcessGracefully(cmd *exec.Cmd) {
cmd.Wait()
}
}

func writePIDtoDisc(pid string) {
// Open the file in append mode (create it if it doesn't exist)
file, err := os.OpenFile(System.Folder.Temp + "PIDs", os.O_RDWR|os.O_APPEND|os.O_CREATE, 0660)
if err != nil {
log.Fatal(err)
}
defer file.Close()

// Write your text to the file
_, err = file.WriteString(pid + "\n")
if err != nil {
log.Fatal(err)
}
}

func deletPIDfromDisc(pid string) {
log.Fatal("Nothing")
}
54 changes: 27 additions & 27 deletions src/webUI.go

Large diffs are not rendered by default.

71 changes: 40 additions & 31 deletions threadfin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package main

import (
"bytes"
"bufio"
"flag"
"fmt"
"os"
Expand Down Expand Up @@ -42,13 +42,13 @@ var GitHub = GitHubStruct{Branch: "Main", User: "marcelGoerentz", Repo: "Threadf
const Name = "Threadfin"

// Version : Version, die Build Nummer wird in der main func geparst.
const Version = "1.2.4-beta"
const Version = "1.2.5-beta"

// DBVersion : Datanbank Version
const DBVersion = "0.5.0"

// APIVersion : API Version
const APIVersion = "1.2.4-beta"
const APIVersion = "1.2.5-beta"

var homeDirectory = fmt.Sprintf("%s%s.%s%s", src.GetUserHomeDirectory(), string(os.PathSeparator), strings.ToLower(Name), string(os.PathSeparator))
var samplePath = fmt.Sprintf("%spath%sto%sthreadfin%s", string(os.PathSeparator), string(os.PathSeparator), string(os.PathSeparator), string(os.PathSeparator))
Expand Down Expand Up @@ -151,25 +151,22 @@ func main() {
// Https Webserver
system.Flag.UseHttps = *useHttps

// kill all ffmpeg and VLC processess
cmdFindFFmpeg := "pgrep -f 'ffmpeg.*Title=Threadfin'"
cmdFindVLC := "pgrep -f 'cvlc.*meta-title=Threadfin'"

// Execute the commands
ffmpegPIDs, _ := getPIDs(cmdFindFFmpeg)

vlcPIDs, _ := getPIDs(cmdFindVLC)

// Combine PIDs into one slice
allPIDs := append(ffmpegPIDs, vlcPIDs...)

// Kill all the processes by PID
for _, pid := range allPIDs {
err := killProcess(pid)
if err != nil {
fmt.Printf("Error killing process %s: %v", pid, err)
} else {
fmt.Printf("Successfully killed process %s", pid)
// Kill all remaining processes and remove PIDs file
pids, err := getPIDsFromFile(*system)
if err != nil {
fmt.Printf("Error scanning file PIDs: %v", err)
} else {
if len(pids) > 0 {
for _, pid := range pids {
err := killProcess(pid)
if err != nil {
fmt.Printf("Error killing process %s: %v", pid, err)
} else {
fmt.Printf("Successfully killed process %s", pid)
}
}
os.Remove(system.Folder.Temp + "PIDs")
}
}

Expand Down Expand Up @@ -210,7 +207,7 @@ func main() {
os.Exit(0)
}

err := src.Init()
err = src.Init()
if err != nil {
src.ShowError(err, 0)
os.Exit(0)
Expand Down Expand Up @@ -241,16 +238,28 @@ func main() {

}

func getPIDs(command string) ([]string, error) {
var out bytes.Buffer
cmd := exec.Command("bash", "-c", command)
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
return nil, err
func getPIDsFromFile(system src.SystemStruct) ([]string, error){
var err error
pids := []string{}
// Open the file
pidsFile := system.Folder.Temp + "PIDs"
_, err_stat := os.Stat(pidsFile)
if os.IsExist(err_stat) {
var file *os.File
file, err = os.Open(pidsFile)
defer file.Close() // Close the file when done

// Create a scanner
scanner := bufio.NewScanner(file)

// Read line by line
for scanner.Scan() {
line := scanner.Text()
pids = append(pids, line)
}
}
pids := strings.Fields(out.String())
return pids, nil
return pids, err

}

// killProcess kills a process by its PID
Expand Down

0 comments on commit 0dad202

Please sign in to comment.