What's new

Possibilities to trigger storage ejection remotely? (a more graceful hard shutdown/reboot)

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

Aziron5

Regular Contributor
Hi

An industrial place is experiencing frequent losses of power but more than half of them is voluntary because of repairs, manufacturing, testing and they just hit the main breaker ... the employees know how to shutdown the PCs, but they don't have a quick way to shutdown the networking stuff.

Thankfully, a Mikrotik LTE antenna which does seem to be more intolerant of ungraceful shutdowns because it screams about it in the logs, unlike routers, and does indeed support a graceful programmatically triggered shutdown which I was able to quickly work into a script that can be triggered by SMS from a phone, which solves the problem for one of the networking devices completely. The Asus Router remains.

In most optimal possible situation, I'd still like to have a more graceful shutdown, just to be extra sure, I am, and neither there are any IT specialists on premises, I wouldn't be able to resolve anything remotely if things break with the router in a major way.
Normally this wouldn't be an issue, as shutting down Routers by just cutting power doesn't seem to be that of an issue, potentially creating permanent errors. Though in general I still disagree with the whole design having no concept of a graceful shutdown.

However this Asus router is running external storage, entware, scripts, diversion etc., and that is a problem, I've had disk check report issues in past, they happened to be resolved. Cutting power to a mounted filesystem is ofcourse not a good thing in linux in general and I've had enough experience with multiple distros.

The creator of AsusWrt-Merlin explained in the past that ejecting storage would then trigger a graceful shutdown of diversion, entware, scripts an a proper unmount of the filesystem and the external storage device, flushing caches, the usual stuff.

So the logical next step is to find a way to more conveniently remotely trigger a storage ejection for Asus Merlin FW ... if I could somehow combine the SMS triggered script functionality of the LTE Antenna providing WAN for this router.

Thanks a lot for ideas.
 
Use the /sbin/ejusb command.

Right, thanks, now I can do that relatively easily, but non-techy people probably won't be to eager to go bother with ssh/login ... still too many steps.

Also is there a command that can check presence of USB storage, there has to be something that lists mounts, but to get a quick and specific answer and not have to look all the non-external mounts ... perhaps I would just check for the path, and end up creating a custom script, checking if, if present eject, then confirm/report result whether it's successful (as linux utilities seem to have zero output if actions succeed, one major thing I disagree with in the linux philosophy)
 
The mount command combined w/ a regular expression should be sufficient to determine if something is mounted.

Code:
mount | grep -q '^/dev/sda1 ' && echo 'mounted'

As far as end-users, it should be a simple matter to configure a local script (Windows or Linux) to execute a remote Linux script using ssh and private/public keypairs to avoid manual login.
 
The mount command combined w/ a regular expression should be sufficient to determine if something is mounted.

Code:
mount | grep -q '^/dev/sda1 ' && echo 'mounted'

As far as end-users, it should be a simple matter to configure a local script (Windows or Linux) to execute a remote Linux script using ssh and private/public keypairs to avoid manual login.

Thanks, I'll take the advice and look deeper into it.

I'm familiar with Termux, and all of the employees have Android-based phones, so it should be very simple to install it and then tell them to perhaps just launch a Shortcut which triggers a Termux (linux) script on the phone, which would use SSH and the private/public keypairs method (which I've yet to familiarize on) to login onto the Router via WiFi (in this case it's turned on for conveniences, althought all of the key infractructure relies on ethernet), and then trigger a secondary script there. Makes sense right?

Now this is interesing, it wouldn't be just for them, I'd be really glad to have such a convenience for myself as well at mine and other locations.
 
Hi

An industrial place is experiencing frequent losses of power but more than half of them is voluntary because of repairs, manufacturing, testing and they just hit the main breaker ... the employees know how to shutdown the PCs, but they don't have a quick way to shutdown the networking stuff.

Thankfully, a Mikrotik LTE antenna which does seem to be more intolerant of ungraceful shutdowns because it screams about it in the logs, unlike routers, and does indeed support a graceful programmatically triggered shutdown which I was able to quickly work into a script that can be triggered by SMS from a phone, which solves the problem for one of the networking devices completely. The Asus Router remains.

In most optimal possible situation, I'd still like to have a more graceful shutdown, just to be extra sure, I am, and neither there are any IT specialists on premises, I wouldn't be able to resolve anything remotely if things break with the router in a major way.
Normally this wouldn't be an issue, as shutting down Routers by just cutting power doesn't seem to be that of an issue, potentially creating permanent errors. Though in general I still disagree with the whole design having no concept of a graceful shutdown.

However this Asus router is running external storage, entware, scripts, diversion etc., and that is a problem, I've had disk check report issues in past, they happened to be resolved. Cutting power to a mounted filesystem is ofcourse not a good thing in linux in general and I've had enough experience with multiple distros.

The creator of AsusWrt-Merlin explained in the past that ejecting storage would then trigger a graceful shutdown of diversion, entware, scripts an a proper unmount of the filesystem and the external storage device, flushing caches, the usual stuff.

So the logical next step is to find a way to more conveniently remotely trigger a storage ejection for Asus Merlin FW ... if I could somehow combine the SMS triggered script functionality of the LTE Antenna providing WAN for this router.

Thanks a lot for ideas.


Create DDNS profile on the router and install the Instant Guard and ASUS Router app on your phone. Connect to your router remotely via Instant Guard and run ASUS Router app and you can also eject USB attached storage to it...

 
In my opinion, attempting to unmount the USB drive causes more harm than it prevents.

My approach is to:
  • Use journaled ext4 filesystem of no greater than 8 GB
  • Run fsck on every reboot
How to check current settings:

Code:
# tune2fs -l /dev/sda1 | grep -E "Filesystem features|Maximum mount count|Check interval"
Filesystem features:      has_journal ext_attr filetype needs_recovery extent flex_bg sparse_super large_file huge_file extra_isize
Maximum mount count:      1
Check interval:           86400 (1 day)

Feature "has_journal" means filesystem is journaled.
Maximum mount count means mount interval between fsck.
Check interval means seconds between fsck.

How to set:

Code:
# tune2fs -c 1 -i 1d /dev/sda1

Verify in syslog messages that fsck had happened on reboot:

Code:
Nov 18 00:23:00 RT-AX88U custom_script: Running /jffs/scripts/pre-mount (args: /dev/sda1 ext4)
Nov 18 00:23:00 RT-AX88U amtm disk check: Probing 'ext4' on device /dev/sda1
Nov 18 00:23:00 RT-AX88U amtm disk check: Running disk check with command 'e2fsck -p' on /dev/sda1
Nov 18 00:23:08 RT-AX88U amtm disk check: Disk check done on /dev/sda1
Nov 18 00:23:08 RT-AX88U hotplug: USB ext4 fs at /dev/sda1 mounted on /tmp/mnt/ent
Nov 18 00:23:08 RT-AX88U kernel: EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: user_xattr
Nov 18 00:23:08 RT-AX88U usb: USB ext4 fs at /dev/sda1 mounted on /tmp/mnt/ent.
 
Last edited:
In my opinion, attempting to unmount the USB drive causes more harm than it prevents.

My approach is to:
  • Use journaled ext4 filesystem of no greater than 8 GB
  • Run fsck on every reboot

Hmm, isn't EXT4 the default/preferred anyway with the latest Routers/AsusWrt-Merlin/AMTM ?

I don't recall the setting up procedure right now, perhaps I had to manually format, I think I always used EXT4, but at this moment I'm sure it's EXT4 already whether I did it or not, because it was just setting it up this summer completely fresh.

I believe at some point it even says that if it's not EXT4 (like ext2) it's going to do a less rigourous test, it can't do a full one it'd like, so I think I made sure I used EXT4.

I'll check up on those other points. Thanks
 
An industrial place is experiencing frequent losses of power but more than half of them is voluntary because of repairs, manufacturing, testing and they just hit the main breaker ... the employees know how to shutdown the PCs, but they don't have a quick way to shutdown the networking stuff.

What about an upgrade to proper power backup with some more industrial ready PoE powered networking equipment behind it? When you need machines for your manufacturing you don't go to the nearest Home Hardware store, I guess. MikroTik has a lot to offer in this field.
 
What about an upgrade to proper power backup with some more industrial ready PoE powered networking equipment behind it? When you need machines for your manufacturing you don't go to the nearest Home Hardware store, I guess. MikroTik has a lot to offer in this field.

I have suggested more than once, twice, all the time, but management is non-tech savvy and generally tought to negotiate with, however a twist happened with the whole solar-panel green thing where there are now companies promoting whole-building power-storage solutions along with significant changes in our country's electircal billing and longterm planning (complicated matter with government involvement, prices, surcharges, types of needs, load, time of year, day, etc.) with one of the benefits being that it works as a backup UPS power supply for the whole premises along with the whole solar-power-bank exchange market and grid management, ... which makes investing in a standalone UPS less interesting.

So they're munching on that but nothing's definitive yet, there's also branded batteries and whether you go DIY route or not ... chinese battery quality and stuff. I'd still went for standard UPS from the very beginning but they refused.

It's not exactly a big business that can just drain resources into what they determine is unnecessary expenses. I have to be realistic and objective, I do tell them when things "work good enough" and that upgrading won't have a significant practical difference. Otherwise I'd be blamed if things go wrong even with "such an investment".

I already use UPS for my self home/work either way.
 
If you can figure out how to send a log message from the LTE antenna to an external log server, you can have the Asus router be that external server. Then, with scribe, you can intercept such a log message and trigger a shutdown/demount script using the program() destination.

A few years ago I had a location with two TrueNAS servers, a PC, my Asus router and a cable modem. Power was nasty. I put all of it on an APC Smart-UPS that would run the Asus router and the cable modem for about 4 -6 hours. The APC was wired into one of the servers, and if the external power went out, that would trigger a graceful shutdown of both. But the TrueNAS servers were also sending log messages to the router, and I could have tried triggering such a script. Never did go that far, because nothing important was on the router that wasn't backed up weekly anyway. The trickier part was turning stuff on; I did that first with two wifi switches, and then by upgrading the TrueNAS servers to more serious motherboards with IPMI.

I seem to recall the Power chute software had a SNMP function, so it may be possible to send something from an APC directly to the router if you have two USB ports in the router.

<Telling you something you already know> I can't imagine a production environment without power resiliency, or one where data files are served up by the router.

Some years ago I had a client, an HMO, that embarked on a belated program to harden its data processing. It built a whole server room with guys in white coats and clipboards, and a great big diesel generator outside for backup. They did all their claims processing in a gigantic batch file. Wrote it all up. The first day, following established procedures, the guy responsible for testing the diesel backup marched into the server room with a key, unlocked the big glass door, and pulled the big power self-test circuit breaker for the first time. Amid all the other guys in white coats and clipboards, and in the middle of a batch file. The generator didn't start, everything went dark, and it took a month to rebuild the data. Revised procedure was a sheet of paper taped to the self-test door with magic marker saying "Do not pull ever"</Telling you something you already know>
 

Similar 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