MagicMirror² v2.13.0 is available! For more information about this release, check out this topic.

Can't get pm2 to auto launch after reboot

  • I’ve Done all of the below steps bit it till wont auto launch when i reboot the PI

    We want Magic Mirror to start up automatically, so type in the following command:
    pm2 startup

    Now create a shell script for startup. Open up the built-in text editor on the Pi by typing in:
    cd ~
    The lower line basically means, “open up a file called in the nano text editor.”

    When the text editor has opened, add this to the file:
    cd ~/MagicMirror
    DISPLAY=:0 npm start
    Exit the editor by pressing ctrl+x and type in y to save the file.

    Make your shiny new script executable by typing in:
    chmod +x

    Now start up Magic Mirror and make it start up on boot:
    pm2 start

    pm2 save

    Now, reboot your Pi by typing in
    sudo reboot

  • Project Sponsor Module Developer

    @gmgarcia719 said in Can’t get pm2 to auto launch after reboot:

    pm2 start
    pm2 save

    instead try
    pm2 start mm

    pm2 save


  • Hello,
    test this:

    there is an existing script provided by MagicMirror now, please try deleting everything on your ~/.pm2 directory, then using:

    sudo su -c "env PATH=$PATH:/usr/bin pm2 startup linux -u pi --hp /home/pi"
        pm2 start ~/MagicMirror/installers/pm2_MagicMirror.json
        pm2 save

    You may have to use systemd instead of linux in the first line if you get an error.

    This solution is not mine but Shbatm.

    See this post: Here


  • Module Developer

    i had the same problem the last weeks.
    It looks like pm2 creates the startup script for systemd with wrong parameters.
    You should check if there exists a file “/etc/systemd/systemd/pm2-pi.service”
    In my case the file existed but contained the following lines:

    USER=root which should be USER=pi
    Environment=PM2_HOME=/root/.pm2 which should be Environment=PM2_HOME=/home/pi/.pm2
    PIDFile=/root/.pm2/ which should be PIDFile=/home/pi/.pm2/

    If the file does not exist you can create it with:
    sudo pm2 startup systemd -u pi

    But you need to check the values again after creating it.
    In the end you can enable the script with:
    sudo systemd enable pm2-pi.service

    The parts in described by @Chris are needed as well

Log in to reply