Bulletproof Docker + Nextcloud Startup: Surviving Power Cuts Without a UPS ๐Ÿ›ก️

Fix Nextcloud Docker startup errors after power cuts or reboots. Bulletproof setup using systemd, symlinks, fsck, and auto permission fixes.

Running a self-hosted Nextcloud instance on your NAS without a UPS? You’ve probably run into this dreaded error after a sudden power loss or OS reinstall:

Your data directory is invalid
Ensure there is a file called .ncdata in the root of the data directory.

Or maybe:

“Permissions are not writable”
“Missing .ncdata”
“Docker container won’t start”

These problems typically happen because Docker starts before your data disk is mounted, especially if you're using /srv/personal symlinks that point to a UUID-based disk path.

This guide combines multiple powerful solutions into one bulletproof setup — ensuring your Nextcloud container remains healthy across power cuts, OS reinstalls, UUID changes, and mount delays.


✅ What You'll Achieve

  • ๐Ÿงท Stable symlinks for persistent Docker volumes
  • ⏳ Make Docker wait for your disk and .ncdata file
  • ๐Ÿ” Auto-fix Nextcloud folder permissions on boot
  • ๐Ÿ” Auto-run fsck after power loss

๐Ÿ“ Step 1: Use a Stable Symlink for Your Data Disk

1. Mount the Disk via OMV

Mount your data disk in OMV → File Systems. It will be mounted under a UUID path like:

/srv/dev-disk-by-uuid-1234abcd/

2. Create a Stable Symlink

sudo rm /srv/personal
sudo ln -s /srv/dev-disk-by-uuid-1234abcd /srv/personal

This allows Docker to always use /srv/personal/nextcloud even if the UUID changes — just update the symlink later.

3. Update Docker Volume Path

volumes:
  - /srv/personal/nextcloud:/var/www/html/data

⏱️ Step 2: Make Docker Wait for .ncdata File

Prevent startup errors by delaying Docker until the file is accessible.

Create the Wait Service:

sudo nano /etc/systemd/system/docker-wait-for-ncdata.service

Paste this:

[Unit]
Description=Wait for /srv/personal/nextcloud/.ncdata before starting Docker
DefaultDependencies=no
After=local-fs.target
Before=docker.service

[Service]
Type=oneshot
ExecStart=/bin/bash -c 'while [ ! -f /srv/personal/nextcloud/.ncdata ]; do echo "Waiting for .ncdata..."; sleep 3; done'
RemainAfterExit=true

[Install]
WantedBy=multi-user.target

Enable it:


sudo systemctl daemon-reload
sudo systemctl enable docker-wait-for-ncdata.service

✅ What to Do Next

  • ๐Ÿ”น Step 1: Manually Create .ncdata

You only need to do this once — unless you erase the data folder again.

sudo touch /srv/personal/nextcloud/.ncdata
sudo chown 33:33 /srv/personal/nextcloud/.ncdata

This creates the marker file that your wait service is looking for.

✅ After this, your systemd logic will work as intended every time, including after power loss.

⚙️ Step 3: Create Docker Service Override

Ensure Docker respects the wait service.


sudo mkdir -p /etc/systemd/system/docker.service.d
sudo nano /etc/systemd/system/docker.service.d/override.conf

Paste this:


[Unit]
Requires=docker-wait-for-ncdata.service
After=docker-wait-for-ncdata.service

Save and reload:


sudo systemctl daemon-reload

Verify:


systemctl cat docker.service

๐Ÿงผ Step 4: Force Filesystem Check on Boot

1. Identify the Disk

df -h /srv/personal/nextcloud

2. Enable fsck Auto-Check

sudo tune2fs -c 1 /dev/sdX

Replace /dev/sdX with the actual device (e.g. /dev/sdb1).

๐Ÿ” Step 5: Auto-Fix Permissions on Boot

1. Create the Script

sudo nano /usr/local/bin/fix-nextcloud-perms.sh

Paste:

#!/bin/bash

# Set ownership of the local Nextcloud bind mount directory
chown -R 33:33 /srv/personal/nextcloud

# Set ownership of the Docker volume data directory
chown -R 33:33 /var/lib/docker/volumes/nextcloud_nextcloud_html/_data

Make it executable:

sudo chmod +x /usr/local/bin/fix-nextcloud-perms.sh

2. Create the Service

sudo nano /etc/systemd/system/fix-nextcloud-perms.service

Paste:

[Unit]
Description=Fix Nextcloud Permissions
After=local-fs.target

[Service]
ExecStart=/usr/local/bin/fix-nextcloud-perms.sh
Type=oneshot

[Install]
WantedBy=multi-user.target

Enable it:


sudo systemctl daemon-reload
sudo systemctl enable fix-nextcloud-perms.service

๐Ÿ” Step 6: Recreate Symlink After UUID Change

1. Re-mount via OMV

Then recreate the symlink:


sudo rm /srv/personal
sudo ln -s /srv/dev-disk-by-uuid-NEWUUID /srv/personal

๐Ÿ“‹ Summary

StepDescription
1Create a symlink for persistent Docker volumes
2Make Docker wait for .ncdata before starting
3Auto-run fsck on every boot
4Auto-fix Nextcloud folder permissions
5Update symlink if UUID changes

๐ŸŽ‰ Conclusion

By combining symlinks, systemd wait services, fsck, and auto permission fixes, your NAS setup becomes resilient and ready for real-world chaos.

This is the ideal solution for homelabbers without a UPS who still want reliable, self-hosted services like Nextcloud, Immich, or Jellyfin.

About the author

Student, Photographer by Hobby, Blogger / Content Writer

Post a Comment