My home server runs FreshRSS, Jellyfin, Navidrome, Wallabag, and WireGuard via Docker Compose. I am
hideously lazy when it comes down to updating my containers, and that's not a best practice; it's a worst practice.
I started a new Llama3.1 chat thread, and I was like "hey man, I don't think I can really benefit that much from local inference but I'll give it the old college try. My desktop is pure manual, and it's better to be manual rather than pure automated because I'll actually know when to reboot for kernel updates. My home server has a bunch of Docker Compose services running and I suck at updating them manually. I haven't automated it because I'm afraid of the complexity."
Llama3.1 basically said "Yeah, I agree, your daily driver desktop don't need automation. Your home server has room for improvement." Relevant section, verbatim.
Llama3.1 said:
Updating system packages, refreshing Docker Compose services, and rebooting if necessary are good candidates for automation.
You have several options to automate this process, but I'd recommend starting simple:
Create a bash script that runs the update and refresh commands, similar to your existing script.
Use cron (or systemd-timer) to schedule the script to run weekly or daily.
Now, I actually already
have a system package updater script. I adapted it from some experimentation I documented
here back in January.
Code:
#!/usr/bin/env bash
set -e
apt_updater() {
sudo apt update && sudo apt full-upgrade -y
}
main() {
apt_updater
}
main "$@"
So, I said "hey man, I already have a script going. Lemme share it and you tell me where I can go from here." Pasted the script, and then it gave me the below output.
Code:
#!/usr/bin/env bash
set -e
apt_updater() {
sudo apt update && sudo apt full-upgrade -y
}
refresh_docker_services() {
for service in freshrss jellyfin navidrome wallabag wireguard; do
cd "$service"
docker-compose pull && docker-compose up -d --force-recreate
cd ..
done
}
main() {
apt_updater
refresh_docker_services
}
main "$@"
This had me taken aback. It
looked really clean. Just invokes a loop, changes into the correct directory, pulls the latest image, forcibly recreates the container, exits, and repeats until it reaches the end of the line. There was just
one hitch that I didn't immediately catch until I tried running it and it failed.
Code:
refresh_docker_services() {
for service in freshrss jellyfin navidrome wallabag wireguard; do
cd "$service"
docker-compose pull && docker-compose up -d --force-recreate
cd ..
done
}
Llama3.1 hyphenated
docker compose. Take the hyphens out like so
Code:
docker compose pull && docker compose up -d --force-recreate
and it works as expected! In absolute fairness, I didn't immediately jump at modifying my updater script. Forcibly recreating the containers made me go "wait, what?" until I saw that all my services already have clearly defined volumes, so data loss was no big issue. The next big step would be to properly schedule a cron job
or a
systemd-timer service. My heart is telling me "cron job! cron job! do the cron job!" but my brain is saying "dude, you're already fiddling with
systemd --user services. It doesn't hurt to learn
systemd-timer and actually see whether or not it's better than a simple cron job."
Either way, that's a pursuit for when I have brain power left to spare. For now, I'm honestly pleased with the results even if it wasn't a one-shot one-kill affair.