✨feature: Reorganize files, add server backoff
This commit is contained in:
31
README.md
31
README.md
@@ -24,10 +24,12 @@ Designed for **homelab** and **server** environments. Script file is named `cifs
|
||||
## How It Works
|
||||
|
||||
1. **Discovery** — scans `/etc/fstab` for uncommented `cifs` entries like:
|
||||
```
|
||||
|
||||
```ini
|
||||
//nas.local/media /mnt/media cifs vers=3.0,credentials=/root/.smbcreds 0 0
|
||||
//192.168.1.50/share /mnt/share cifs credentials=/root/.creds,iocharset=utf8 0 0
|
||||
```
|
||||
|
||||
2. **Reachability** — ensures the server resolves, optionally pings, and has TCP/445 open.
|
||||
3. **Health probe** — times a quick `ls` against the mountpoint.
|
||||
4. **Repair** — remount or unmount/remount as needed, with retries and logging.
|
||||
@@ -37,34 +39,44 @@ Designed for **homelab** and **server** environments. Script file is named `cifs
|
||||
## First-Run Setup
|
||||
|
||||
1. **Install prerequisites**
|
||||
|
||||
```bash
|
||||
sudo apt install cifs-utils
|
||||
```
|
||||
|
||||
2. **Credentials file**
|
||||
|
||||
```bash
|
||||
sudo nano /root/.smbcreds
|
||||
```
|
||||
```
|
||||
|
||||
```ini
|
||||
username=myuser
|
||||
password=mypassword
|
||||
domain=MYDOMAIN # optional
|
||||
```
|
||||
|
||||
```bash
|
||||
sudo chmod 600 /root/.smbcreds
|
||||
```
|
||||
|
||||
3. **Add to `/etc/fstab`**
|
||||
```
|
||||
|
||||
```ini
|
||||
//192.168.1.10/media /mnt/media cifs vers=3.0,credentials=/root/.smbcreds,uid=1000,gid=1000,file_mode=0644,dir_mode=0755 0 0
|
||||
```
|
||||
|
||||
> Avoid `noauto` if you want the script to manage the mount.
|
||||
|
||||
4. **Test manually**
|
||||
|
||||
```bash
|
||||
sudo mount -a
|
||||
sudo ls /mnt/media
|
||||
```
|
||||
|
||||
5. **Verify connectivity**
|
||||
|
||||
```bash
|
||||
ping -c 2 192.168.1.10
|
||||
nc -zv 192.168.1.10 445
|
||||
@@ -80,12 +92,14 @@ sudo touch /var/log/cifs-remount.log && sudo chmod 600 /var/log/cifs-remount.log
|
||||
```
|
||||
|
||||
**Test it:**
|
||||
|
||||
```bash
|
||||
sudo /usr/local/sbin/cifs-watch --dry-run --verbose
|
||||
sudo /usr/local/sbin/cifs-watch --verbose
|
||||
```
|
||||
|
||||
Logs:
|
||||
|
||||
- `/var/log/cifs-remount.log`
|
||||
- `journalctl -t cifs-watch` or `journalctl -u cifs-watch.service`
|
||||
|
||||
@@ -96,6 +110,7 @@ Logs:
|
||||
Create the following two files:
|
||||
|
||||
**`/etc/systemd/system/cifs-watch.service`**
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=Monitor and repair CIFS mounts
|
||||
@@ -107,6 +122,7 @@ Nice=10
|
||||
```
|
||||
|
||||
**`/etc/systemd/system/cifs-watch.timer`**
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=Run cifs-watch periodically
|
||||
@@ -122,6 +138,7 @@ WantedBy=timers.target
|
||||
```
|
||||
|
||||
Enable and start:
|
||||
|
||||
```bash
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now cifs-watch.timer
|
||||
@@ -149,7 +166,8 @@ Prevents hammering an offline NAS with constant retries.
|
||||
- Backoff state is reset on reboot (uses `/var/tmp`).
|
||||
|
||||
Example log flow:
|
||||
```
|
||||
|
||||
```log
|
||||
[WARN] Server NOT reachable: nas.local (skipping /mnt/media)
|
||||
[INFO] Backoff started: will not retry nas.local for 10 minutes
|
||||
...
|
||||
@@ -171,7 +189,7 @@ Example log flow:
|
||||
|
||||
## Cron Alternative
|
||||
|
||||
```
|
||||
```ini
|
||||
*/5 * * * * /usr/local/sbin/cifs-watch >/dev/null 2>&1
|
||||
```
|
||||
|
||||
@@ -188,4 +206,5 @@ Example log flow:
|
||||
|
||||
## License
|
||||
|
||||
MIT — see `LICENSE`.
|
||||
Released under the [Unlicense](https://unlicense.org/).
|
||||
You can do whatever you want with this code. No warranty provided.
|
||||
|
||||
Reference in New Issue
Block a user