1

First of all, please, read until the end of the story and believe me that this is not a duplicate question - I've read all the possibilities and all the variations of this kind of issue but I didn't found a fix until now.

Second of all - let me tell you about my issue: I have a Raspberry PI 3 updated and upgraded, I have a node.js app (v 4.3.2) which if it's run from the command line when the user is logged in, it runs perfectly but if I'm scheduling the app to be run on startup it doesn't do anything. I mean, the app is running:

  492 ?        S      0:00 sudo nohup node /home/pi/meteo/meteo.js
  527 ?        Sl     0:01 node /home/pi/meteo/meteo.js

but it doesn't do anything.

In order to make it to run at startup I used the crontab way of scheduling like this:

@reboot sudo nohup node /home/pi/meteo/meteo.js &> /home/pi/meteo/meteo-reboot.log &

and accordingly to the processes that are running after startup, the application is working but, as I've said, it doesn't do anything.

Few words about the app: it's a simple app which connects to a Bluetooth sensor (TI CC2650) and sends the data to the IoT Hub on Azure. The app doesn't expect any input from the user.

Is there any place where can I see any node.js logging or is there any way of tracing what it might be the issue because I suspect that something might not be initialized when the app starts after reboot.

As you see in my crontab command, I'm sending all the output to a file - if I run that command manually, the meteo-reboot.log file is filled with my app output but if the app is running after startup using the crontab scheduling system, that file is empty and it doesn't get any data in it.

Thank you for your time and hopefully that there is someone who knows how can I get some info about what is wrong.

Evdin

Edi
  • 155
  • 1
  • 5
  • Why are you using sudo in the crontab? If you want it run root, run it from the system crontab. Also, if it is run by some user other than pi (e.g., if the system cron is running as user cron, you'll have to check), then note that redirection (&>) cannot be used with sudo to circumnavigate permissions. E.g., user pi cannot sudo ls $HOME > /list.txt. – goldilocks Mar 13 '16 at 19:10
  • I will try right now to use the root crontab to see what is happening... Be back in few seconds... Thanks – Edi Mar 13 '16 at 19:20
  • No change - added the command to the root crontab and now I have the process running: 461 ? Sl 0:01 node /home/pi/meteo/meteo.js; the crontab command is @reboot nohup node /home/pi/meteo/meteo.js &> /home/pi/meteo/meteo-reboot.log & – Edi Mar 13 '16 at 19:27
  • Have you tried rc.local instead? I think cron probably starts stuff earlier in the boot process, whereas you ideally would have this happen as late as possible (rc.local is run last). You may also find this useful: http://raspberrypi.stackexchange.com/questions/40493/log-output-of-background-or-boot-script -> Although you obviously already have normal logging set up, sometimes applications will throw initialization errors and such to stderr/stdout and you need to catch those differently. – goldilocks Mar 13 '16 at 19:54
  • I added this to the /etc/rc.local: (sudo nohup /usr/bin/node /home/pi/meteo/meteo.js) &>> /home/pi/meteo/meteo-reboot.log & and nothing is happening... I suspect that is something wrong with the node.js but I don't know how to investigate this kind of issues. – Edi Mar 13 '16 at 20:51
  • As I've said several times sudo in rc.local (or other init scripts which do not de-escalate) is at best totally pointless and at worst a cause of problems. Using nohup in this context is also unnecessary. – goldilocks Mar 13 '16 at 20:53
  • (/usr/bin/node /home/pi/meteo/meteo.js) &>> /home/pi/meteo/meteo-reboot.log & - better now? :-) – Edi Mar 13 '16 at 20:57
  • Yeah. If it is actually running but has not produced any log output, try sending it a signal. I haven't used node in years, I don't know what if anything it will respond to, but you could start with sudo kill -s 1 [pid] where [pid] is node's. There's a list you can see with kill -L. Try stuff like ABRT, STOP, INT, (or the corresponding numbers), checking the log and whether it is still around each time, move on to TERM. – goldilocks Mar 13 '16 at 21:05

1 Answers1

1

Your app might be waiting for some other application to run and return data to consume, check whether the dependencies of your app are started before your app runs.

Add a timer of 30 sec's and check if it works.

Vimal
  • 56
  • 1