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

Restarting MM² when config.js file changes

  • Module Developer

    This has been helpful for me, but I didn’t see it mentioned anywhere, so I thought I’d share. For anyone looking for a simple way to automatically restart your MM² when you change the config.js file:

    Note: This assumes you are using pm2 to start the server, as described here: Auto Starting MagicMirror

    1. Create a file in the same location as your script called mm.json.
    2. Paste the contents of this gist into the file (adjust if needed for your setup).
    3. Run pm2 stop mm && pm2 delete mm to stop & remove the current mm script.
    4. Run pm2 start mm.json to restart MM. Now any time you change config.js, pm2 will automatically restart the process.
    5. Run pm2 save to save your changes for the next reboot.

    That’s it!

    Originally inspired by: Restart Mirror?

  • Module Developer

    For those that do a lot of testing, something I’ve found very useful as well: extract the config.js file out into it’s own git repo; then just switch between branches when you want to test something, that way you don’t break your “main” config file.

    cd ~
    mkdir mmConfig
    cd mmConfig
    git init
    mv ~/MagicMirror/config/config.js ./config.js
    ln -s /home/pi/mmConfig/config.js /home/pi/MagicMirror/config/config.js
    git commit -am "Initial Commit"
    git checkout -b testing
    # Change and test config.js without fear of breaking it!
    # Use checkout -f master to switch back to your main branch

  • Hello !

    I’ve followed your tutorial and it seems to work. For example my MM starts on boot.
    But when my MM is open, if I press Alt+tab to open and modify my config.js file, nothing is happening (it is not restarting).
    I don’t know why, do you have any idea ?

    Thank you !

    Edit: After a reboot, this is working ! Ty
    Edit2: There is a way to not completly rebooting it ? I mean doing the same thing as pressing CTRL + R, so the mirror reboots but stays on a black screen (instead of going back on the Desktop)
    Edit3: If I do “pm2 stop mm.json” to stop the process and then start it again doing “pm2 start mm.json” then If I modify the config file, this is not working anymore

  • Module Developer

    Wow. Cool idea.

Log in to reply