Pitel
Posts: 25
Joined: Fri Jun 22, 2012 1:37 pm
Location: Brno, CZE
Contact: Website Facebook Google+ Skype Twitter YouTube

Cron reboot does not work

Tue Feb 26, 2013 11:36 am

Because of known issue with unstable USB (ethernet stops to work after about 1 day) I decided to simply reboot my Pi every 12 hours. So I did

Code: Select all

sudo crontab -e
and put the folowing line to it:

Code: Select all

0 */12 * * * /sbin/reboot
But it dees not work! Right now, I am compiling node.js from source, and all I saw is

Code: Select all

Broadcast message from root@raspberrypi (Tue Feb 26 12:00:01 2013):

The system is going down for reboot NOW!
but the compilation keeps running and uptime is now over 24 hours, which should not be possible!

But nginx and php5-fpm services are stoped every 12 hours.

Any idea what's going on? Running reboot from ssh session manully works ok.

User avatar
RaTTuS
Posts: 10558
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Cron reboot does not work

Tue Feb 26, 2013 11:43 am

make sure you are running that as the root cron and not a normal user
I'd use
/sbin/shutdown -r now

also see what it says in syslog when it runs

[tail -f syslog]
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

Pitel
Posts: 25
Joined: Fri Jun 22, 2012 1:37 pm
Location: Brno, CZE
Contact: Website Facebook Google+ Skype Twitter YouTube

Re: Cron reboot does not work

Tue Feb 26, 2013 11:48 am

I tried the /sbin/shutdown -r now method since yetserday, and result is the same. This is /var/log/syslog:

Code: Select all

Feb 26 12:00:01 raspberrypi /USR/SBIN/CRON[22057]: (root) CMD (/sbin/shutdown -r now)
Feb 26 12:00:01 raspberrypi shutdown[22058]: shutting down for system reboot
Feb 26 12:00:12 raspberrypi init: Switching to runlevel: 6
Feb 26 12:00:12 raspberrypi ifplugd(eth0)[1410]: Exiting.

banana
Posts: 3
Joined: Mon Mar 11, 2013 10:10 pm

Re: Cron reboot does not work

Mon Mar 11, 2013 10:27 pm

I know this is a bit old but people may come across this problem in 2013 as well...

The syslog is correct, everything is fine. The cron job is launched correctly.

So it looks like a process or a faulty init.d script is preventing the Pi to reboot.

What you can do to solve the problem:

a) identify that process (best solution)
b) shutdown -r now; sync; reboot -f (should work but this may hurt)
=> the "-f" argument almost does the same as plugging the Pi off and on again. Only use it if it's really needed, and after trying to shut it down correctly. The "sync" command is to synchronize hard drives and prevent data loss and data corruption.

User avatar
skidoobond
Posts: 40
Joined: Mon Feb 25, 2013 8:26 pm

Re: Cron reboot does not work

Wed Mar 13, 2013 11:39 pm

Create a file (mine is called rboot.sh) and put in it "sudo reboot". Use chmod to make it executable. Then use crontab -e with:
* */12 * * * /yourpath/rboot.sh

Replace /yourpath/ with the path to the file you created. This works as the pi (default) user as well.

Pitel
Posts: 25
Joined: Fri Jun 22, 2012 1:37 pm
Location: Brno, CZE
Contact: Website Facebook Google+ Skype Twitter YouTube

Re: Cron reboot does not work

Fri Mar 15, 2013 8:27 am

I found a cause of this!

Redis server, installed with this script.

Removing those created initscripts, and RPi reboots without any problem.

Maybe I'll report it as a bug to them...

EDIT: https://github.com/antirez/redis/issues/1007
Last edited by Pitel on Fri Mar 15, 2013 12:18 pm, edited 1 time in total.

ski522
Posts: 394
Joined: Sun Sep 30, 2012 2:22 pm

Re: Cron reboot does not work

Fri Mar 15, 2013 9:48 am

I just use a script that I run every 15 minutes from a cron job which only reboots the Pi if it has too

Code: Select all

#!/bin/sh

# cron script for checking wlan connectivity
IP_FOR_TEST="192.168.1.1"
PING_COUNT=1

PING="/bin/ping"
IFUP="/sbin/ifup"
IFDOWN="/sbin/ifdown --force"

INTERFACE="eth0"

FFLAG="/opt/check_lan/stuck.fflg"

# ping test
$PING -c $PING_COUNT $IP_FOR_TEST > /dev/null 2> /dev/null
if [ $? -ge 1 ]
then
    logger "$INTERFACE seems to be down, trying to bring it up..."
        if [ -e $FFLAG ]
        then
                logger "$INTERFACE is still down, REBOOT to recover ..."
                rm -f $FFLAG 2>/dev/null
                sudo reboot
        else
                touch $FFLAG
                logger $(sudo $IFDOWN $INTERFACE)
                sleep 10
                logger $(sudo $IFUP $INTERFACE)
        fi
else
#    logger "$INTERFACE is up"
    rm -f $FFLAG 2>/dev/null
fi

banana
Posts: 3
Joined: Mon Mar 11, 2013 10:10 pm

Re: Cron reboot does not work

Sat Mar 16, 2013 7:14 pm

Pitel wrote: Removing those created initscripts, and RPi reboots without any problem.
Nice, so it looks I was right. People having this kind of problem with some daemons shutting down and other which aren't, are facing the same situation.
If this happens on your Pi, plug a screen to it to see what is failing. (It may be possible to log the boot / shutdown sequence, but I have no idea how.)

Please stop posting useless answers. Putting "sudo reboot" in a script or a cron job won't help!
Workarounds like this (supposing it worked) are often a bad idea because the original problem isn't solved, so I bet at next update has to be faced again.

User avatar
skidoobond
Posts: 40
Joined: Mon Feb 25, 2013 8:26 pm

Re: Cron reboot does not work

Thu Apr 11, 2013 5:10 am

@banana - If you are referring to my post as "useless", I have to disagree. It specifically fixes the OPs solution to a usable state. I made no claim as to a "correct" fix as to why he needed to reboot. My interpretation was to get his solution to work, which on my Pi, does.

banana
Posts: 3
Joined: Mon Mar 11, 2013 10:10 pm

Re: Cron reboot does not work

Thu Apr 11, 2013 7:49 am

Sorry but your post didn't help at all.

The OP never said it solved the problem. The cause was a program he installed which was preventing from rebooting (as I thought).

User avatar
skidoobond
Posts: 40
Joined: Mon Feb 25, 2013 8:26 pm

Re: Cron reboot does not work

Fri Apr 12, 2013 6:44 pm

OP "Because of known issue with unstable USB (ethernet stops to work after about 1 day) I decided to simply reboot my Pi every 12 hours. So I did Code:.... and put the folowing line to it: Code:.... But it dees not work!"

I see no mention of him installing or running other code. This to me suggested he was having a problem with cron not rebooting his pi, which was the reason for my reply.

AaronCompNetSys
Posts: 3
Joined: Sun Jul 14, 2013 7:38 pm

Re: Cron reboot does not work

Sun Jul 14, 2013 7:40 pm

Just thought I would stop by to report the same issue, my resolution was to use "/sbin/shutdown -r now" instead of "reboot". Added to the root user's crontab.

zanco
Posts: 24
Joined: Fri Dec 07, 2012 1:38 pm

Re: Cron reboot does not work

Sat Aug 17, 2013 5:20 pm

ski522 wrote:I just use a script that I run every 15 minutes from a cron job which only reboots the Pi if it has too

Code: Select all

#!/bin/sh
[/quote]

Thanks ! After 30 days online my Pi went offline again. I copied your script and now the Pi only should reboot if it goes offline..


Kind regards,
Ben

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: Cron reboot does not work

Sat Aug 17, 2013 5:41 pm

Am I the only one you edits the /etc/crontab file and tells it to use the root user ?

Always works for me.
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

darren.enns
Posts: 1
Joined: Wed Jan 08, 2014 1:45 am

Re: Cron reboot does not work

Wed Jan 08, 2014 1:48 am

ski522 wrote:I just use a script that I run every 15 minutes from a cron job which only reboots the Pi if it has too

Code: Select all

#!/bin/sh[/quote]

Can someone assist me with understanding where I would run this script? I'm a noob to this and haven't a clue where to create and save this script. Is it inside the Cron file?

User avatar
DougieLawson
Posts: 38883
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Cron reboot does not work

Wed Jan 08, 2014 7:00 am

darren.enns wrote:
ski522 wrote:I just use a script that I run every 15 minutes from a cron job which only reboots the Pi if it has too

Code: Select all

#!/bin/sh[/quote]

Can someone assist me with understanding where I would run this script? I'm a noob to this and haven't a clue where to create and save this script. Is it inside the Cron file?[/quote]
The best place to put locally written scripts is in /usr/local/bin (same for programs) 

Use sudo nano /usr/bin/netcheck.sh copy the code from the forum, paste it in and save it.

Then change the permission bits to make it executable. sudo chmod 755 /usr/bin/netcheck.sh

Then sudo crontab -e and add the lines to run every 15 minutes.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Fanch
Posts: 2
Joined: Fri Mar 20, 2015 2:13 pm

Re: Cron reboot does not work

Fri Mar 20, 2015 2:18 pm

skidoobond wrote:Create a file (mine is called rboot.sh) and put in it "sudo reboot". Use chmod to make it executable. Then use crontab -e with:
* */12 * * * /yourpath/rboot.sh

Replace /yourpath/ with the path to the file you created. This works as the pi (default) user as well.
My root account is deactivated for security reason, and I wasn't able to make the other answers working.
So the only solution for my configuration that works is yours, thank you.
(but I'm not expert in Linux)

iaing4dpf
Posts: 1
Joined: Thu Mar 23, 2017 7:02 pm

Reboot.sh

Thu Mar 23, 2017 7:08 pm

Hi All

This detection of connectivity and reboot if not is just what I've been looking for.

I have the script installed and when I test it I get

Touch: cannot touch ‘/opt/check_lan/stuck.ffg’: no such file or directory

Please can someone give me a hint as to what I've done incorrectly
I am a newbie !
Thanks Iain

Return to “Troubleshooting”