1

我有一个基于对文本文件的一些更改的 inotify cron(Incron),它应该运行一个脚本。下面也是我的 incrontab 文件

/home/pi/payload.txt IN_ATTRIB,IN_CLOSE_WRITE bash /home/pi/deploy.sh

为了显示 incrontab 实际上正在触发下面的脚本是它的日志

Dec 23 19:17:01 raspberrypi /USR/SBIN/CRON[13526]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Dec 23 20:17:01 raspberrypi /USR/SBIN/CRON[25509]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Dec 23 21:17:01 raspberrypi /USR/SBIN/CRON[6389]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Dec 23 21:32:34 raspberrypi incrond[23252]: (pi) CMD (bash /home/pi/deploy.sh)
Dec 23 21:51:56 raspberrypi incrond[23252]: table for user pi changed, reloading
Dec 23 21:52:02 raspberrypi incrond[23252]: (pi) CMD (sh /home/pi/deploy.sh)
Dec 23 21:52:56 raspberrypi incrond[23252]: table for user pi changed, reloading
Dec 23 21:53:15 raspberrypi incrond[23252]: (pi) CMD (cd /home/pi/ && ./deploy.sh)
Dec 23 21:53:15 raspberrypi incrond[14102]: cannot exec process: No such file or directory
Dec 23 21:55:30 raspberrypi incrond[23252]: table for user pi changed, reloading
Dec 23 21:55:49 raspberrypi incrond[23252]: (pi) CMD (/home/pi/deploy.sh)

它的工作原理是,当它重新启动节点服务器并尝试通过 Web 访问它时,它给了我一个禁止的错误,如下所示:

Error: Forbidden
   at SendStream.error (/home/pi/Code/borikanes/node/node_modules/express/node_modules/send/index.js:239:16)
   at SendStream.pipe (/home/pi/Code/borikanes/node/node_modules/express/node_modules/send/index.js:425:19)
   at serveStatic (/home/pi/Code/borikanes/node/node_modules/express/node_modules/serve-static/index.js:110:12)
   at Layer.handle [as handle_request] (/home/pi/Code/borikanes/node/node_modules/express/lib/router/layer.js:82:5)
   at trim_prefix (/home/pi/Code/borikanes/node/node_modules/express/lib/router/index.js:270:13)
   at /home/pi/Code/borikanes/node/node_modules/express/lib/router/index.js:237:9
   at Function.process_params (/home/pi/Code/borikanes/node/node_modules/express/lib/router/index.js:312:12)
   at /home/pi/Code/borikanes/node/node_modules/express/lib/router/index.js:228:12
   at Function.match_layer (/home/pi/Code/borikanes/node/node_modules/express/lib/router/index.js:295:3)
   at next (/home/pi/Code/borikanes/node/node_modules/express/lib/router/index.js:189:10)

这个 shell 脚本也重新启动了一个烧瓶服务器,但重新启动很好。更奇怪的是,如果我手动运行 shell 脚本(通过 SSH 连接到服务器并运行./deploy.sh),它工作正常,没有禁止错误。即使 incrontab 以与我用来手动运行脚本的用户相同的用户身份运行脚本,我只是对如何发生这种情况感到震惊。

提供更多信息:我正在使用屏幕会话运行烧瓶和节点服务器,因此每个服务器都有自己的屏幕会话。所以 bash 脚本只是终止屏幕会话,从我的 GitHub 存储库中提取最新更改,然后在屏幕会话中重新启动服务器。他们都在树莓派上运行

我最后的手段是使用 nodemon 或但我实际上想知道为什么会发生此错误。谢谢!

4

0 回答 0