# Contentstore Mount Setup

## Quick Setup (Automatic Mount on Boot)

To configure the contentstore to mount automatically on boot, run:

```bash
sudo bash scripts/setup_mount.sh
```

This script will:
1. ✅ Create the mount point directory
2. ✅ Verify credentials file exists
3. ✅ Mount the contentstore
4. ✅ Add entry to `/etc/fstab` for automatic mounting
5. ✅ Install and enable systemd mount unit (primary method)
6. ✅ Install and enable fallback mount service (backup method)

**The setup uses a dual-layer approach:**
- **Primary**: Systemd mount unit (tries to mount automatically)
- **Backup**: Fallback service (ensures mount happens if primary fails)

This ensures maximum reliability for CIFS mounts on boot.

## Manual Mount (Temporary)

For a quick manual mount without configuring boot:

```bash
sudo bash scripts/mount_lrs.sh
```

## Verification

Check if mount is configured for boot:

```bash
bash scripts/verify_boot_setup.sh
```

Or run comprehensive diagnostics:

```bash
bash scripts/diagnose_mount.sh
```

Or check manually:

```bash
# Check fstab
grep aumentum_contentstore /etc/fstab

# Check systemd mount unit
systemctl status mnt-aumentum_contentstore.mount
systemctl is-enabled mnt-aumentum_contentstore.mount

# Check fallback service
systemctl status ensure-contentstore-mount.service
systemctl is-enabled ensure-contentstore-mount.service
```

## Mount Methods

### Method 1: Systemd Mount Unit (Primary)

The systemd mount unit is the primary method for mounting. It:
- Waits for network to be ready
- Has retry logic (soft, timeo=30, retrans=3)
- Integrates with systemd services

**File:** `/etc/systemd/system/mnt-aumentum_contentstore.mount`

**Enable:**
```bash
sudo systemctl daemon-reload
sudo systemctl enable mnt-aumentum_contentstore.mount
sudo systemctl start mnt-aumentum_contentstore.mount
```

### Method 1b: Fallback Mount Service (Backup)

A fallback service ensures the mount happens even if the mount unit fails:
- Checks if mount exists before attempting
- Retries with proper timing
- Required by API service

**File:** `/etc/systemd/system/ensure-contentstore-mount.service`

**Enable:**
```bash
sudo systemctl daemon-reload
sudo systemctl enable ensure-contentstore-mount.service
sudo systemctl start ensure-contentstore-mount.service
```

### Method 2: fstab (Tertiary Fallback)

If systemd mount unit is not available, fstab will be used.

**Entry in `/etc/fstab`:**
```
//10.10.10.5/LRS_STORAGE /mnt/aumentum_contentstore cifs credentials=/root/.smb_credentials_aumentum,uid=1000,gid=1000,file_mode=0755,dir_mode=0755,_netdev 0 0
```

**Test:**
```bash
sudo mount -a
```

## Troubleshooting

### Mount Not Working on Boot

1. **Check credentials file:**
   ```bash
   sudo cat /root/.smb_credentials_aumentum
   ```

2. **Check network connectivity:**
   ```bash
   ping 10.10.10.5
   ```

3. **Check mount status:**
   ```bash
   mountpoint /mnt/aumentum_contentstore
   df -h | grep aumentum
   ```

4. **Check systemd mount unit logs:**
   ```bash
   sudo journalctl -u mnt-aumentum_contentstore.mount -n 50
   ```

5. **Check fallback service logs:**
   ```bash
   sudo journalctl -u ensure-contentstore-mount.service -n 50
   ```

6. **Check all mount-related logs:**
   ```bash
   sudo journalctl -u mnt-aumentum_contentstore.mount -u ensure-contentstore-mount.service --since "1 hour ago"
   ```

5. **Test manual mount:**
   ```bash
   sudo umount /mnt/aumentum_contentstore
   sudo mount -t cifs //10.10.10.5/LRS_STORAGE /mnt/aumentum_contentstore -o credentials=/root/.smb_credentials_aumentum,uid=1000,gid=1000,file_mode=0755,dir_mode=0755
   ```

### Service Starts Before Mount

The API service is configured with `RequiresMountsFor=/mnt/aumentum_contentstore`, which ensures it waits for the mount. If you still have issues:

1. Verify the mount unit is enabled:
   ```bash
   sudo systemctl is-enabled mnt-aumentum_contentstore.mount
   ```

2. Check service dependencies:
   ```bash
   systemctl list-dependencies plagis-aumentum-api.service
   ```

## Files

- `scripts/setup_mount.sh` - Main setup script (configures boot mounting)
- `scripts/mount_lrs.sh` - Quick manual mount script
- `scripts/mnt-aumentum_contentstore.mount` - Systemd mount unit template (primary)
- `scripts/ensure-contentstore-mount.service` - Fallback mount service (backup)
- `scripts/verify_boot_setup.sh` - Verification script
- `scripts/diagnose_mount.sh` - Comprehensive diagnostics script

