node update sync wip
This commit is contained in:
parent
30aa3d0238
commit
8f913eca0d
5 changed files with 189 additions and 45 deletions
52
update.go
Normal file
52
update.go
Normal file
|
@ -0,0 +1,52 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Function to check for updates and restart the server if an update is found
|
||||
func checkForUpdates() {
|
||||
repoURL := "https://weforgecode.xyz/Spitfire/Search.git"
|
||||
localDir := "." // Assume the repository is cloned in the current directory
|
||||
|
||||
for {
|
||||
err := gitPull(repoURL, localDir)
|
||||
if err != nil {
|
||||
fmt.Println("Error checking for updates:", err)
|
||||
time.Sleep(10 * time.Minute)
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Println("Update found. Syncing updates...")
|
||||
nodeUpdateSync()
|
||||
|
||||
fmt.Println("Restarting server to apply updates...")
|
||||
update()
|
||||
time.Sleep(10 * time.Minute)
|
||||
}
|
||||
}
|
||||
|
||||
// Function to pull updates from the Git repository
|
||||
func gitPull(repoURL, localDir string) error {
|
||||
cmd := exec.Command("git", "-C", localDir, "pull", repoURL)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
// Function to download updates and restart the server
|
||||
func update() {
|
||||
cmd := exec.Command("sh", "run.sh")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
fmt.Println("Error starting the server:", err)
|
||||
return
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue