MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    pm2 doesnt work with crontab

    Scheduled Pinned Locked Moved Troubleshooting
    45 Posts 8 Posters 14.7k Views 6 Watching
    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.
    • plainbrokeP Offline
      plainbroke @chrisfr1976
      last edited by plainbroke

      @chrisfr1976 said in pm2 doesnt work with crontab:

      find / -iname pm2

      /usr/local/bin/pm2
      /usr/local/lib/node_modules/pm2
      /usr/local/lib/node_modules/pm2/bin/pm2
      /usr/local/lib/node_modules/pm2/lib/templates/logrotate.d/pm2
      /usr/local/lib/node_modules/pm2/pm2
      
      
      /home/pi/MagicMirror/node_modules/.bin/pm2
      /home/pi/MagicMirror/node_modules/pm2
      /home/pi/MagicMirror/node_modules/pm2/bin/pm2
      /home/pi/MagicMirror/node_modules/pm2/lib/templates/logrotate.d/pm2
      /home/pi/MagicMirror/node_modules/pm2/pm2
      
      

      Which is the true one and one to use?

      Slow learner. But trying anyways.
      MM is on Raspberry Pi 4B w/8gb ram loaded on a 128gb nvme drive.
      Running Trixie and the latest MM version.

      C 1 Reply Last reply Reply Quote 0
      • C Offline
        chrisfr1976 @plainbroke
        last edited by

        @plainbroke
        Then use this:
        /usr/local/bin/pm2

        Regards, Chris.

        plainbrokeP 1 Reply Last reply Reply Quote 1
        • plainbrokeP Offline
          plainbroke @chrisfr1976
          last edited by plainbroke

          @chrisfr1976
          @sdetweil
          Thank you both for the help.
          /usr/local/bin/pm2 restart mm
          worked so I set it up to stop now and if (fingers crossed) works.
          I am golden.
          Wonder why I never had to use the full path before?
          Maybe my pm2 path was /home/pi/pm2 before.
          Doesn’t really matter as long as it works, I am a happy camper.
          It works.
          Thank you so much… I will mark this solved.
          Well I would if I could… strange.

          By the way " which pm2 " shows the path that I needed to use in crontab -e

          Slow learner. But trying anyways.
          MM is on Raspberry Pi 4B w/8gb ram loaded on a 128gb nvme drive.
          Running Trixie and the latest MM version.

          S 1 Reply Last reply Reply Quote 1
          • S Do not disturb
            sdetweil @plainbroke
            last edited by sdetweil

            @plainbroke awesome

            i should have remembered the path problem

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            plainbrokeP 1 Reply Last reply Reply Quote 1
            • plainbrokeP Offline
              plainbroke @sdetweil
              last edited by

              @sdetweil
              Did the new MM and or trixie change the way crontab works? Mine has stopped working since the update to 2.33. I tried again tonight and will see if the changes work or not… also my mm.json file quit working. Hind sight is 20/20 should have left well enough alone…

              Slow learner. But trying anyways.
              MM is on Raspberry Pi 4B w/8gb ram loaded on a 128gb nvme drive.
              Running Trixie and the latest MM version.

              S 1 Reply Last reply Reply Quote 0
              • S Do not disturb
                sdetweil @plainbroke
                last edited by

                @plainbroke I do not know

                Sorry, I have to ask, you DID use a new sd card, right?

                What does /var/log/syslog say about the crontab execution

                Did you use crontab -e
                Or sudo crontab -e

                1st is run as user who executed the crontab command
                2nd is run as root

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                plainbrokeP 1 Reply Last reply Reply Quote 0
                • plainbrokeP Offline
                  plainbroke @sdetweil
                  last edited by plainbroke

                  @sdetweil
                  Using NVMe disk 256gb smallest I had on hand. 3 of them are exhibiting the same issues. I did try going back to Bookworm and I am still getthing a blank screen after a while. I ran npm run config:check it says all is good in the config.js ////
                  I am currently reloading from scratch.
                  Which OS is better for the 2.33 MM? 32 or 64 bit?
                  Wondering if I was using 32 bit and now the 64 bit is messing with me… So dang many things can mess with these little devices.

                  I only use crontab -e, should I try sudo crontab -e

                  Slow learner. But trying anyways.
                  MM is on Raspberry Pi 4B w/8gb ram loaded on a 128gb nvme drive.
                  Running Trixie and the latest MM version.

                  S 1 Reply Last reply Reply Quote 0
                  • S Do not disturb
                    sdetweil @plainbroke
                    last edited by sdetweil

                    @plainbroke no, without sudo is best

                    Maybe pm2 isn’t in the path when crontab fires
                    Check the syslog for crontab errors

                    32 bit is about to be trouble.

                    The latest nodejs version, 24, has dropped builds for 32 bit

                    Sam

                    How to add modules

                    learning how to use browser developers window for css changes

                    plainbrokeP 1 Reply Last reply Reply Quote 0
                    • plainbrokeP Offline
                      plainbroke @sdetweil
                      last edited by plainbroke

                      @sdetweil
                      Thanks for the info I almost pulled down 32 bit.
                      It has been interesting to say the least going to trixie.
                      Turns out my problem was a failed NVMe drive.
                      I thought those things where supposed to last for a LONG long time…
                      I did get crontab -e to work with trixie and MM 2.33 not a fun ride, but entertaining. I finally learned how to use bash to make batch style files…
                      So not a complete loss of time…

                      Slow learner. But trying anyways.
                      MM is on Raspberry Pi 4B w/8gb ram loaded on a 128gb nvme drive.
                      Running Trixie and the latest MM version.

                      S 1 Reply Last reply Reply Quote 1
                      • S Do not disturb
                        sdetweil @plainbroke
                        last edited by

                        @plainbroke technology is SOOOO much fun! Simple, til it’s not!

                        Thanks for the feedback. Others will ask, I’m sure they could use your help!

                        Sam

                        How to add modules

                        learning how to use browser developers window for css changes

                        plainbrokeP 1 Reply Last reply Reply Quote 0
                        • plainbrokeP Offline
                          plainbroke @sdetweil
                          last edited by plainbroke

                          @sdetweil
                          Ok crontab -e worked last night to shutdown MM. So the pm2 stop all worked.
                          BUT this morning the pm2 restart mm did nothing.
                          I used find to get these:

                          /home/pi/MagicMirror/node_modules/.bin/pm2
                          /home/pi/MagicMirror/node_modules/pm2
                          /home/pi/MagicMirror/node_modules/pm2/bin/pm2
                          /home/pi/MagicMirror/node_modules/pm2/lib/templates/logrotate.d/pm2
                          /home/pi/MagicMirror/node_modules/pm2/pm2
                          /usr/local/bin/pm2
                          /usr/local/lib/node_modules/pm2
                          /usr/local/lib/node_modules/pm2/bin/pm2
                          /usr/local/lib/node_modules/pm2/lib/templates/logrotate.d/pm2
                          /usr/local/lib/node_modules/pm2/pm2
                          
                          

                          ANY idea on which one would work better.?
                          Here is my current crontab -e

                          # Turn off display at 9pm
                          00 21 * * 0-6 /usr/local/bin/pm2 stop all >/dev/null >2&1
                          # Turn on screen Monday - Friday at 6:45 am
                          45 06 * * 1-5 /usr/local/bin/pm2 start mm >/dev/null >2&1
                          # Turn on screen Saturday - Sunday at 7:30 am
                          30 07 * * 6,0 /usr/local/bin/pm2 start mm >/dev/null >2&1
                          
                          

                          Slow learner. But trying anyways.
                          MM is on Raspberry Pi 4B w/8gb ram loaded on a 128gb nvme drive.
                          Running Trixie and the latest MM version.

                          S mumblebajM 3 Replies Last reply Reply Quote 0
                          • S Do not disturb
                            sdetweil @plainbroke
                            last edited by sdetweil

                            @plainbroke which one, if any , are in the path
                            Are they all executable?

                            ls -laF
                            Will give you the permissions mask

                            Are any of them links to another?

                            What changed?

                            /usr/local/bin/pm2
                            Should be the one

                            Sam

                            How to add modules

                            learning how to use browser developers window for css changes

                            plainbrokeP 1 Reply Last reply Reply Quote 0
                            • S Do not disturb
                              sdetweil @plainbroke
                              last edited by

                              @plainbroke also look in /var/log/syslog
                              To find the logging of the execute at the time it should fire

                              Sam

                              How to add modules

                              learning how to use browser developers window for css changes

                              1 Reply Last reply Reply Quote 0
                              • plainbrokeP Offline
                                plainbroke @sdetweil
                                last edited by

                                @sdetweil
                                Weird, I do not have /var/log/syslog.
                                Even did a find for it nothing, popped up…

                                pi@Pixie:~ $ ls -laF
                                total 348
                                drwx------ 15 pi   pi     4096 Nov 10 15:36 ./
                                drwxr-xr-x  3 root root   4096 Sep 30 19:18 ../
                                -rw-------  1 pi   pi     9080 Nov 10 13:17 .bash_history
                                -rw-r--r--  1 pi   pi      220 Sep 30 19:06 .bash_logout
                                -rw-r--r--  1 pi   pi     3523 Sep 30 19:06 .bashrc
                                drwx------ 13 pi   pi     4096 Nov  7 18:22 .cache/
                                drwx------ 22 pi   pi     4096 Nov  8 12:57 .config/
                                drwx------  3 pi   pi     4096 Nov  7 17:49 .dbus/
                                drwxrwxr-x  2 pi   pi     4096 Sep 30 19:17 Desktop/
                                drwx------  2 pi   pi     4096 Nov  7 23:11 Documents/
                                -rw-rw-r--  1 pi   pi        0 Nov  7 20:00 .gitconfig
                                -rw-rw-r--  1 pi   pi       81 Nov  7 18:24 .gtkrc-2.0
                                -rw-rw-r--  1 pi   pi   222126 Oct 27 18:52 install.log
                                drwx------  4 pi   pi     4096 Sep 30 19:18 .local/
                                drwxrwxr-x 16 pi   pi     4096 Nov  8 12:54 MagicMirror/
                                -rwxrwxrwx  1 pi   pi      320 Jun 12  2022 mm.json*
                                -rwxrwxrwx  1 pi   pi       38 Jul 16  2023 mm.sh*
                                drwx------  4 pi   pi     4096 Nov  6 21:05 .mozilla/
                                drwxrwxr-x  4 pi   pi     4096 Oct 27 18:30 .npm/
                                drwx------  3 pi   pi     4096 Oct 27 18:52 .pki/
                                drwxrwxr-x  5 pi   pi     4096 Nov  9 17:24 .pm2/
                                -rw-r--r--  1 pi   pi      807 Sep 30 19:06 .profile
                                -rw-rw-r--  1 pi   pi       66 Oct 27 19:22 .selected_editor
                                drwxrwxr-x  4 pi   pi     4096 Nov 10 15:43 shared/
                                -rw-r--r--  1 pi   pi        0 Sep 30 19:18 .sudo_as_admin_successful
                                drwx------  3 pi   pi     4096 Nov  5 17:30 .vnc/
                                -rw-------  1 pi   pi       50 Nov  9 17:24 .Xauthority
                                -rw-------  1 pi   pi     8238 Nov  9 19:32 .xsession-errors
                                -rw-------  1 pi   pi     7945 Nov  9 17:24 .xsession-errors.old
                                
                                

                                Slow learner. But trying anyways.
                                MM is on Raspberry Pi 4B w/8gb ram loaded on a 128gb nvme drive.
                                Running Trixie and the latest MM version.

                                1 Reply Last reply Reply Quote 0
                                • mumblebajM Offline
                                  mumblebaj Module Developer @plainbroke
                                  last edited by

                                  @plainbroke Instead of piping the output to a blackhole, maybe pipe it to a logfile which you can interrogate to see why the pm2 start is not working?

                                  Check out my modules at: https://github.com/mumblebaj?tab=repositories
                                  Check my blog-post: https://mumblebaj.xyz/
                                  Check my MM Container: https://hub.docker.com/repository/docker/mumblebaj/magicmirror/general

                                  evroomE 1 Reply Last reply Reply Quote 0
                                  • evroomE Offline
                                    evroom @mumblebaj
                                    last edited by

                                    About /var/log/syslog.
                                    Debian does not use that anymore, already since a while.
                                    As far as I understand it, you will need to get familiar with journalctl.
                                    For cron jobs try this:

                                    $ journalctl --since "1 hour ago" --unit cron.service
                                    
                                    $ journalctl -f -u cron.service
                                    

                                    Happy hunting.

                                    MagicMirror version: 2.33.0
                                    Raspberry Pi 4 Model B Rev 1.5 (8 GB RAM)
                                    Raspbian GNU/Linux 12 (bookworm)

                                    Test environment:
                                    MagicMirror version: v2.33.0
                                    Raspberry Pi 3 Model B Plus Rev 1.3 (1 GB RAM)
                                    Raspbian GNU/Linux 12 (bookworm)

                                    plainbrokeP 1 Reply Last reply Reply Quote 0
                                    • plainbrokeP Offline
                                      plainbroke @evroom
                                      last edited by

                                      @evroom,
                                      I get that nothing is found, when I run either of your suggestions.

                                      @mumblebaj
                                      Explain piping, Please…

                                      Slow learner. But trying anyways.
                                      MM is on Raspberry Pi 4B w/8gb ram loaded on a 128gb nvme drive.
                                      Running Trixie and the latest MM version.

                                      S evroomE mumblebajM 3 Replies Last reply Reply Quote 0
                                      • S Do not disturb
                                        sdetweil @plainbroke
                                        last edited by sdetweil

                                        @plainbroke piping is a technique of stitching together multiple commands to accomplish a task

                                        The vertical bar is called the pipe character
                                        Which takes the output of the left side and presents it as input to the right side , so its like forming a pipe

                                        When I want to find all the MagicMirror processes running in the background I do this

                                        ps -ef
                                        

                                        This give the processes and the command line used to start them
                                        But is a lot of data

                                        So I can filter that with grep , and I can pass in data on its stdin

                                        ps -ef | grep -i MagicMirror 
                                        

                                        That gives just the rows of the process list with MagicMirror on them

                                        But if I want to kill them I need the process id on each row
                                        That’s the second value on each row
                                        I can use the awk command to get that

                                        ps -ef | grep -i MagicMirror | awk ‘{ print $2}’
                                        

                                        Now I have the process ids and can issue the kill command with them

                                        ps -ef | grep -i MagicMirror | awk ‘{ print $2}’ |  xargs sudo  kill -9
                                        

                                        Sam

                                        How to add modules

                                        learning how to use browser developers window for css changes

                                        1 Reply Last reply Reply Quote 0
                                        • evroomE Offline
                                          evroom @plainbroke
                                          last edited by

                                          @plainbroke said in pm2 doesnt work with crontab:

                                          @evroom,
                                          I get that nothing is found, when I run either of your suggestions.

                                          The journalctl -f shows the current activities.
                                          Simular to tail -f <filename>.
                                          So when there are none, you will see none.
                                          Use that when you know that a cron job is going to occur anytime soon.
                                          The --since "1 hour ago" searches for activities in the last hour.
                                          Change to, for example --since "24 hours ago" for activities in the last 24 hours.
                                          When nothing comes out, then indeed nothing happened (during the time period you are searching in).

                                          Other --since options:

                                          "today"
                                          "00:20"
                                          "2025-11-12"
                                          "2025-11-12 07:30:00"
                                          

                                          MagicMirror version: 2.33.0
                                          Raspberry Pi 4 Model B Rev 1.5 (8 GB RAM)
                                          Raspbian GNU/Linux 12 (bookworm)

                                          Test environment:
                                          MagicMirror version: v2.33.0
                                          Raspberry Pi 3 Model B Plus Rev 1.3 (1 GB RAM)
                                          Raspbian GNU/Linux 12 (bookworm)

                                          1 Reply Last reply Reply Quote 0
                                          • mumblebajM Offline
                                            mumblebaj Module Developer @plainbroke
                                            last edited by

                                            @plainbroke Afternoon. What I was saying was that instead of sending your current output to a blackhole, >/dev/null >2&1, i meant sending it to a log file:
                                            30 07 * * 6,0 /usr/local/bin/pm2 start mm >> /home/pi/mon.log 2>&1. This will send the output of the command /usr/local/bin/ pm2 start mm to a log file residing at /home/pi/mof.log. You can then interrogate this log file to see if there were any errors when the command was executed.

                                            So, by pipe I meant redirect the output to somewhere.

                                            Check out my modules at: https://github.com/mumblebaj?tab=repositories
                                            Check my blog-post: https://mumblebaj.xyz/
                                            Check my MM Container: https://hub.docker.com/repository/docker/mumblebaj/magicmirror/general

                                            1 Reply Last reply Reply Quote 0

                                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                            With your input, this post could be even better 💗

                                            Register Login
                                            • 1
                                            • 2
                                            • 3
                                            • 2 / 3
                                            • First post
                                              Last post
                                            Enjoying MagicMirror? Please consider a donation!
                                            MagicMirror created by Michael Teeuw.
                                            Forum managed by Sam, technical setup by Karsten.
                                            This forum is using NodeBB as its core | Contributors
                                            Contact | Privacy Policy