MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord

    Auto-start MagicMirror after reboot (Raspberry Pi)

    General Discussion
    3
    3
    3269
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      pbelanger last edited by pbelanger

      My Raspberry Pi mirror has shut off a few times by accident (overheated, lost power, etc). Every time I turned it back on it was kind of a pain - I had to take the mirror off the wall, hook up my keyboard and mouse, start up the mirror, etc. This happened enough that I wanted to automate a solution. I finally found this article and followed “method 2”. I thought I’d summarize here in case this can help anyone else.

      What this will do

      Start up your mirror whenever your raspberry pi gets turned on.

      How?

      We’ll utilize Raspian’s autostart mechanism to run a shell script whenever your Raspberry Pi starts up. The shell script will turn off sleep mode on your Pi and start your mirror.

      1) Write a shell script

      Create a shell script in the home directory. From the terminal, type:

      $ vi /home/pi/start-mirror.sh
      

      Copy this code into the start-mirror.sh file that was just opened, then save and close the file:

      #!/bin/bash
      
      sudo xset -dpms
      sudo xset s off
      cd /home/pi/MagicMirror && npm start
      

      3) Create a .desktop file

      This will utilize the autostart system on the pi. Your script will run after the desktop system starts up.

      $ mkdir /home/pi/.config/autostart
      $ vi /home/pi/.config/autostart/mirror.desktop        
      

      Note: you might not need to run the first command to create the autostart directory - I already had this directory on my computer.

      Copy this code into the mirror.desktop file and save it:

      [Desktop Entry]
      Type=Application
      Name=MirrorStart
      Exec=sh /home/pi/start-mirror.sh
      

      After this saves, you’re all set. Reboot the pi and test it out:

      sudo reboot
      

      After the reboot you should see the Desktop pop up for 10-20 seconds, then your mirror should automatically start up.

      S 1 Reply Last reply Reply Quote 1
      • S
        sdetweil @pbelanger last edited by

        @pbelanger but u can do it a lot easier with node process manager (aka pm2)…

        it will start on boot, restart if failed, etc,etc,etc

        if U used my install scripts, it was an option,
        I also provide the setup script to add this on after install

        see https://github.com/sdetweil/MagicMirror_scripts

        last entry
        fixuppm2.sh

        one copy/paste

        this works the same on Windows, Linux and Mac

        no special files, no services, …

        Sam

        Create a working config
        How to add modules

        BKeyport 1 Reply Last reply Reply Quote 1
        • BKeyport
          BKeyport Module Developer @sdetweil last edited by

          Yeah, I’d recommend the PM2 method. In my install, I’ve also got an 18650 battery based UPS in place along with proper cooling… the UPS automatically shuts down the Pi if on battery too long, and will restart it for me. Easy as Pi(e).

          The "E" in "Javascript" stands for "Easy"

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Enjoying MagicMirror? Please consider a donation!
          MagicMirror created by Michael Teeuw.
          Forum managed by Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
          This forum is using NodeBB as its core | Contributors
          Contact | Privacy Policy