Blame

eb4d88 Tebby Dog 2025-07-06 21:43:46
Added intro
1
# Mount-Point-Service-Sync
2
32ed51 Tebby Dog 2025-07-06 21:44:47
Formatting
3
## Intro
4
----------------
5
eb4d88 Tebby Dog 2025-07-06 21:43:46
Added intro
6
Plex kept shitting the bed every time the SMB share randomly dropped offline. After getting sick of jumping in to fix it manually over and over, I hacked together a script that shuts down the Plex service when the share bails, tries to remount the damn thing, and fires Plex back up once the share is stable again.
7
8
# MPSS (Mount Point Service Sync)
9
=====================================
10
11
MPSS dynamically controls start/stop of services (plexmediaserver, tdarr_node, Tdarr_Uptime, emby-server) based on presence or absence of "MOUNT_POINT_ALIVE" file on a network share. It logs actions to /var/log/mpss.log and trims the log to 200 lines.
12
13
14
### Basic Concept
15
---------------
16
17
1. Crontab that runs this script regularly
18
2. Script checks for a file on the network share
19
* If it does, ensure the service is running
20
* If it does not, ensure the service is stopped
21
22
## Setup
23
--------
24
25
### Step 1: Download the Script
26
------------------------------
27
28
Download the script from this git repository:
29
30
```bash
31
mkdir /opt/mpss
32
git clone https://github.com/tebwritescode/mpss.git
33
cp ./mpss/mpss.sh /opt/mpss/mpss.sh
34
```
35
36
### Step 2: Customize the Script
37
-------------------------------
38
39
Customize the script by modifying the variables at the top of the file:
40
41
```bash
42
nano /opt/mpss/mpss.sh
43
```
44
45
Modify `FILE`, `SERVICE`, `LOG_FILE`, and `MAX_LINES` to match your setup.
46
47
Example:
48
```bash
49
FILE="/path/to/mount/MOUNT_POINT_ALIVE" #The location of the file on the share
50
SERVICE="plexmediaserver" #Service that can be started/stopped with systemctl
51
LOG_FILE="/var/log/mpss.log" #Where to save the log
52
MAX_LINES=200 #How many lines of logs to keep in the log file
53
```
54
55
Save your changes with <kbd>ctrl</kbd> + <kbd>x</kbd>, then <kbd>y</kbd>, then <kbd>return</kbd>.
56
57
### Step 3: Create the Log File
58
---------------------------
59
60
Create the log file:
61
62
```bash
63
touch /var/log/mpss.log
64
```
65
66
### Step 4: Create the Check File
67
------------------------------
68
69
Create the check file on the network share:
70
71
```bash
72
touch /path/to/mount/MOUNT_POINT_ALIVE
73
```
74
75
### Step 5: Make the Script Executable
76
------------------------------------
77
78
Make the script executable:
79
80
```bash
81
chmod +x /opt/mpss/mpss.sh
82
```
83
84
### Step 6: Schedule the Script with Crontab
85
-----------------------------------------
86
87
Schedule the script to run regularly using crontab. Add the following line to your crontab file (use `crontab -e` to edit):
88
89
```bash
90
*/1 * * * * /opt/mpss/mpss.sh
91
```
92
93
Note: Be aware that some versions of cron do not support all times you can create on crontab.guru, you will get an error when saving the file.
94
95
That's it! Your MPSS script should now be set up to automatically start/stop services based on the presence or absence of the `MOUNT_POINT_ALIVE` file on your network share.