Compare commits
16 Commits
v1.15
...
v1.16.beta
Author | SHA1 | Date | |
---|---|---|---|
|
605914d1e1 | ||
|
86cf40564b | ||
|
819297118c | ||
|
a76d4cfe6c | ||
|
14ba79c2b3 | ||
|
c5f0649ab5 | ||
|
7c6f8f910b | ||
|
d07616bde9 | ||
|
4f81692954 | ||
|
588af5143f | ||
|
2d8924b7fe | ||
|
08fb7aabf8 | ||
|
9f0a51ce0e | ||
|
8a3a2d570b | ||
|
e5405f4fa9 | ||
|
9d9cce0f31 |
45
.github/workflows/go.yml
vendored
Normal file
45
.github/workflows/go.yml
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
name: Go
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: Set up Go 1.13
|
||||
uses: actions/setup-go@v1
|
||||
with:
|
||||
go-version: 1.13
|
||||
id: go
|
||||
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Get dependencies
|
||||
run: |
|
||||
export GO111MODULE=on
|
||||
go env -w GOPROXY=https://goproxy.io,direct
|
||||
go get
|
||||
|
||||
- name: Build
|
||||
run: go build
|
||||
|
||||
- name: Use
|
||||
run: |
|
||||
export PATH=/home/runner/work/fileboy/fileboy:$PATH
|
||||
fileboy version
|
||||
fileboy help
|
||||
fileboy init
|
||||
cat filegirl.yaml
|
||||
fileboy exec
|
||||
fileboy daemon
|
||||
ls -al .fileboy.pid
|
||||
ps aux | grep fileboy
|
||||
fileboy stop
|
@@ -20,7 +20,7 @@ script:
|
||||
- fileboy init
|
||||
- cat filegirl.yaml
|
||||
- fileboy exec
|
||||
- fileboy deamon
|
||||
- fileboy daemon
|
||||
- ls -al .fileboy.pid
|
||||
- ps aux | grep fileboy
|
||||
- fileboy stop
|
||||
|
15
CHANGELOG.md
15
CHANGELOG.md
@@ -1,3 +1,18 @@
|
||||
### Release v1.16
|
||||
|
||||
2020.08.23
|
||||
|
||||
- 优化 文件扫描性能
|
||||
|
||||
2020.07.19
|
||||
|
||||
- 增加 pid 文件处理
|
||||
- 增加 信息处理
|
||||
|
||||
2020.03.16
|
||||
|
||||
- typo deamon->daemon
|
||||
|
||||
### Release v1.15
|
||||
|
||||
2020.03.08
|
||||
|
@@ -1,10 +1,10 @@
|
||||
## 项目说明
|
||||
|
||||
[](https://travis-ci.org/dengsgo/fileboy) [](https://goreportcard.com/report/github.com/dengsgo/fileboy)
|
||||
 [](https://travis-ci.org/dengsgo/fileboy) [](https://goreportcard.com/report/github.com/dengsgo/fileboy)
|
||||
|
||||
[简体中文](README.md) | [ENGLISH](README_EN.md)
|
||||
|
||||
fileboy,文件变更监听通知系统,使用 Go 编写。
|
||||
fileboy,文件变更监听通知工具,使用 Go 编写。
|
||||
适用于 Hot Reload (典型的如开发go项目,无需每次手动执行 go build;又比如前端 node 打包) 或者 系统监控的场景。
|
||||
|
||||
## 特性
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
[简体中文](README.md) | [ENGLISH](README_EN.md)
|
||||
|
||||
Fileboy, File Change Monitoring Notification System, written with Go.
|
||||
Fileboy, File Change Monitoring Notification Tool Software, written with Go.
|
||||
For Hot Reload scenarios (typically for developing go projects without having to perform go build manually every time; for example, front-end node packaging) or system monitoring.
|
||||
|
||||
## FEATURES
|
||||
|
@@ -12,11 +12,11 @@ func getPidFile() string {
|
||||
return projectFolder + "/.fileboy.pid"
|
||||
}
|
||||
|
||||
func runAsDeamon() (int, error) {
|
||||
func runAsDaemon() (int, error) {
|
||||
if runtime.GOOS == "windows" {
|
||||
logAndExit("daemons mode cannot run on windows.")
|
||||
}
|
||||
err := stopDeamon()
|
||||
err := stopDaemon()
|
||||
if err != nil {
|
||||
logAndExit(err)
|
||||
}
|
||||
@@ -24,22 +24,22 @@ func runAsDeamon() (int, error) {
|
||||
if err != nil {
|
||||
logAndExit("cannot found `fileboy` command in the PATH")
|
||||
}
|
||||
deamon := exec.Command("fileboy")
|
||||
deamon.Dir = projectFolder
|
||||
deamon.Env = os.Environ()
|
||||
deamon.Stdout = os.Stdout
|
||||
err = deamon.Start()
|
||||
daemon := exec.Command("fileboy")
|
||||
daemon.Dir = projectFolder
|
||||
daemon.Env = os.Environ()
|
||||
daemon.Stdout = os.Stdout
|
||||
err = daemon.Start()
|
||||
if err != nil {
|
||||
logAndExit(err)
|
||||
}
|
||||
pid := deamon.Process.Pid
|
||||
pid := daemon.Process.Pid
|
||||
if pid != 0 {
|
||||
ioutil.WriteFile(getPidFile(), []byte(strconv.Itoa(pid)), 0644)
|
||||
}
|
||||
return pid, nil
|
||||
}
|
||||
|
||||
func stopDeamon() error {
|
||||
func stopDaemon() error {
|
||||
bs, err := ioutil.ReadFile(getPidFile())
|
||||
if err != nil {
|
||||
return nil
|
||||
@@ -48,3 +48,9 @@ func stopDeamon() error {
|
||||
os.Remove(getPidFile())
|
||||
return nil
|
||||
}
|
||||
|
||||
func stopSelf() {
|
||||
pid := os.Getpid()
|
||||
os.Remove(getPidFile())
|
||||
_ = exec.Command("kill", strconv.Itoa(pid)).Run()
|
||||
}
|
56
fileboy.go
56
fileboy.go
@@ -6,9 +6,11 @@ import (
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"gopkg.in/fsnotify/fsnotify.v1"
|
||||
@@ -111,6 +113,11 @@ func eventDispatcher(event fsnotify.Event) {
|
||||
func addWatcher() {
|
||||
logInfo("collecting directory information...")
|
||||
dirsMap := map[string]bool{}
|
||||
for _, dir := range cfg.Monitor.ExceptDirs {
|
||||
if dir == "." {
|
||||
logAndExit("exceptDirs must is not project root path ! err path:", dir)
|
||||
}
|
||||
}
|
||||
for _, dir := range cfg.Monitor.IncludeDirs {
|
||||
darr := dirParse2Array(dir)
|
||||
if len(darr) < 1 || len(darr) > 2 {
|
||||
@@ -145,16 +152,7 @@ func addWatcher() {
|
||||
}
|
||||
|
||||
}
|
||||
for _, dir := range cfg.Monitor.ExceptDirs {
|
||||
if dir == "." {
|
||||
logAndExit("exceptDirs must is not project root path ! err path:", dir)
|
||||
}
|
||||
p := projectFolder + "/" + dir
|
||||
delete(dirsMap, p)
|
||||
listFile(p, func(d string) {
|
||||
delete(dirsMap, d)
|
||||
})
|
||||
}
|
||||
|
||||
for dir := range dirsMap {
|
||||
logInfo("watcher add -> ", dir)
|
||||
err := watcher.Add(dir)
|
||||
@@ -200,6 +198,15 @@ func initWatcher() {
|
||||
}
|
||||
|
||||
func watchChangeHandler(event fsnotify.Event) {
|
||||
// stop the fileboy daemon process when the .fileboy.pid file is changed
|
||||
if event.Name == getPidFile() &&
|
||||
(event.Op == fsnotify.Remove ||
|
||||
event.Op == fsnotify.Write ||
|
||||
event.Op == fsnotify.Rename) {
|
||||
logUInfo("exit daemon process")
|
||||
stopSelf()
|
||||
return
|
||||
}
|
||||
if event.Op != fsnotify.Create && event.Op != fsnotify.Rename {
|
||||
return
|
||||
}
|
||||
@@ -213,13 +220,7 @@ func watchChangeHandler(event fsnotify.Event) {
|
||||
continue
|
||||
}
|
||||
// check exceptDirs
|
||||
has := false
|
||||
for _, v := range cfg.Monitor.ExceptDirs {
|
||||
if strings.HasPrefix(event.Name, projectFolder+"/"+v) {
|
||||
has = true
|
||||
}
|
||||
}
|
||||
if has {
|
||||
if hitDirs(event.Name, &cfg.Monitor.ExceptDirs) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -265,8 +266,8 @@ func parseArgs() {
|
||||
case len(os.Args) > 1:
|
||||
c := os.Args[1]
|
||||
switch c {
|
||||
case "deamon":
|
||||
pid, err := runAsDeamon()
|
||||
case "deamon", "daemon":
|
||||
pid, err := runAsDaemon()
|
||||
if err != nil {
|
||||
logAndExit(err)
|
||||
}
|
||||
@@ -274,7 +275,7 @@ func parseArgs() {
|
||||
logUInfo("fileboy is ready. the main process will run as a daemons")
|
||||
return
|
||||
case "stop":
|
||||
err := stopDeamon()
|
||||
err := stopDaemon()
|
||||
if err != nil {
|
||||
logAndExit(err)
|
||||
}
|
||||
@@ -310,6 +311,20 @@ func parseArgs() {
|
||||
}
|
||||
}
|
||||
|
||||
func signalHandler() {
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
go func() {
|
||||
<-c
|
||||
if taskMan != nil && taskMan.cmd != nil && taskMan.cmd.Process != nil {
|
||||
if err := taskMan.cmd.Process.Kill(); err != nil {
|
||||
logError("stopping the process failed: PID:", taskMan.cmd.ProcessState.Pid(), ":", err)
|
||||
}
|
||||
}
|
||||
os.Exit(0)
|
||||
}()
|
||||
}
|
||||
|
||||
func getFileGirlPath() string {
|
||||
return projectFolder + "/" + filegirlYamlName
|
||||
}
|
||||
@@ -332,5 +347,6 @@ func main() {
|
||||
if err != nil {
|
||||
logAndExit(err)
|
||||
}
|
||||
signalHandler()
|
||||
parseArgs()
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module fileboy
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect
|
||||
golang.org/x/sys v0.0.0-20200408040146-ea54a3c99b9b // indirect
|
||||
gopkg.in/fsnotify/fsnotify.v1 v1.4.7
|
||||
gopkg.in/yaml.v2 v2.2.8
|
||||
)
|
||||
|
2
go.sum
2
go.sum
@@ -1,5 +1,7 @@
|
||||
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
|
||||
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200408040146-ea54a3c99b9b h1:h03Ur1RlPrGTjua4koYdpGl8W0eYo8p1uI9w7RPlkdk=
|
||||
golang.org/x/sys v0.0.0-20200408040146-ea54a3c99b9b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify/fsnotify.v1 v1.4.7 h1:XNNYLJHt73EyYiCZi6+xjupS9CpvmiDgjPTAjrBlQbo=
|
||||
gopkg.in/fsnotify/fsnotify.v1 v1.4.7/go.mod h1:Fyux9zXlo4rWoMSIzpn9fDAYjalPqJ/K1qJ27s+7ltE=
|
||||
|
2
raw.go
2
raw.go
@@ -112,7 +112,7 @@ Usage of fileboy:
|
||||
初始化 fileboy, 在当前目录生成 filegirl.yaml 配置文件
|
||||
exec
|
||||
尝试运行定义的 command 命令
|
||||
deamon
|
||||
daemon
|
||||
读取当前目录下的 filegirl.yaml 配置,以守护进程的方式运行在后台
|
||||
stop
|
||||
停止守护进程
|
||||
|
BIN
resources/icon.png
Normal file
BIN
resources/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.8 KiB |
8
snapcraft.yaml
Normal file
8
snapcraft.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
name: fileboy
|
||||
vendor: dengsgo, https://github.com/dengsgo, <dengsgo@yoytang.com>
|
||||
summary: File Change Monitoring Notification Tools.
|
||||
description: File Change Monitoring Notification Tools. Please Visit https://github.com/dengsgo/fileboy
|
||||
version: 1.15
|
||||
icon: resources/icon.png
|
||||
base: core18
|
||||
grade: stable
|
13
util.go
13
util.go
@@ -53,11 +53,24 @@ func dirParse2Array(s string) []string {
|
||||
return r
|
||||
}
|
||||
|
||||
func hitDirs(d string, dirs *[]string) bool {
|
||||
d += "/"
|
||||
for _, v := range *dirs {
|
||||
if strings.HasPrefix(d, projectFolder+"/"+v+"/") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func listFile(folder string, fun func(string)) {
|
||||
files, _ := ioutil.ReadDir(folder)
|
||||
for _, file := range files {
|
||||
if file.IsDir() {
|
||||
d := folder + "/" + file.Name()
|
||||
if hitDirs(d, &cfg.Monitor.ExceptDirs) {
|
||||
continue
|
||||
}
|
||||
fun(d)
|
||||
listFile(d, fun)
|
||||
}
|
||||
|
Reference in New Issue
Block a user