2024/12/10

NextCloud AIO with Docker

I could not find anyone that had found a great way to integrate Nextcloud AIO with systemd, so I will leave this unit-file here for anyone interested. Maybe I will spare you some research work. It could need som polishing and sandboxing, but it gets the work done. I use the internal backup script to automatically start and stop the containers. This makes it possible to safely shutdown and start NextCloud without using the AIO.

Remember to remove restart: always or change it to restart: unless-stopped.

I think I have some issues were the nextcloud backup script just hangs due to DNS issues withing the NextCloud containers, but I have yet to find a solution.

[Unit]
Description=Docker Compose Nextcloud AIO service for nanura.no
After=network.target docker.socket

[Service]
Type=simple
WorkingDirectory=/var/www/nanura.no/cloud/

ExecStart=/usr/bin/docker-compose -f /var/www/nanura.no/cloud/docker-compose.yml up
ExecStartPost=/usr/bin/sleep 10 
ExecStartPost=/usr/bin/docker exec --env START_CONTAINERS=1 nextcloud-aio-mastercontainer /daily-backup.sh

ExecStop=/usr/bin/docker exec --env STOP_CONTAINERS=1 nextcloud-aio-mastercontainer /daily-backup.sh
ExecStopPost=/usr/bin/docker-compose -f /var/www/nanura.no/cloud/docker-compose.yml down

Restart=always


[Install]
WantedBy=multi-user.target
devself-hosting