Why is my @reboot cron job not working on my Raspberry Pi?

0
35
Asked By CuriousCoder42 On

I'm trying to set up a cron job on my Raspberry Pi that starts a Podman container at reboot. My crontab has a line like this: `@reboot podman container start dbbb4c810bef`. However, this isn't working, even though running the command directly in the terminal works perfectly. I don't have any encrypted volumes. After some digging, I discovered that adding a delay fixed the issue since the command was executing too early. I changed it to `@reboot sleep 60; /usr/bin/podman container start dbbb4c810bef`. Any thoughts on what might have gone wrong initially?

4 Answers

Answered By OldSchoolUnix On

Don't forget about root privileges! You need to ensure your cron job has the required permissions. You could use `sudo crontab -e` to edit the root crontab. Just make sure you specify the exact path for commands like `/usr/bin/systemctl reboot` or similar.

Answered By TechieJoe89 On

Have you checked if the cron service is running? Sometimes, using the full path to your command can help, like `/usr/bin/podman` instead of just `podman`. It might not find the command without the full path. Glad to hear the sleep command worked for you in the end!

PracticalPi -

Yeah, the cron service was fine, and I tried the full path too. It was just running too early—so the delay was definitely the trick!

Answered By ContainerNinja On

I’ve heard that crontab jobs can sometimes misbehave if they run before certain services are up. Using something that waits or setting it up as a systemd service sounds like a solid solution, especially for reliability.

Answered By SystemSage On

Instead of cron, have you considered creating a systemd service? It's often more reliable than using cron's `@reboot`. Many recent distros prefer systemd timers because they can handle dependencies better. If you want, I can help you look into it!

CuriousCoder42 -

That sounds interesting! I fixed the cron issue for now, but if there's a better way, I'm definitely open to trying systemd.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.