“Out-of-theBox”, the installed MagicMirror software does not start automatically after the RaspberryPi boots up. That's why it's practical to set up an autostart for the MagicMirror software.
How to do this is described in the following article.
Safety instructions
I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/sicherheitshinweise/
Affiliate links/advertising links
The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂
Requirements
Helpful articles:
Before you start with the article you should have prepared the RaspberryPi so far that it is accessible over the network and controllable via SSH. In addition, the MagicMirror software should already be installed.
The following articles describe what has to be done to prepare the RaspberryPi so far:
RaspberryPi – setup for nerdiys!
RaspberryPi – The first configuration!
RaspberryPi – Control the RaspberryPi via SSH
MagicMirror - Installing the required software
Required material:
-no-
Required material:
In the following list you will find all the parts you need to implement this article.
Log in to the RaspberryPi via SSH
To start, you must first log in to the Rasp Pi with Putty via SSH. How to do this is in the article RaspberryPi - Control the RaspberryPi via SSH described.
Set up autostart with the Node.js Process Manager
There are several ways to organize the autostart of MagicMirror. One of these ways is the ProcessManager for Node.js applications. The advantage of this is that it not only handles the autostart of the MagicMirror software. It also monitors after startup if the software is running correctly and restarts it if necessary.
Installation of the Process Manager
The process manager is not pre-installed on most systems. Therefore it must be installed with the following command.
sudo npm install -g pm2
Installation of the ProcessManager
Set up autostart of the ProcessManager
If the ProcessManager is installed, you must now set up an autostart for the ProcessManager. Because the ProcessManager can only take care of the autostart of the MagicMirror software, if it was started before. You can set up the autostart of the ProcessManager with the following command.
sudo pm2 startup
Set up MagicMirror Start Script
For the autostart of the MagicMirror to work you must first set up a start script. To do this, change to your home directory with the following command:
CD ~
There you create a new (still empty) file:
nano mm.sh
And inserts the following text in it.
cd ~/MagicMirror DISPLAY=:0 npm start
After that you have to make this script executable. The following command is sufficient
sudo chmod +x mm.sh
Now you can start the script with the ProcessManager.
pm2 start mm.sh
And now comes the real magic. With the following command the current state (the script/MagicMirror is running) is saved. This means that the ProcessManager now continuously checks whether the script and thus the MagicMirror is running correctly. If the MagicMirror crashes or is not running yet it will be started automatically by the ProcessManager.
pm2 save
Controlling the MagicMirror via the Process Manager
You can also control the MagicMirror via the ProcessManager. So start and stop. You also have the possibility to display login information.
Restart
pm2 restart mm
Stop
pm2 stop mm
Show log file
pm2 logs mm
Show process information
pm2 show mm
More information
https://github.com/MichMich/MagicMirror/wiki/Auto-Starting-MagicMirror
Have fun with the project
I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂
PS Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂
Good evening,
Thank you very much for these detailed and easy-to-understand explanations. My son (12 years old) and I are trying to get the autostart function set up. We can trace the entire path exactly, including the information in the command line up to the entry “pm2 save”. The MagicMirror display on the display is also shown or started. Unfortunately, when I turn the power off the Raspi4 and turn it back on, the Raspi only starts up to the normal desktop, but not the MagicMirror environment as I would expect. We use the MagicMirror2 environment.
Is there anything else to consider so that when the power is switched on, the MagicMirror environment is started? My son and I would be so grateful for feedback. Gladly for a small donation. Greetings from Lower Saxony, Andreas Graupner
Hey Andrew 🙂
could you please try the following:
– enter the command “pm2 startup”.
– enter the command “pm2 start mm.sh”.
– wait until the MagicMirror interface is visible on the screen and fully loaded
– enter the command “pm2 save”.
– then restart the RaspberryPi with “sudo reboot”.
If the MagicMirror doesn't start automatically after restarting, you can see if you notice anything in the log files. 🙂 To do this you have to enter the command “pm2 logs mm”. You can also post the output here. Then I'll take a look at it. 🙂
Best regards
Fabian
PS Of course I'm happy about a donation, but I'm also happy to help you. 🙂
I don't know if solved...
I had the same problem. In the end it was due to the ProcessManager's autostart. It wasn't set up correctly. “sudo pm2 startup” was not sufficient for me. After I entered “pm2 startup” a command was displayed that I had to execute once.
I couldn't set it up using “sudo pm2 startup”. After “pm2 startup” a command was displayed in the command line that I had to execute. Now the ProcessManager works correctly including booting the MagicMirror.
I don't know if the problem has been solved yet. For me, the ProcessManager autostart was not “set up” correctly. I had to type “pm2 startup” instead of “sudo pm2 startup”. A command was then displayed in the console, which I executed. The ProcessManager now works correctly, including booting the MagicMirror.