“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.
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.
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. 🙂
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
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:
There you create a new (still empty) file:
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.
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.
pm2 restart mm
pm2 stop mm
Show log file
pm2 logs mm
Show process information
pm2 show mm
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. 🙂