You are not logged in.

#1 2019-03-01 20:13:39

ua4000
Member
Registered: 2015-10-14
Posts: 566

[SOLVED] Put NAS file-system into read-only on inactivity

I have a headless NAS with BTRFS.
I want to simply hard cut power supply with the switching socket after work.
But of course I don't want the BTRFS get damaged :-)

The idea is:
Put the BTRFS into ro on inactivity.

sudo mount -o remount,ro ...

Put it back to rw when needed.

sudo mount -o remount,rw ...

Users use ssh, sftp, rsync over ssh, these should be the trigger.
The NAS is used only occasionally, most time it's idle and has no remote users connected.

Is this idea feasible?
What are the options to check for inactivity/activity?

Thanks very much!

Last edited by ua4000 (2019-03-06 17:23:46)

Offline

#2 2019-03-01 20:41:27

bugsmanagement
Member
Registered: 2017-04-21
Posts: 201

Re: [SOLVED] Put NAS file-system into read-only on inactivity

Hello there,

Why would you want to turn off the NAS?

Regards

Offline

#3 2019-03-02 07:41:11

ua4000
Member
Registered: 2015-10-14
Posts: 566

Re: [SOLVED] Put NAS file-system into read-only on inactivity

Energy Saving !
Preventive fire protection !
While I'm sleeping or during day at the office the NAS is unused.

Offline

#4 2019-03-02 08:13:17

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,097

Re: [SOLVED] Put NAS file-system into read-only on inactivity

It is not really safe to pull the plug even with the fs in ro mode,  power down the nas before you pull the plug. Or just have the nas suspend and don't pull the plug?

Last edited by Mr.Elendig (2019-03-02 08:15:56)


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#5 2019-03-02 08:19:31

ua4000
Member
Registered: 2015-10-14
Posts: 566

Re: [SOLVED] Put NAS file-system into read-only on inactivity

The NAS is a self made arch box, the hardware is not entirely suspend capable.
Also suspend won't solve all my points at #3.

Last edited by ua4000 (2019-03-02 08:19:54)

Offline

#6 2019-03-02 12:09:50

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: [SOLVED] Put NAS file-system into read-only on inactivity

I'm sure you could hack a shell script that would do this but I don't see why.... just spin down the HDDs for power savings.  Fire prevention??  Never heard of NAS catching fire.

Offline

#7 2019-03-02 13:20:14

ua4000
Member
Registered: 2015-10-14
Posts: 566

Re: [SOLVED] Put NAS file-system into read-only on inactivity

https://www.ksta.de/wohnhaus-laptop-ver … d-12277502
All power supplies could break down, overheat and cause a fire.

Back to my topic:
I think I can use the sshd pam, like I found here :
https://wiki.archlinux.org/index.php/Dm … g_at_login
as trigger for switching to rw mode.

And for switching to ro mode I could use a timer, checking every minute the ps -eaf output.

Any better ideas ?

Offline

#8 2019-03-03 08:39:44

ua4000
Member
Registered: 2015-10-14
Posts: 566

Re: [SOLVED] Put NAS file-system into read-only on inactivity

This will state the number of remote ssh users:

users() {
	ps -eaf | egrep -i ' sshd: ' | egrep -v ' grep ' | wc --lines
}

If it's 0 a periodic systemd timer can put the system into ro mode.

And this one will set rw mode on remote logins:

# sudoedit /etc/pam.d/system-remote-login
session   optional  pam_exec.so quiet /usr/local/sbin/s-rw rw

Better ideas are still welcome.

Offline

Board footer

Powered by FluxBB