在文件更改时自动重新启动服务器

问题描述 投票:0回答:1

我想运行一个简单的http服务器(阻止命令),并在Linux上更改指定文件时使其自动重新启动。像这样的东西:

hotreload -w src/ -w index.html simple-http-server

当目录src或文件index.html更改时重新启动命令。

Linux是否有类似这样的命令?我只发现了npm和非常低的级别inotify API的扩展名。

linux web-services command hot-reload
1个回答
0
投票

cargo watch实际上是Rust构建工具商品的插件,但是它可以监视任何文件并运行shell命令:

cargo watch

cargo watch -w src/ -w index.html -s "./start_server.sh &" 脚本应包含以下内容:

start_server.sh

因为当服务器仍在后台运行时,新实例将无法访问端口。

这将运行用kill $(pidof simple-http-server) # kill any running instances to free up port simple-http-server 指定的命令,并在用-s "…"监视的任何文件或目录发生更改时将重新运行它。

© www.soinside.com 2019 - 2024. All rights reserved.