mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-13 18:36:37 +08:00
feat: implement server self-upgrade functionality
- Added update service to fetch the latest server release from GitHub. - Implemented server upgrade scheduling and execution logic. - Created platform-specific restart mechanisms for Unix and Windows. - Introduced API endpoints for fetching the latest release and triggering upgrades. - Developed UI components for version upgrade modal, including loading and error states. - Updated documentation to reflect new upgrade features and instructions. - Refactored settings types to streamline interface definitions.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
//go:build !windows
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func replaceAndRestartServer(execPath string, tmpPath string) error {
|
||||
backupPath := execPath + ".bak"
|
||||
_ = os.Remove(backupPath)
|
||||
if err := os.Rename(execPath, backupPath); err != nil {
|
||||
_ = os.Remove(tmpPath)
|
||||
return fmt.Errorf("备份当前服务端二进制失败: %w", err)
|
||||
}
|
||||
if err := os.Rename(tmpPath, execPath); err != nil {
|
||||
_ = os.Rename(backupPath, execPath)
|
||||
return fmt.Errorf("替换服务端二进制失败: %w", err)
|
||||
}
|
||||
_ = os.Remove(backupPath)
|
||||
if err := syscall.Exec(execPath, os.Args, os.Environ()); err != nil {
|
||||
return fmt.Errorf("重启服务失败: %w", err)
|
||||
}
|
||||
return fmt.Errorf("unreachable after exec")
|
||||
}
|
||||
Reference in New Issue
Block a user