MagicMirror Forum

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

    pm2 doesnt work with crontab

    Troubleshooting
    3
    9
    1143
    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.
    • K
      keineAhnung123 last edited by

      Hello,

      Im trying to restart my MM every day in the night so i want to use a crontab.

      Might be easy:

      sudo crontab -e
      

      and add

      59 23 * * * pm2 restart mm
      

      But that doesnt work.
      The crontab seems to work:

      Feb 27 13:37:01 raspberrypi CRON[3581]: (root) CMD (pm2 restart mm)
      
      

      And i did a pm2 flush before and after the crontab did its job there is nothing in the log:

      pi@raspberrypi:~ $ pm2 logs --lines=100
      [TAILING] Tailing last 100 lines for [all] processes (change the value with --lines option)
      /home/pi/.pm2/pm2.log last 100 lines:
      /home/pi/.pm2/logs/mm-error.log last 100 lines:
      /home/pi/.pm2/logs/mm-out.log last 100 lines:
      0|mm       | [27.02.2021 13:38.28.339] [INFO]  Newsfeed-Fetcher: Broadcasting 39 items.
      
      

      so it seems that pm2 didnt do anything.

      Next try after some online research:

      pi@raspberrypi:~ $ which node
      /home/pi/.config/nvm/versions/node/v10.23.0/bin/node
      pi@raspberrypi:~ $ which pm2
      /home/pi/.config/nvm/versions/node/v10.23.0/bin/pm2
      
      

      i changed the crontab to

      1 14 * * * /home/pi/.config/nvm/versions/node/v10.23.0/bin/node /home/pi/.config/nvm/versions/node/v10.23.0/bin/pm2 restart mm
      
      

      (1 14 is for testing)

      It still doesnt work: no output in pm2 log.

      Does anyone have an idea?

      Thanks 🙂

      S Assassins 2 Replies Last reply Reply Quote 0
      • S
        sdetweil @keineAhnung123 last edited by sdetweil

        @keineahnung123 u need to run pm2 as the user that did the save and where mm was running. it cannot be rootScreenshot_20210227-074511_Chrome.jpg

        you also create a user specific crontab in /var/spool/cron
        user needs to own the file, then username is not required on the contab entries themselves

        Each user, including root, can have a cron file. These files don't exist by default, but can be created in the /var/spool/cron directory using the crontab -e command that's also
        

        Sam

        Create a working config
        How to add modules

        K 1 Reply Last reply Reply Quote 0
        • K
          keineAhnung123 @sdetweil last edited by

          @sdetweil Thanks.

          With

          sudo nano /etc/crontab
          

          and

          30 16   * * *   pi      /home/pi/.config/nvm/versions/node/v10.23.0/bin/node /home/pi/.config/nvm/versions/node/v10.23.0/bin/pm2 stop mm
          

          it seems to work 🙂

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

            @keineahnung123 i don’t think u need those paths now

            Sam

            Create a working config
            How to add modules

            K 1 Reply Last reply Reply Quote 0
            • K
              keineAhnung123 @sdetweil last edited by keineAhnung123

              @sdetweil

              45 16   * * *   pi      pm2 stop mm
              

              doesnt work. I have to set the paths.

              I think there went something wrong when i upgraded to buster.
              I had a shellscript with

              cd ~/MagicMirror && npm start
              

              which worked fine and after the upgrade to buster i have to use

              cd ~/MagicMirror && /home/pi/.config/nvm/versions/node/v10.23.0/bin/npm start
              

              otherwise it says “npm: not found”

              Same seems to be with crontab…

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

                @keineahnung123 looks like u need to reinstall nvm

                Sam

                Create a working config
                How to add modules

                K 1 Reply Last reply Reply Quote 0
                • K
                  keineAhnung123 @sdetweil last edited by

                  @sdetweil said in pm2 doesnt work with crontab:

                  @keineahnung123 looks like u need to reinstall nvm

                  nvm or npm?

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

                    @keineahnung123 nvm

                    Sam

                    Create a working config
                    How to add modules

                    1 Reply Last reply Reply Quote 0
                    • Assassins
                      Assassins @keineAhnung123 last edited by

                      @keineahnung123
                      Hello, i Can send you a script om monday, where you make backup to a small .img and where is restart you MagicMirror on the same time.

                      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