mirror of
https://github.com/akyaiy/GoSally-mvp.git
synced 2026-01-07 05:52:26 +00:00
Implement automatic update functionality and improve server initialization; add NODE_PATH to Makefile, enhance logging, and update README
This commit is contained in:
45
core/init/init.go
Normal file
45
core/init/init.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package init
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func init() {
|
||||
if strings.HasPrefix(os.Args[0], "/tmp") {
|
||||
return
|
||||
}
|
||||
runPath, err := os.MkdirTemp("", "*-gs-runtime")
|
||||
log.SetOutput(os.Stderr)
|
||||
input, err := os.Open(os.Args[0])
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to init node: %s", err)
|
||||
}
|
||||
|
||||
runBinaryPath := filepath.Join(runPath, "node")
|
||||
output, err := os.Create(runBinaryPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to init node: %s", err)
|
||||
}
|
||||
|
||||
if _, err := io.Copy(output, input); err != nil {
|
||||
log.Fatalf("Failed to init node: %s", err)
|
||||
}
|
||||
|
||||
// Делаем исполняемым (на всякий случай)
|
||||
if err := os.Chmod(runBinaryPath, 0755); err != nil {
|
||||
log.Fatalf("Failed to init node: %s", err)
|
||||
}
|
||||
|
||||
input.Close()
|
||||
output.Close()
|
||||
runArgs := os.Args
|
||||
runArgs[0] = runBinaryPath
|
||||
if err := syscall.Exec(runBinaryPath, runArgs, append(os.Environ(), "GS_RUNTIME_PATH=" + runPath)); err != nil {
|
||||
log.Fatalf("Failed to init node: %s", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user