MagicMirror Forum

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

    Crontab to Restart Magic Mirror does not work

    Bug Hunt
    3
    11
    528
    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.
    • D
      Desert Rat last edited by

      I have researched all of the documentation I can find but have failed to resolve this problem.
      I can create a Crontab entry as follows 44 * * * * PM2 restart MagicMirror

      I created a second entry to put a date entry in a file each minute in the same crontab . This one works as expected.

      My research has exposed this kind of issue using pm2 and I’ve attempted to implement suggested resolutions. All were ineffective.

      Forgive me if I missed a posed solution but would greatly appreciate any assistance.

      Thanks

      S evroom 2 Replies Last reply Reply Quote 0
      • S
        sdetweil @Desert Rat last edited by sdetweil

        @desert-rat what is in the pm2 log??

        pm2 logs --lines=50

        what user is the cron entry running as?
        typically root…

        but the pm2 entry is setup for pi probably

        Sam

        Create a working config
        How to add modules

        1 Reply Last reply Reply Quote 0
        • evroom
          evroom @Desert Rat last edited by

          @desert-rat

          I would try pm2 iso PM2.
          And even would advise to use the full path, that can be determined using:
          which pm2

          With Debian it would be /usr/local/bin/pm2

          And you can check this log if cron did anything at all:
          /var/log/syslog

          Or edit /etc/rsyslog.conf and remove comment on the line with cron (around line 63)
          Then the dedicated cron log will be in /var/log/cron.log.
          After editing, restart with „sudo systemctl restart rsyslog“.

          Good luck,

          E.J.

          MagicMirror version: 2.21.0
          Raspberry Pi 3 Model B Plus Rev 1.3
          Raspbian GNU/Linux 10 (buster)

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

            @evroom good catch on the uppercase pm2…

            @Desert-Rat
            everything in Linux is case sensitive

            Sam

            Create a working config
            How to add modules

            D 1 Reply Last reply Reply Quote 0
            • D
              Desert Rat @sdetweil last edited by

              @sdetweil
              Thanks for the quick reply. I changed the crontab. I actually changed it to PM2 START MagicMirror.

              The process I used was to , via the terminal, pm2 stop MagicMirror. This worked and MagicMirror was stopped sucessfully.
              Crontab was updated as above PM2 START MagicMirror.
              It did not start.

              Here are the entries from the log file

              Nov 27 13:44:01 raspberrypi CRON[3620]: (pi) CMD (SUDO PM2 START MagicMirror)
              Nov 27 13:44:01 raspberrypi CRON[3618]: (CRON) info (No MTA installed, discarding output)
              Nov 27 13:55:01 raspberrypi CRON[3661]: (root) CMD (sudo pm2 restart MagicMirror)
              Nov 27 13:55:04 raspberrypi CRON[3659]: (CRON) info (No MTA installed, discarding output)
              Nov 27 14:17:01 raspberrypi CRON[3772]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)

              S evroom 2 Replies Last reply Reply Quote 0
              • S
                sdetweil @Desert Rat last edited by

                @desert-rat PM2 is not the command

                pm2 is the command and start is the parm

                all lower case

                Sam

                Create a working config
                How to add modules

                1 Reply Last reply Reply Quote 0
                • evroom
                  evroom @Desert Rat last edited by

                  @desert-rat

                  Could you please show the crontab ?

                  $ crontab -l
                  

                  To get rid of this:

                  (CRON) info (No MTA installed, discarding output)
                  

                  you have to add >/dev/null 2>&1

                  Try:

                  44 * * * * /usr/local/bin/pm2 start MagicMirror >/dev/null 2>&1
                  

                  MagicMirror version: 2.21.0
                  Raspberry Pi 3 Model B Plus Rev 1.3
                  Raspbian GNU/Linux 10 (buster)

                  1 Reply Last reply Reply Quote 0
                  • D
                    Desert Rat last edited by

                    Problem resolved! Outstanding.

                    My thanks to all who responded.

                    My mission now is to research the provided solution and try to understand why it worked. Clearly the devil is in the details.

                    Thanks again to all of you

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

                      @desert-rat said in Crontab to Restart Magic Mirror does not work:

                      to understand why it worked.

                      your crontab entry

                      44 * * * * PM2 restart MagicMirror
                      

                      the working crontab entry

                      44 * * * * /usr/local/bin/pm2 start MagicMirror >/dev/null 2>&1
                      

                      could be restart as well…

                      simple, two things

                      cron runs as root, BUT certain folders are not in the path
                      so you need to specify the path to the command

                       /usr/local/bin/
                      

                      second the command is pm2, you tried PM2
                      in linux EVERYTHING is case sensitive

                      so yours is command not found, cause there is no command named PM2

                      Sam

                      Create a working config
                      How to add modules

                      D 1 Reply Last reply Reply Quote 0
                      • D
                        Desert Rat @sdetweil last edited by

                        @sdetweil Thanks Sam! I clearly need some education. Do you have a favorite set of training documentation for newbies

                        Desert Rat

                        S 1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 1 / 2
                        • 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