Read the statement by Michael Teeuw here.
Starting MM Crontab
-
Hi.
I have been using crontab to start my MM for ages and it has always worked well. After updating it no longer seems to work. cron calls a script that has the following.
cd ~/MagicMirror DISPLAY=0 npm startNow, I have seen that it is suggest to use
node --run start:X11going forward and I have updated my start script with same but that does not seem to work either.So my
mm.shnow looks like,cd ~/MagicMirror DISPLAY=0 node --run start:X11But as mentioned, this does not work.
Any ideas?
-
@mumblebaj said in Starting MM Crontab:
DISPLAY=0 node --run start:X11
It should be
start:x11and notstart:X11.Are you still using X11?
Does it run when you start it manually?
Can you provide the logs from the startup?
-
@KristjanESPERANTO Sorry, typo, it is lower
x. It start when I manually runnpm start. When I manually runnode --run start:x11it works fine. When I manually run the script./mm.shit works fine. When calling it from the cron nothing. In my log I see the commandnode --run start:x11but MM does not launch. -
@mumblebaj is the cron jon in the user crontab (contrab -e) ? or root (sudo crontab -e) ?
if root, the pm2 job doesn’t exist there, it opnly exists under user who created the pm2 job
-
@sdetweil in my user,
crontab -e. It worked just fine until I updated my mirror this morning. I don’t use pm2 on my installation for my own reasons… 😉 -
@mumblebaj said in Starting MM Crontab:
It worked just fine until I updated my mirror this morning.
only MM update?
note that we changed the startup strings.
“start”: “node --run start:x11”,
-
@sdetweil Yep, only MM update. Let me try
start: node --run start:x11and see what happens. -
@mumblebaj Just an idea: Maybe the node version used in Cron could be to old. When you run a script manually in your terminal, your full user environment (including things like .bashrc or .zshrc) is loaded. Cron runs in a much more minimal environment — it often doesn’t load your shell config files, so tools like nvm (Node Version Manager) might not be available.
How to fix it:
- Use the full path to Node: Find it with
which nodeand use that path in your cron job. - Set the environment manually in cron: You can define your PATH at the top of the cron file.
- Source nvm in your script: If you use nvm, add source
~/.nvm/nvm.shandnvm use <version>before calling node.
- Use the full path to Node: Find it with
-
@KristjanESPERANTO Thanks Kristjan. But I don’t see how updating MM could cause this. I only updated MM with Sam’s upgrade script. Don’t see how that has changed anything with regards to how Crontab works. Maybe it is related to changing the launch to
node --run start. I can see the command being fired in the log but it does not launch MM like it did before the upgrade.Anyhow, I manually launch it for now till I find a suitable solution.
-
@mumblebaj did you use npm start before?
it ‘may’ be the path as @KristjanESPERANTO mentioned
so from the user command line do
which node
and use that result in the cron command
-
@sdetweil Hi Sam. I have always used npm. I have just been reading through the PR-3764 and i agree with your arguments in that it could have breaking affects for how we do things as both users and devs. Case in point.
However, the forum is about new things and moving forward, so I agree with @KristjanESPERANTO on that point of view as well.
I have now resolved my script issue and am now able to launch from the cron again. 😉
For somebody who may have the same issue, this is how I solved for it.
export DISPLAY=:0 cd ~/MagicMirror npm run start:x11The above has solved it for me now.
-
@sdetweil Stupid question, how do I mark this as resolved?
-
@mumblebaj you didn’t open it as an issue, so it can’t be resolved
Normally 3 dot menu right of selected post
-
@mumblebaj what do you think fixed your problem?
DISPLAY is set in package.json if not already
folder of course -
@sdetweil A few things:
The main issue being:
MagicMirror is now using a flat npm config, and the start scripts are handled differently,node --run start:x11is not a valid Node.js command — unless you are using a custom wrapper or an internal script, this will fail silently or do nothing.As Crontab runs in a minimal environment, so any graphical (X11) application must explicitly export DISPLAY. Previously I had the command as
DISPLAY=:0 npm start. Now, I had toexport DISPLAY=:0first and then start MM.
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