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

    From NY@me@privacy.net to comp.sys.raspberry-pi on Thu Nov 12 13:34:27 2026
    From Newsgroup: comp.sys.raspberry-pi

    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.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From druck@news@druck.org.uk to comp.sys.raspberry-pi on Thu Nov 12 15:27:04 2026
    From Newsgroup: comp.sys.raspberry-pi

    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
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Richard Kettlewell@invalid@invalid.invalid to comp.sys.raspberry-pi on Thu Nov 12 18:08:49 2026
    From Newsgroup: comp.sys.raspberry-pi

    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/
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.sys.raspberry-pi on Thu Nov 12 20:18:37 2026
    From Newsgroup: comp.sys.raspberry-pi

    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.
    --- Synchronet 3.22a-Linux NewsLink 1.2