What's new

Router shutdown script

  • 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!

Oracle

Regular Contributor
I know there's no shutdown command because *reasons* but I need a way to safely turn off the router.
I have now more than 1 USB drive attached and several addons accessing attached storage, besides the original services.
I'm looking for a script to stop services and unmount drives, so I don't discover the wheel trying to write it myself. :)
 
I can't try it now because I have stuff going on, but have you tried "halt"? The command exists, but I don't know how safely it shuts things down. On a normal Linux distro like Ubuntu it does a safe shutdown.
 
I usually issue the following commands on my router upon a imminent shutdown notification from my UPS. The sync commands help ensure any data is flushed to disk before power loss.

Code:
sync;sync;halt
 
It depends on the model. Most of them don't have the ability to "power off". You can invoke a shutdown/halt but the router doesn't terminate the power.
 
It depends on the model. Most of them don't have the ability to "power off". You can invoke a shutdown/halt but the router doesn't terminate the power.
Yes, I should have added that fact. The sync/halt is only meant to prepare for the rug to be pulled out of under the router when the UPS dies. In fact, I don't know any ASUS router that has is able to power down.
 
This sounds fragile for data storage. I would be prepared for disaster recovery... have a backup plan.

OE
 
In fact, I don't know any ASUS router that has is able to power down.
You're probably right. I thought I remembered someone having a router that powered off, but thinking about it a bit more I think that was a hardware fault rather than a feature.
 
sync;sync;halt
I'll take this as best answer to date. :)
And it's familiar.
I'll even set the LEDs off for added visual fun. Of course power will stay on, waiting for unplug.
 
I have now more than 1 USB drive attached and several addons accessing attached storage, besides the original services.

You're looking for trouble. The router is not a NAS replacement and was never designed to be.
 
You're looking for trouble. The router is not a NAS replacement and was never designed to be.
Is the feature unreliable? I figure for a lot of people it'd be handy to be able to plug a few drives into their router to make them accessible on the network, especially for backups and such, if they don't have a PC that's always on to act as a file server.
 
I can crash this router without touching it with file transfers. Any firmware version Asuswrt or Asuswrt-Merlin. This is how reliable it is. For light file shares is okay, but if you push it a bit harder thinking you've got a cheap NAS - it goes down, including main services like WAN connection and Wi-Fi.
 
I do run samba on my router, but only for transient file transfers. I have another NAS for the heavy haul stuff. I do have a reverse proxy server on the router for my other network services. For me, just setting the router in a cozy state before the UPS turns off just lessons the possibility of USB drive/entware problems. My shut down script also remote shut down three other linux machines. That little 32gb no name USB drive has been going 4 years non stop now. I do have a 30 day rotating backup, which happens nightly (for jffs and USB key), but touch wood have not had to use it.
 
Hello,

I am running PostgreSQL on an AC88U router.

It started as a simple test, but I plan to keep using it.

Would it be meaningful to execute `/jffs/scripts/service-stop` before running the `sync; sync; halt` command?
 
Would it be meaningful to execute `/jffs/scripts/service-stop` before running the `sync; sync; halt` command?
There's no such script as service-stop so I assume you mean services-stop.

Last time I checked, issuing the halt command automatically runs services-stop and unmount. But that may have changed so check it on your router.

Entware services normally have start and stop scripts in /opt/etc/init.d which are called from the mount and unmount scripts.
 
Last edited:
Hello,

I am running PostgreSQL on an AC88U router.

It started as a simple test, but I plan to keep using it.

Would it be meaningful to execute `/jffs/scripts/service-stop` before running the `sync; sync; halt` command?

The services-stop script gets called by the OS, usually during a reboot sequence. That script is not likely to be called on a halt command.

If your objective is to safely shutdown PostgreSQL, you can call the PostgreSQL init.d unit script with "stop" as an argument to shutdown PostgreSQL before halting the router.
 
Sure, we're not over thinking this? You can unmount the drives using the GUI and then remove them if necessary, or even at that point just turn the router off!
 
Sure, we're not over thinking this? You can unmount the drives using the GUI and then remove them if necessary, or even at that point just turn the router off!
Ha! True enough....

I guess I was thinking on the lines of automated shutdown on a signal from a UPS that the gig is up (battery exhausted). Maybe I am overthinking it.
 
I used a translation tool (GPT) for this, so if you find the content overly complex or unclear, please let me know, and I’ll be happy to revise it to make it easier to understand. Also, I always appreciate feedback on my English for learning purposes!

I think my initial question may have been a bit brief.

To explain in more detail, `/jffs/scripts/services-stop` runs `/opt/etc/init.d/rc.unslung stop`. So, if `halt` automatically executes `services-stop`, I wouldn’t need to run `services-stop` manually. I was curious about how `halt` actually functions.

Additionally, based on Crimliar’s comment, it seems that unmounting the drive from the GUI ensures that the data is safely closed. Does this mean that the unmount process automatically stops services using the storage? (It seems unlikely that the router would manage this automatically.)

Since I’m using both a database and transmission, I’m looking for a safe way to shut everything down before powering off the router.

From all the answers, it seems the conclusion I’ve reached is that, to safely preserve the data for both the database and transmission, I must run `services-stop` before executing `halt` and send a signal to stop the services before physically cutting the power.

Does this conclusion sound correct to you?
 
Common theme in many of my posts - I'm a bit lazy and so will try to use the quickest/easiest way to do a thing! For absolute peace of mind, I'd probably be stopping the services and then using the GUI to eject the media - as the router could still be writing to it thanks to other processes. Oh and I'm an absolute wizard at destroying USB flash drives by doing stupid things with them - so maybe get a second opinion on all of this!
 

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