🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.raspberry-pi
4 messages
4 total messages Started by NY Thu, 12 Nov 2026 13:34
Starting a NODE app from a Cron job or start-on-boot
#82
Author: NY
Date: Thu, 12 Nov 2026 13:34
59 lines
3259 bytes
I've got a Pi running Raspberry Pi OS Bookworm. I've been starting a 
NODE app (not mine - one that I've downloaded) from a cron job and using 
one of the start-at-boot mechanisms (I forget which!).

This has worked until did a "sudo apt update" and "sudo apt upgrade".

Now the cron job fails to start the app, even though an explicit 
background job works from a terminal window.

The script that is run from the crob job is

#start
cd /srv/ext/NAS/tplink-energy-monitor

# At midnight, output a double-row separator; otherwise a single-row 
separator
date | grep " 00:00"
if [ $? -eq 0 ]; then
   echo "====================" >> /srv/ext/NAS/tplink-energy-monitor/tp.log
else
   echo "--------------------" >> /srv/ext/NAS/tplink-energy-monitor/tp.log
fi

date >> /srv/ext/NAS/tplink-energy-monitor/tp.log

echo "before 'npm start'" >> /srv/ext/NAS/tplink-energy-monitor/tp.log
ps -alef | grep -e node -e npm | grep -v grep | grep -v fusermount >> 
/srv/ext/NAS/tplink-energy-monitor/tp.log

npm start &

echo "after 'npm start'" >> /srv/ext/NAS/tplink-energy-monitor/tp.log
ps -alef | grep -e node -e npm | grep -v grep | grep -v fusermount >> 
/srv/ext/NAS/tplink-energy-monitor/tp.log

sleep 30

echo "after 'sleep 30'" >> /srv/ext/NAS/tplink-energy-monitor/tp.log
date >> /srv/ext/NAS/tplink-energy-monitor/tp.log
ps -alef | grep -e node -e npm | grep -v grep | grep -v fusermount >> 
/srv/ext/NAS/tplink-energy-monitor/tp.log
#end

The critical lines are

cd /srv/ext/NAS/tplink-energy-monitor
npm start &

The rest is logging to check that it works OK.


The script runs fine - all the logging stuff is OK. But it seems that 
"node" does not like running as a background job any more when invoked 
from a cron job as opposed to a terminal session.

The reason it's run from a cron job is that it has a habit of crashing 
every so often (no idea why, and writer of the app doesn't reply to 
emails) so I run it from cron every 5 minutes to restart it if it has 
stopped.
Re: Starting a NODE app from a Cron job or start-on-boot
#83
Author: druck
Date: Thu, 12 Nov 2026 15:27
13 lines
1836 bytes
On 12/11/2026 13:34, NY wrote:
> I've got a Pi running Raspberry Pi OS Bookworm. I've been starting a 
> NODE app (not mine - one that I've downloaded) from a cron job and using 
> one of the start-at-boot mechanisms (I forget which!).
> 
> This has worked until did a "sudo apt update" and "sudo apt upgrade".
> 
> Now the cron job fails to start the app, even though an explicit 
> background job works from a terminal window.
Have you tried updating all of the npm packages too?
Or is this likely to cause more problems than it solves?

---druck
Re: Starting a NODE app from a Cron job or start-on-boot
#84
Author: Richard Kettlewell
Date: Thu, 12 Nov 2026 18:08
14 lines
1578 bytes
NY <me@privacy.net> writes:
> I've got a Pi running Raspberry Pi OS Bookworm. I've been starting a
> NODE app (not mine - one that I've downloaded) from a cron job and
> using one of the start-at-boot mechanisms (I forget which!).
>
> This has worked until did a "sudo apt update" and "sudo apt upgrade".
>
> Now the cron job fails to start the app, even though an explicit
> background job works from a terminal window.

What is the output from the cron job?

-- 
https://www.greenend.org.uk/rjk/
Re: Starting a NODE app from a Cron job or start-on-boot
#85
Author: Lawrence D’Oliveiro
Date: Thu, 12 Nov 2026 20:18
17 lines
1937 bytes
On Thu, 12 Nov 2026 13:34:27 +0000, NY wrote:

> The script runs fine - all the logging stuff is OK. But it seems
> that "node" does not like running as a background job any more when
> invoked from a cron job as opposed to a terminal session.

What exactly is the error?

> The reason it's run from a cron job is that it has a habit of
> crashing every so often (no idea why, and writer of the app doesn't
> reply to emails) so I run it from cron every 5 minutes to restart it
> if it has stopped.

I would do this via a systemd service definition. That provides
automatic monitoring and restarting if/when it crashes (up to some
reasonable limit, to guard against endless loops). And any error
messages should appear in the journal as well.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads