Compare commits

...

2 Commits

Author SHA1 Message Date
8130d82b4c Added README for remount 2024-11-05 23:24:37 +00:00
84e37dfd4e Add remount checker
I should add instructions on how to call it too
2024-11-05 23:15:23 +00:00
4 changed files with 59 additions and 0 deletions

19
remount_checker/README.md Normal file
View File

@@ -0,0 +1,19 @@
# Remount Checker
This is a very simple program to check if a particular folder is a mounted folder or not. If it's not, run the mount command - simple!
## ``mount_points``
You *need* a ``mount_points.py`` file. The ``example_mount_points.py`` provides an example format (it's a touple - first element is the folder to check, second element is the command to run).
## ``mount`` command
You'll need to make sure that the ``cron``user (can't think of the exact correct term - the user that cron _pretends_(?) to be when runnign the command??) is able to actually run the mount command. There are 2 simple options that I can see:
1. Use ``sudo crontab -e`` and make ``root`` use run the command, or
2. Make your user able to run the mount command. I'm sorry I don't know 100%, but I think that means adding ``user`` to the mount options in ``fstab``.
## crontab
The idea is you should run this is crontab every X minutes - 5 seems to work fine for me. An example crontab is:
``*/5 * * * * /usr/bin/python /home/<USER>/code/remount_checker/remount.py``
Replace <USER> (and the rest) with the location of remount

View File

@@ -0,0 +1,4 @@
mount_points = (
# ('/mnt/external', 'mount /mnt/external')
# ('/mnt/network_drive', 'cd /mnt; mount network_drive')
)

View File

@@ -0,0 +1,5 @@
mount_points = (
('/mnt/btn', '/usr/bin/mount /mnt/btn'),
('/mnt/ptp', '/usr/bin/mount /mnt/ptp'),
('/mnt/music', '/usr/bin/mount /mnt/music')
)

View File

@@ -0,0 +1,31 @@
import sys
import subprocess
try:
from mount_points import mount_points
except ImportError:
print('Couldn\'t find the mount points. Please copy the example_mount_points.py')
print('to mount_points.py and edit the file.')
sys.exit(1)
def is_mounted(mount_point):
lines = None
with open('/proc/mounts', 'r') as f:
lines = f.readlines()
for line in lines:
if mount_point in line:
return True
return False
if __name__ == '__main__':
for mount_point in mount_points:
if is_mounted(mount_point[0]):
print('{} is mounted'.format(mount_point[0]))
else:
print('{} is not mounted; remounting using {}'.format(mount_point[0], mount_point[1]))
subprocess.call(mount_point[1], shell=True)
if is_mounted(mount_point[0]):
print('{} if mounted again'.format(mount_point[0]))
else:
print('{} is not mounted - might need fixing'.format(mount_point[0]))