“Out-of-theBox” the installed MagicMirror software does not start automatically after the RaspberryPi has started up. That’s why it is usefull to setup an autostart.
How to do this is described in the following article.
Hints for our lovely english readers: Basically, many of the articles on Nerdiy.de are translations from the original german articles. Therefore, it may happen here and there that some illustrations are not available in english and that some translations are weird/strange/full of mistakes or generally totaly wrong. So if you find some obvious (or also not obvious) mistakes don't hesitate to leave us a hint about that in the comment section.
Also please don't get confused, that instead of a "dot" often a "comma" is used as decimal separator. 🙂
- 1 Safety instructions
- 2 Affiliate links / advertising links
- 3 Requirements
- 4 Log in via SSH on the RaspberryPi
- 5 Setting up the autostart with the Node.js Process Manager
- 6 Installation of the Process Manager
- 7 Startup of the ProcessManager
- 8 Set up MagicMirror Start Script
- 9 Controlling the MagicMirror via the Process Manager
- 10 Additional information
I know the following hints are always a bit annoying and seem unnecessary. But unfortunately, many people who knew it "better" from carelessness lost their eyes, fingers or other things or hurt themselves. In comparison, a loss of data is almost not worth mentioning, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Even the coolest project is worth no injury or other annoyance. https://www.nerdiy.de/en/sicherheitshinweise/
The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and shop via this link, Nerdiy.de receives a commission from the online shop or provider concerned. The price doesn't change for you. If you do your purchases via these links, you will support Nerdiy.de in being able to offer further useful projects in the future. 🙂
Before you start with this article, you should have prepared the RaspberryPi so that it can be reached via the network and controlled by SSH. In addition, the MagicMirror software should already be installed.
The following articles describe what to do to prepare the RaspberryPi:
RaspberryPi – Setting up for Nerdiys!
RaspberryPi – The first configuration
RaspberryPi – Controlling 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 via SSH on the RaspberryPi
To get started, you first need to log in to RasPi with SSH on Putty. How to do it is described in the article
Setting up the autostart with the Node.js Process Manager
There are several ways to organize the startup of the MagicMirror software. One of these ways is the ProcessManager for Node.js applications. The advantage of this is that it not only takes over the autostart of MagicMirror software. It also monitors after starting whether the software runs correctly and restarts it if necessary.
Installation of the Process Manager
Process Manager is not preinstalled on most systems. That’s why it needs to be installed with the following command.
sudo npm install -g pm2
Installation of the ProcessManager
Startup of the ProcessManager
If the ProcessManager is installed you now have to set up an autostart for the ProcessManager. Because the ProcessManager can of course only take care of the startup of the MagicMirror software, if it was previously started by itself. You can start the Autostart of the Processmanager with the following command.
sudo pm2 startup
Set up MagicMirror Start Script
In order for the start of the MagicMirror to work, you must first set up a startup script. To do this you change to your home directory with the following command:
There you create a new (still empty) file:
And insert the following text in it.
cd ~/MagicMirror DISPLAY=:0 npm start
Then you have to make this script executable. The following command suffices for this
sudo chmod +x mm.sh
Now you can start the script with the ProcessManager.
pm2 start mm.sh
And now comes the real magic. The following command saves the current state (The script/MagicMirror is running). This means that the ProcessManager now continuously checks whether the script is running and that the MagicMirror is running correctly. If this crashes or does not run yet, it will be automatically started by the ProcessManager.
Controlling the MagicMirror via the Process Manager
You can then control the MagicMirror via the ProcessManager. So start and stop. You also have the option to display log information.
pm2 restart mm
pm2 stop mm
pm2 logs mm
Show process information
pm2 show mm
I hope everything worked as described. If not or you have any other questions or suggestions, please let me know in the comments. Also, ideas for new projects are always welcome. 🙂
P.S. 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 appreciate it that I share these information with you, I would be happy about a small donation to the coffee box. 🙂