What's new

halt the router through cronjob

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

slytho

Regular Contributor
Hi!

If I type "halt" in a shell, it works as expected and the router halts itself (I know, it's not totally powered off).

But if I add "halt" to a cronjob, it doesn't halt the router but performs an unwanted reboot at the given time:
Bash:
cru a Shutdown "30 2 * * * halt"

Is there something wrong with the cronjob command? How can I make it halt instead of reboot the router?
 
Can’t answer why the halt doesn’t work in a cronjob, but be careful with “halt” of you have any storage devices connected or some scripts running. It really does “halt” so I don’t believe it does any clean unmounts of storage or call some of the various “stop” scripts.

I too wish there was a service halt command in addition to service reboot.

Every once in a while I want to power off the router to do something. I used to use “halt” but ended up with some scripts not starting correctly after power on.
I now do a service reboot and watch and wait for all the leds to go off - then power down…
 
BTW, try:

cru a Shutdown "30 2 * * * exec halt"

Not sure it will work - I can’t test it on my home router ;-)
 
... so I don’t believe it does any clean unmounts of storage or call some of the various “stop” scripts.
It does actually. That was my initial concern so I've just checked it again on my RT-AX86U having previously checked it a few years ago on my RT-AC68U.

That said, there are probably subtle differences beyond which user scripts are called (or in what order). So YMMV, especially when it comes to third party addon scripts.
 
Last edited:
Hi! I haven't encountered problems here with 'halt' yet - at least when I run it manually :p But I'm sure I don't use as advanced scripts or services as you probably do.

I use 'halt' mostly hoping to unmount drives correctly - yes, I have got an external ssd attached. As said, no problems with invalid data or broken file systems so far. And I once saw an entry in the syslog saying "Emergeny sync" or so after I ran 'halt'. So that is at least better than powering it off without halting it first.

But it would be awesome to have an automated way to let cru halt the router and not only reboot it. Will check your hint tonight. :)
 
Erm ... one more question: how can I reload changed cru settings without rebooting the whole router?
 
Is it possible the halt state is hitting some time limit and rebooting the router?
 
Erm ... one more question: how can I reload changed cru settings without rebooting the whole router?
I'm not sure what you mean by "reload". If you want to change an existing crontab entry just delete it and recreate it.
 
I'm not sure what you mean by "reload". If you want to change an existing crontab entry just delete it and recreate it.
Hhm, ah I see. Thank you. I assumed it was something like a service that needs to be restarted/reloaded to take effect. Never mind.
 
@slytho If the "exec" method above doesn't work try this, which is basically what the halt command does.

Code:
cru a Shutdown "30 2 * * * sync; kill -QUIT 1"

I can't say that I like this method as there's no guarantee that Asus might not change things in the future. Even now it may not work on some models.
 
Alright, was able to conduct some testing ... and

Code:
kill -QUIT 1
does the job
! Awesome! 🥳 This really takes some hassle from me each night when I'm here. Thank you very much for that hint! 👍

"exec halt" by the way didn't have any effect as a cronjob (only when running it manully at the command line).

So, I'll add a cru like that:
cru a Shutdown "30 2 * * * sync; kill -QUIT 1"

note for other readers: adding "sync" to the cron job is advisable because there is no "halt" command anymore that usually runs a sync itself.

Why "halt" doesn't work, i.e. conducts a reboot, when used in a cronjob remains unclear. Just an idea: maybe halt sends the signal TERM (15) instead of QUIT (3)? I've tried it. TERM leads to a reboot, QUIT to a halt of the router.
 
Last edited:
What is halt good for? The router has to be power cycled after, no?
 
What is halt good for? The router has to be power cycled after, no?
I am trying to figure out the end game too.... In my case, when UPS NUT sends an "I am almost dead" alarm, I use sync;sync;halt just to put the router into a state ready for the power to be yanked! :)

Will have to play around with the kill method.
 
Will have to play around with the kill method.
As I alluded to in post #10 I wouldn't recommend this method unless you have no other choice. If halt works for you then keep using it. The problem is that halt doesn't work for the OP (and me) when called from the crontab. You can see what's happening if you look at init.c.
 
As I alluded to in post #10 I wouldn't recommend this method unless you have no other choice. If halt works for you then keep using it. The problem is that halt doesn't work for the OP (and me) when called from the crontab. You can see what's happening if you look at init.c.
Thanks Colin. I'll stick to what I got.
 
Yup :) Works perfect for me now.
exec halt or kill -QUIT 1?

I have been reading through some of the code. The halt command is actually a link to Asus rc. So it has knowledge of the firmware.
kill is linked to busybox and doesn’t really know about things like nvram, firmware stuff.
 
exec halt or kill -QUIT 1?

I have been reading through some of the code. The halt command is actually a link to Asus rc. So it has knowledge of the firmware.
kill is linked to busybox and doesn’t really know about things like nvram, firmware stuff.
The fact that kill is a busybox command is irrelevant in this case. kill -QUIT 1 is sending SIGQUIT to process 1 (init). Which is what the halt command does via rc.c and init.c.


It's reentrant code that branches based on the signals being sent to it. I'm still not sure why there's a difference between running halt from cron and the command line. I think I know what's happening but it was making my head hurt thinking about it.
 
Last edited:
Too many #ifdefs. My head hurts as well…
All I care about is making sure Entware/External USB/Addons are safe and synced before turning off the power.
Asus rightly assumes no Entware, No addons and their databases - the ”normal home user”.
Turning the router off is fine - everything gets rebuilt/restored on power up.

It’s us us “techie” users that have to deal with this…
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top