mirror of
https://github.com/xiaoqidun/wslkd.git
synced 2024-12-27 08:31:06 +08:00
feat(实现功能): 实现功能
This commit is contained in:
parent
bb66e73222
commit
b789cb74fb
@ -1,3 +1,7 @@
|
||||
# WslKD
|
||||
|
||||
Windows Subsystem for Linux Keep Daemon
|
||||
Windows Subsystem for Linux Keep Daemon
|
||||
|
||||
# 简要说明
|
||||
|
||||
wsl在没有使用的情况下守护进程会被关闭,本工具在指定的wsl发行版打开一个shell为wsl守护进程保活。
|
||||
|
35
wslkd.go
35
wslkd.go
@ -1,5 +1,38 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
import (
|
||||
"flag"
|
||||
"github.com/xiaoqidun/gowsl"
|
||||
"log"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var d string
|
||||
flag.StringVar(&d, "d", "Debian", "distribution")
|
||||
flag.Parsed()
|
||||
waitGroup := &sync.WaitGroup{}
|
||||
distroList := strings.Split(d, ",")
|
||||
for i := 0; i < len(distroList); i++ {
|
||||
distro := strings.TrimSpace(distroList[i])
|
||||
if distro == "" {
|
||||
continue
|
||||
}
|
||||
waitGroup.Add(1)
|
||||
go exec(waitGroup, distro)
|
||||
}
|
||||
waitGroup.Wait()
|
||||
}
|
||||
|
||||
func exec(done *sync.WaitGroup, distro string) {
|
||||
defer done.Done()
|
||||
if !gowsl.Registered(distro) {
|
||||
log.Printf("%v does not exist\n", distro)
|
||||
return
|
||||
}
|
||||
cmd := gowsl.Command(distro, "/bin/bash")
|
||||
if err := cmd.Run(); err != nil {
|
||||
log.Printf("%v cmd run err: %v", distro, err)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user