HowTo: Magic Mirror – set up autostart

"Out-of-theBox" the installed MagicMirror software does not start automatically after the RaspberryPi is booted. Therefore it is 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.

After entering your username and password you can enter the first commands.

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
To set up the autostart of the ProcessManager you have to enter the 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 you have inserted the text, save the file by pressing "CTRL+X" and...
... a press on "Enter".

After that you have to make this script executable. The following command is sufficient

sudo chmod +x mm.sh
This will give the script the necessary permissions to be executed.

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. 🙂

Buy Me a Coffee at ko-fi.com       

4 comments

  1. Good evening,
    Thank you 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 follow the entire path exactly, there is also information in the command line up to the "pm2 save" entry. The MagicMirror display is also shown or started. Unfortunately, when I turn off the power from the Raspi4 and turn it on again, 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

    1. 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 does not start automatically after the restart, you can see if you notice anything in the log files. 🙂 For this you have to enter the command "pm2 logs mm". You are also welcome to post the output of it here. Then I'll take a look. 🙂

      Best regards
      Fabian

      PS Of course I'm happy about a donation, but I'm also happy to help you. 🙂

  2. I don't know if solved...
    I had the same problem. In the end it was the Autostart of the ProcessManager. It wasn't set up correctly. "sudo pm2 startup" was not sufficient for me. After I entered "pm2 startup" I was shown another command that I had to run once.

    I couldn't set it up with "sudo pm2 startup". After "pm2 startup" I was presented with a command in the command line that I had to run. Now the ProcessManager works correctly including booting the MagicMirror.

  3. I don't know if the problem has already been solved. The autostart of the ProcessManager was not set up correctly for me. I had to type "pm2 startup" instead of "sudo pm2 startup". Then the console showed me a command that I ran. Now the ProcessManager works correctly, including booting the MagicMirror.

Kommentar hinterlassen

Your email address will not be published. Erforderliche Felder sind mit * markiert

This site uses Akismet to reduce spam. Learn how your comment data is processed.