This was a pain to get right, so here’s what I landed on:
- Open System Settings > Energy Saver
- Turn on Start up automatically after a power failure
- Under Privacy & Security > Full Disk Access, add the executable
/usr/sbin/cron
- Log in as root:
sudo su
- Install pm2 globally:
npm i -g pm2
- Don’t get trapped in vim:
export EDITOR=nano
- Copy the PATH to clipboard:
eval 'echo PATH="$PATH"' | pbcopy
- Edit crontab:
crontab -e
- Paste in the PATH
- Create cron entries using the full path for file/directory references (you don’t need it for executables)
Example root cron:
PATH=/Users/steve/.bun/bin:/usr/local/bin:...
@reboot pm2 start /full/path/to/script.js
This creates a PM2 service for the root user. You can only see/remove its entries when logged in as root:
sudo su
# list services
pm2 list
# remove 1st entry
pm2 del 0