Can't get pm2 to auto launch after reboot
I’ve Done all of the below steps bit it till wont auto launch when i reboot the PI
We want Magic Mirror to start up automatically, so type in the following command:
When the text editor has opened, add this to the mm.sh file:
DISPLAY=:0 npm start
Exit the editor by pressing ctrl+x and type in y to save the file.
Make your shiny new script executable by typing in:
chmod +x mm.sh
Now start up Magic Mirror and make it start up on boot:
pm2 start mm.sh
Now, reboot your Pi by typing in
pm2 start mm.sh
pm2 start mm
Chris last edited by
there is an existing script provided by MagicMirror now, please try deleting everything on your ~/.pm2 directory, then using:
sudo su -c "env PATH=$PATH:/usr/bin pm2 startup linux -u pi --hp /home/pi" pm2 start ~/MagicMirror/installers/pm2_MagicMirror.json pm2 save
You may have to use systemd instead of linux in the first line if you get an error.
This solution is not mine but Shbatm.
See this post: Here
i had the same problem the last weeks.
It looks like pm2 creates the startup script for systemd with wrong parameters.
You should check if there exists a file “/etc/systemd/systemd/pm2-pi.service”
In my case the file existed but contained the following lines:
USER=root which should be USER=pi
Environment=PM2_HOME=/root/.pm2 which should be Environment=PM2_HOME=/home/pi/.pm2
PIDFile=/root/.pm2/pm2.pid which should be PIDFile=/home/pi/.pm2/pm2.pid
If the file does not exist you can create it with:
sudo pm2 startup systemd -u pi
But you need to check the values again after creating it.
In the end you can enable the script with:
sudo systemd enable pm2-pi.service
The parts in described by @Chris are needed as well