mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-30 06:16:37 +08:00
6140ed1718
- 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.
28 lines
715 B
Go
28 lines
715 B
Go
//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")
|
|
}
|