🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.raspberry-pi
Article #82

Starting a NODE app from a Cron job or start-on-boot

#82
From: 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.
Technical Details
Message-ID: <11d4f94$3ve0f$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: NY <me@privacy.net>
Newsgroups: comp.sys.raspberry-pi
Subject: Starting a NODE app from a Cron job or start-on-boot
Date: Thu, 12 Nov 2026 13:34:27 +0000
Organization: A noiseless patient Spider
Lines: 59
Message-ID: <11d4f94$3ve0f$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 12 Nov 2026 13:34:29 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="4175887"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19XYmzj9wm2qZTynLh45gdWUar/twwQijU="; posting-host="4801160062b9f40c498ad15c386e8b14"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Z67ChxhPIJAf3mRY0O8MKiV7lu8= sha256:bYlmYPfMGjjaU3swJkjRwtDEHex7mMnt8tofef7aEWg=
	sha1:f3I+bJcQHYCVPFNWoUScf0C1eQ8= sha256:Z09LW6GTZOjFei/fkAcZOwwj9uhfR1FJvaxcbbIcJiY=
X-Antivirus: AVG (VPS 261111-6, 11/11/2026), Outbound message
Content-Language: en-GB
X-Antivirus-Status: Clean