User avatar
Stone Man
Posts: 16
Joined: Tue Nov 10, 2015 10:16 pm

[Guide] Scheduled Reboots: Keep your Pi Fresh!

Mon Nov 16, 2015 2:11 pm

Image

You may notice your Pi becoming more and more sluggish each and every day. Maybe your MicroSD card keeps corrupting. Neither of which are fun, and they may be linked to your uptime. Of course, you could simply restart your Pi each time you go to use it, or maybe after, but there is a much easier solution. The cron command! Cron, an acronym for Command Run On Notice, is already running on your Pi, and you may not even notice! See what I did there? The use of cron is how your Pi knows to check for updates or various other things. With cron, or rather your crontab, you can schedule your Pi to reboot, run a script, open an application, etc., based on a time you set. It's a fairly simple process, and it will do all the work for you after initial setup. Pretty nifty, huh?

Let's begin:
• Open your terminal.
• Enter the following code:

Code: Select all

sudo nano /etc/crontab
• Type your password and hit 'ENTER'. (It will be invisible.)
• Use the down arrow of your keyboard to scroll your cursor down to lowest hash. (#)
• Hit 'ENTER' to lower it, then use your up arrow to edit between them.
• Add the following line:

Code: Select all

0  0     * * *   root    reboot
• Once you are satisfied with the changes, use CTRL+X to exit.
• You will be asked to accept the changes, to which you hit the 'Y' key on your keyboard.
• Finally, hit the 'ENTER' key to accept the default file name.

You are done! Your Pi will now restart every night at midnight, and you'll always be fresh the next day. You can obviously change this to any varying time that is best for you, your pi, or your server. For more about that, read here. Hope I helped!

texy
Forum Moderator
Forum Moderator
Posts: 5156
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Mon Nov 16, 2015 2:47 pm

You just need to be careful about what the pi is actually left on for. If it's not doing anything actively then it should be switched off anyway.
If it's on and doing a task, then this reboot could upset it.......
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
Stone Man
Posts: 16
Joined: Tue Nov 10, 2015 10:16 pm

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Mon Nov 16, 2015 2:54 pm

texy wrote:You just need to be careful about what the pi is actually left on for. If it's not doing anything actively then it should be switched off anyway.
If it's on and doing a task, then this reboot could upset it.......
Texy
This is meant more for those that use their Pi as a desktop computer and would like to come and go as they wish.

Also, the crontab can also be used to start tasks on reboot, so you could restart any task and keep this action.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5757
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Mon Nov 16, 2015 3:05 pm

Stone Man wrote:You may notice your Pi becoming more and more sluggish each and every day. Maybe your MicroSD card keeps corrupting.
This doesn't keep the pi "fresh", it's masking some underlying problem you seem to be having. That just shouldn't be happening.

I would strongly advise against doing this.

User avatar
Stone Man
Posts: 16
Joined: Tue Nov 10, 2015 10:16 pm

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Mon Nov 16, 2015 6:39 pm

Might either of you delete this, then?

I simply created this guide because I had seen a thread with uptime and many seemed low. I'm still waiting to recieve my Pi.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5757
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Mon Nov 16, 2015 7:55 pm

Might be worth keeping for the sake of discussion, didn't mean to dismiss it outright.

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Mon Nov 16, 2015 9:04 pm

ShiftPlusOne wrote:Might be worth keeping for the sake of discussion, didn't mean to dismiss it outright.
This wouldn't be the first time that someone set up their system to automatically reboot because something was causing problems if they didn't reboot regularly. One application that I think "goes nuts", if we can call it that, is Firefox. If it is using a ton of memory because a lot of tabs are open and I close most of them, there isn't always the same behaviour that one would get with that many tabs open after at least restarting Firefox.

User avatar
Stone Man
Posts: 16
Joined: Tue Nov 10, 2015 10:16 pm

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Mon Nov 16, 2015 9:18 pm

It wasn't so much that the usefulness of the guide was dismissed, it was more of the way it was dismissed as if I was doing this PURELY because there was something wrong with my system. Which, again, I have yet to even receive. I made the guide due to things I've seen around the forum about uptime, and about how frequent writing seems to not interact with the cards well. I had assumed a reboot ever so often would help this issue, but I must be wrong.
Last edited by Stone Man on Tue Nov 17, 2015 10:31 am, edited 1 time in total.

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Mon Nov 16, 2015 9:37 pm

It might have been wiser to wait until you had actually owned and used a device.
I'm sure you realise that posts generally appear after people have problems - and they number only a small percentage of Pi owners

User avatar
Stone Man
Posts: 16
Joined: Tue Nov 10, 2015 10:16 pm

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Mon Nov 16, 2015 9:42 pm

fruit-uk wrote:It might have been wiser to wait until you had actually owned and used a device.
I'm sure you realise that posts generally appear after people have problems - and they number only a small percentage of Pi owners
Perhaps I was a bit too hasty in my desire to help in a minuit way.

If I was to alter the name and the post to be a guide on how to automate scripts and such, would an admin be willing to wipe the comments?

RDS
Posts: 712
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Mon Nov 16, 2015 11:01 pm

I for one hope that this thread remains because cron is something that I intend to use but not because of a system problem.
I like the fact that it sounds like it can be used to boot the Pi at a certain time and more importantly for me, run a program.
I do agree though, that the title would be better if it did not just infer it can be used to solve problems.

One application I have for the Pi, is to monitor in detail the output from my Solar Panels, so I had intended to shut the Pi down in the evening but have power applied to it via a timer switch early in the morning (just after sunrise would be ideal) so to have cron run my program at set times would be ideal for me.

User avatar
Stone Man
Posts: 16
Joined: Tue Nov 10, 2015 10:16 pm

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Mon Nov 16, 2015 11:16 pm

RDS wrote:I for one hope that this thread remains because cron is something that I intend to use but not because of a system problem.
I like the fact that it sounds like it can be used to boot the Pi at a certain time and more importantly for me, run a program.
I do agree though, that the title would be better if it did not just infer it can be used to solve problems.

One application I have for the Pi, is to monitor in detail the output from my Solar Panels, so I had intended to shut the Pi down in the evening but have power applied to it via a timer switch early in the morning (just after sunrise would be ideal) so to have cron run my program at set times would be ideal for me.
I'm glad you find cron useful. It's pretty neat.

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Tue Nov 17, 2015 4:35 am

RDS wrote:I for one hope that this thread remains because cron is something that I intend to use but not because of a system problem.
I like the fact that it sounds like it can be used to boot the Pi at a certain time and more importantly for me, run a program.
In order for cron to do anything the Pi has to be running!
One application I have for the Pi, is to monitor in detail the output from my Solar Panels, so I had intended to shut the Pi down in the evening but have power applied to it via a timer switch early in the morning (just after sunrise would be ideal) so to have cron run my program at set times would be ideal for me.
That's more realistic.

User avatar
DougieLawson
Posts: 35519
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Tue Nov 17, 2015 8:57 am

If you want automated power down and restart for the RPi look at WittyPi.
http://www.uugear.com/witty-pi-realtime ... pberry-pi/

It has an external microcontroller and a real time clock.

BTW, there's no need to periodically restart your RPi unless you need to install a new Linux kernel. Two of my RPis have been running for more than 160 days. It's not like a Microsoft Windows system.
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
RaTTuS
Posts: 10365
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Tue Nov 17, 2015 9:17 am

DougieLawson wrote:I..... It's not like a Microsoft Windows system.
no need to bash windows anymore - I have windows systems that stay up as long as my linux systems
the only time I have to reboot linux is to free zombie tasks [another story], and windows when the system decides to lock files [that is probably down to windows zombie tasks]

scheduled reboot are not necessary though if there is a problem it may be easier to reboot than to find out what has happened - this is not the right way but YMMV
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

User avatar
DougieLawson
Posts: 35519
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Tue Nov 17, 2015 10:34 am

I'd guess you haven't upgraded to Win10. That gets unstable to the point of unusability every Tuesday/Wednesday for more than an hour when the weekly update comes down the wire. Hopefully, the size of those update packages will tail off as it becomes more stable.
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

FlyTT14
Posts: 9
Joined: Thu Mar 24, 2016 4:08 pm
Location: Norway

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Mon May 16, 2016 6:56 pm

Stone Man wrote: You may notice your Pi becoming more and more sluggish each and every day. Snip/Cut...
Thanks Stone Man :)
I have a five Pi's running plain tracker software and with heavy load I have see that for some reason they just stop tracking
I have not been able to find out what's go wrong but a manual restart have solved it.
(It might be the RTL dongle that need a power cycle)
Thanks to your tips I give them all a restart every night and no problem has been detected after this

--
Lasse

starcrouz
Posts: 1
Joined: Wed Jan 04, 2017 11:11 pm

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Wed Jan 04, 2017 11:43 pm

Just for the records, the method described at the beginning of this thread doesn't work with Raspbian Jessie.

What worked for me was :
> sudo crontab -e
typing "enter" the first time (to chose Nano as editor).
adding this line at the end of the file : (reboot at 23:06 everyday)
6 23 * * * /sbin/shutdown -r now
saving by typing ctrl + X and "yes"
You should read :
> crontab: installing new crontab

If it doesn't work just modify the line (and read the content of cronlog.txt to see the error after 23:06 o'clock)
6 23 * * * /sbin/shutdown -r now >> /home/pi/cronlog.txt

Hope it helps.

PS : I'm using this method with a RPi 3 with only Homebridge (an Apple Homekit gateway) and one plugin homebridge-eedomus installed. The RPi stops working after no more than 3 days... I'm not able to fix these projects code but I like a lot what they achieve : making my non Apple Homekit appliances (lights, tv, tv box, netatmo...) voice commandable with Siri on my phone. That is for the "why".

User avatar
ReverseEMF
Posts: 3
Joined: Sun Mar 12, 2017 3:02 pm
Location: Utah
Contact: Website

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Sun Mar 12, 2017 3:15 pm

This doesn't keep the pi "fresh", it's masking some underlying problem you seem to be having. That just shouldn't be happening.

I would strongly advise against doing this
In my case, the "underlying problem" is a lack of RAM (only half a gig). I'm running a webcam on a Raspberry Pi B+ and every few days the thing locks up. So, I'm going to try a crontab reboot once a night.
Your mind is tricking you into believing this is more than just a bunch of strategically arranged dots.

masterkenobi
Posts: 2
Joined: Sun May 22, 2016 3:49 am

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Tue Apr 18, 2017 2:03 am

starcrouz wrote:Just for the records, the method described at the beginning of this thread doesn't work with Raspbian Jessie.

What worked for me was :
> sudo crontab -e
typing "enter" the first time (to chose Nano as editor).
adding this line at the end of the file : (reboot at 23:06 everyday)
6 23 * * * /sbin/shutdown -r now
saving by typing ctrl + X and "yes"
You should read :
> crontab: installing new crontab

If it doesn't work just modify the line (and read the content of cronlog.txt to see the error after 23:06 o'clock)
6 23 * * * /sbin/shutdown -r now >> /home/pi/cronlog.txt

Hope it helps.

PS : I'm using this method with a RPi 3 with only Homebridge (an Apple Homekit gateway) and one plugin homebridge-eedomus installed. The RPi stops working after no more than 3 days... I'm not able to fix these projects code but I like a lot what they achieve : making my non Apple Homekit appliances (lights, tv, tv box, netatmo...) voice commandable with Siri on my phone. That is for the "why".
It works wonderfully on my RPi3. Now I am wondering how do I change the time or delete it after it is created?

Ntreacy93
Posts: 2
Joined: Tue Apr 18, 2017 7:16 pm

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Tue May 02, 2017 1:52 pm

Hi,

Can anyone tell me how to schedule a shutdown command and reboot command for the raspberry Pi using the GUI?

User avatar
DougieLawson
Posts: 35519
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Wed May 03, 2017 6:08 am

Open an LXterminal window
sudo shutdown -r 21:00[enter]
and your RPi will reboot at 9:00pm local time.
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

norrillous
Posts: 1
Joined: Mon Aug 28, 2017 5:50 pm

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Mon Aug 28, 2017 5:55 pm

Is there a log file that shows when this executes? Or can it write a time stamp in a text file after it is executed?

User avatar
DougieLawson
Posts: 35519
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Tue Aug 29, 2017 2:32 am

/var/log/messages /var/log/syslog /var/log/kern.log all have evidence of when your system reboots.

You can also use uptime and uptime -s commands to see when a restart happened.
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

tdragovich
Posts: 4
Joined: Mon Mar 17, 2014 4:55 am

Re: [Guide] Scheduled Reboots: Keep your Pi Fresh!

Tue Jun 19, 2018 4:49 pm

First, thank you for sharing. I have setup a raspberry pi zero w as a Google cloud print server. I regulate the times internet is available and turn off the wifi router at "Bedtime". Due to this I had been experiencing an issue where the printer is not available after this disconnect. It is easier to have a scheduled reboot than to log in remotely and reconnect the server.

Good, bad, or ugly this guide fits my situation. So all the haters need to back off of op. I have never in the last five years seen a community of pi that have provided this much hate. OP, great job.

Return to “Beginners”