mirror of
https://github.com/qingchencloud/cftunnel.git
synced 2026-08-28 18:20:34 +08:00
a7e4cf9dff
- goreleaser 添加 windows 构建(zip 格式) - cloudflared 下载支持 Windows + macOS tgz 解压 - 进程管理跨平台(process_unix/process_windows) - 信号处理跨平台(signal_unix/signal_windows) - Windows Service 实现(sc.exe) - selfupdate 支持 Windows zip 格式 - PowerShell 安装脚本 - README 添加 Windows 安装说明
39 lines
827 B
Go
39 lines
827 B
Go
//go:build windows
|
|
|
|
package service
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
type Windows struct{}
|
|
|
|
const svcName = "cftunnel"
|
|
|
|
func (w *Windows) Install(binPath, token string) error {
|
|
binArg := fmt.Sprintf(`%s tunnel run --token %s`, binPath, token)
|
|
if err := exec.Command("sc", "create", svcName, "binPath=", binArg, "start=", "auto").Run(); err != nil {
|
|
return fmt.Errorf("创建服务失败: %w", err)
|
|
}
|
|
return exec.Command("sc", "start", svcName).Run()
|
|
}
|
|
|
|
func (w *Windows) Uninstall() error {
|
|
exec.Command("sc", "stop", svcName).Run()
|
|
return exec.Command("sc", "delete", svcName).Run()
|
|
}
|
|
|
|
func (w *Windows) Running() bool {
|
|
out, err := exec.Command("sc", "query", svcName).Output()
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return strings.Contains(string(out), "RUNNING")
|
|
}
|
|
|
|
func New() Service {
|
|
return &Windows{}
|
|
}
|