Shell hack: docker-nfs-check
I use docker containers that mount nfs mounts. Sometimes if the docker server comes up before the nfs server does, (and the systemd service dependency definitions don't work), then I want to bounce the services after I've gotten nfs working.
This affects things like my photo app (PhotoPrism) and metube which store files on the network share.
It uses my favorite shell redirection spaghetti boilerplate code to prepend STDERR to standard error messages that all end up in the same place.
But inside all that, is the sauce of running the "mount" command and then restarting the docker container if the output is not as expected.
I use shell completion:
# File: /etc/bash_completion.d/docker-nfs-check # vim: set syntax=sh: # startdate: 2023-07-18-3 15:45 _docker_nfs_check() { local cur prev words cword; _init_completion || return _tmpfile1="$( mktemp )" # populate list find /etc/sysconfig/docker-nfs-check -mindepth 1 -maxdepth 1 ! -type d ! -name '.*' -printf '%P\n' > "${_tmpfile1}" COMPREPLY=($( compgen -W "$( cat ${_tmpfile1} )" -- "$cur" )) command rm -rf "${_tmpfile1:-NOTHINGTODEL}" 1>/dev/null 2>&1 return 0 } && complete -F _docker_nfs_check docker-nfs-check
And what it does is list the service definitions available in directory /etc/sysconfig/docker-nfs-check/
.
# File: /etc/sysconfig/docker-nfs-check/photoprism # dot-sourced by /usr/local/bin/docker-nfs-check # To load this file, you must set DOCKER_SERVICE to match this filename. # su to this user and then DS_USER="photoprism" # cd to this path DS_PATH="/home/photoprism/photoprism" # to run the docker-compose command on this container name DS_CONTAINER="photoprism" # how many lines should return from docker-compose exec ${this_filename} mount | grep nfs DS_LINES=3 # if the lines are incorrect, restart this systemd service DS_SERVICE="photoprism.service"
This is indeed a ridiculous hack and work-around, but it works for me. And clearly I'm running out of good blog topics I'm actually going to bother to write.
Comments