I have written this bash script to autostart the containers:
#!/bin/bash
# Name of the container to check
CONTAINER_NAME="nextcloud-aio-mastercontainer"
sleep 120 # Wait 180 seconds before start checking
# Function to check if the container is running and healthy
is_container_healthy() {
local STATUS=$(docker inspect --format '{{.State.Health.Status}}' $CONTAINER_NAME 2>/dev/null)
[[ "$STATUS" == "healthy" ]]
}
# Wait until the container is healthy
echo "Waiting for the container $CONTAINER_NAME to be healthy..."
until is_container_healthy; do
echo "The container $CONTAINER_NAME is not healthy yet. Waiting..."
sleep 10 # Wait 10 seconds before checking again
done
# Once the container is healthy, wait an additional 30 seconds
echo "The container $CONTAINER_NAME is healthy. Waiting an additional 30 seconds..."
sleep 30
# Run the desired command
echo "Running the command..."
docker exec -it $CONTAINER_NAME sudo -u www-data php /var/www/docker-aio/php/src/Cron/StartAndUpdateContainers.php
echo "Command execution completed."
So there is already a way in the mastercontainer to simply start/start and update/stop the child containers, so why cant this be an an official way?
Yes, i have seen this, thats why i have written the script to autostart the child containers. The command to start is 1:1 taken from the daily-backup.sh script.
But thats not a good solution in my opinion for this problem.
Also, i know i could set the autostart for all child containers separately through the unraid webui, but that has problems:
The containers that the master container created are not in order and there is no dependecy checking happening. So the autostart would happen in the order, the containers appear in the gui (which sometimes can get messed up).
For example for me, the apache container would start first, or nextcloud would start before the database. I dont know the exact order in which they would have started. And if any new containers are needed or old ones get removed, then i would have to reorder them all. Also by just setting the autostart like that, even with the correct order, the database could fail to start, but nextcloud itself would still autostart.
So thats the issue.
So in my opinion, there should be a simple environment variable for the mastercontainer, so it autostarts the child containers correctly and in order, without relying on the user setting up external scripting to do that.
This is not a problem in the case of AIO as the AIO containers have a dependency check built directly into them. E.g. the nextcloud container checks if redis and database are available, the apache container checks if nextcloud is available, etc.
When the autostart happens, the containers start in the wrong order and stop because of dependency checking, then maybe half of the containers will run correctly and the other half will be stopped
Ok, but we still need a solution, as i just found out, that in the next version of unraid, this mechanic will disappear. Th next version is supposed to be released in the next 1-2 months.
WIth the new version it wont be possible to set autostarts for containers, that havent been created by the unraid docker manager
Why would this discussion lead to nowhere?
Why would it be so difficult to implement a simple environment variable to the AIO image that just runs the command sudo -u www-data php /var/www/docker-aio/php/src/Cron/StartAndUpdateContainers.php at startup so users on unraid can autostart/autostart&update the AIO child containers on startup?
I dont understand what the problem here is @szaimen, so please, explain it. I would like to know.
Also, if this is the official way, then there should atleast be an entry in the “wiki” for it (although i dont think that this is in any way “official”, its rather hacking around the lack of a proper solution)
The problem is that the script runs async - there is no process running inside the container that triggers this. So if you want to trigger this you need to run it via script. Also it might cause unexpected sideffects. Additionally it does not work for example if the initial setup is not done. Adding this leads to completely unnecessary complications on the aio side that would not be necessary if unraid would simply use the defined standard for auto-starting containers.
Indeed, you are 100% right. Standardization is the way to go and should be preffered. I didnt knew the startup process of the mastercontainer is so complex.
Could it atleast be added as a workaround for unraid in the “wiki” so more people would know about this solution?
Also not sure if my script is the best way to do it, i hacked it together in like 10 minutes or so witohut thinking about better ways