个人不喜欢Qexo的Github Action方式,其本地方式又有问题,故在此给大家提供一种思路。
安装Qexo
自行阅读文档。快速开始 | Qexo 文档。以下提供本人自用的Docker run
1 2 3 4 5 6 7 8 9
| docker run -d \ --restart=unless-stopped \ -v $(pwd)/db:/app/db \ -v blog目录:/blog \ -p 127.0.0.1:40001:8000 \ -e TIMEOUT=600 \ --name="qexo" \ abudulin/qexo:latest
|
其中blog目录设置为你的blog所在目录,端口映射如果你不在意直接暴露端口则可以不用设置监听127.0.0.1,当然我使用反代将80端口反代到40001端口,方便我套CDN,也避免泄露服务器的IP。
在Qexo设置方面,参考如下

监听文件变动
安装inotify-tools
1
| sudo apt install inotify-tools
|
找一个目录放监控脚本,我放在/etc/komri/blog/blog_monitor.sh,设置脚本有可执行权限chmod -x /etc/komri/blog/blog_monitor.sh,脚本美容如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #!/bin/bash
TARGET="/etc/komari/blog/source"
if [ ! -d "$TARGET" ]; then echo "错误: 目录 $TARGET 不存在。" exit 1 fi
echo "开始监控 $TARGET ..."
inotifywait -m -r -e modify,create,delete,move --format '%w%f' "$TARGET" | while read FILE do while read -t 10 NEXT_FILE; do : done
echo "检测到变动:$FILE,正在执行任务..." cd /etc/komari/blog && /usr/local/bin/hexo g && /usr/local/bin/hexo d echo "任务执行完毕,继续监控..." done
|
设置开机自启
创建一个systemd服务,并编辑vim /etc/systemd/system/blog-monitor.service
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| [Unit] Description=Inotify Folder Monitor for Komari Blog After=network.target
[Service]
User=root Group=root
ExecStart=/usr/local/bin/blog_monitor.sh
Restart=always
RestartSec=5s
StandardOutput=journal StandardError=journal
[Install]
WantedBy=multi-user.target
|
重启systemd并设置开启自启
1 2 3
| sudo systemctl daemon-reload sudo systemctl enable blog-monitor.service sudo systemctl start blog-monitor.service
|
这样就能监控是否创建了新的文章,如果修改了主题文件,则自己去blog文件夹下重新执行一遍hexo clean && hexo g && hexo d