1

I have an inotify cron(Incron) that based on some changes to a text file, it should run a script. Below is also my incrontab file

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

To show that the incrontab is actually firing the script below is the log from it

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)

It works except that when it restarts the node server and I try to access it over web, it gives me a forbidden error like below:

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)

This shell script also restarts a flask server but that's restarting fine. The more weird thing is if I run the shell script manually(by SSHing to the server and running ./deploy.sh), it works fine, no forbidden error. I'm just stunned as to how this could happen even though the incrontab is running the script as the same user that i used to run the script manually.

To give more info: I am running both a flask and node server using screen sessions so each server has it's own screen session. So the bash script just kills the screen sessions, pulls latest changes from my GitHub repo and then restarts the servers in screen sessions. They're both running on a raspberry pi

My last resort is using nodemon or BUT I would actually like to know why this error is occuring. Thanks!

  • After battling with it for a while, I decided to just go with nodemon which works. But i'm still curious to know why this isn't working. – Bori Oludemi Dec 24 '15 at 19:23

0 Answers0