Eu encontrei uma solução depois de pesquisar um pouco.
O problema se origina de inotifywait
subshell como @mikeserv declarado nos comentários acima.
Então eu tive que escrever um método de limpeza para isso. Meu script:
#!/bin/bash
#
#
# script for immediatly changing the owner and group of the let's encrypt challenge file in the given webroot
Pidfile="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/run-file-chowner.pid
echo $$ > $Pidfile
function terminate_process () {
trap - SIGHUP SIGINT SIGTERM SIGQUIT
printf "\nTerminating process...\n"
rm "$Pidfile" > /dev/null 2>&1;
kill -- -$$
exit $1
}
function main () {
trap terminate_process SIGHUP SIGINT SIGTERM SIGQUIT
local OPTIND D opt
while getopts D: opt;
do
case $opt in
D)
Domain=$OPTARG;;
esac
done
shift $((OPTIND-1))
case $Domain in
'domain-b.com')
VHost="doma-www"
;;
'domain-a.com')
VHost="domb-www"
;;
*)
printf "\nScript usage : [ $0 -D \"example.com\" ]\n\n"
exit 1;
;;
esac
WebPath=/var/www/$Domain/$VHost/htdocs/public/.well-known/acme-challenge
inotifywait -m $WebPath | while read -r dir event name; do
case $event in
CREATE)
chown $VHost:$VHost $WebPath/$name
printf "\nOwner and group of \"$name\" were changed to $VHost...\n"
;;
DELETE)
printf "\nThe file \"$name\" was deleted\n"
terminate_process 0
;;
*)
printf "\nEvent $event was triggered.\n"
;;
esac
done
}
main "$@"
Nesta saída, quando um arquivo na pasta monitorada é criado e excluído:
root #: bash file-chowner -D dom-a.com
Setting up watches.
Watches established.
Owner and group of "test" were changed to doma-www...
Event OPEN was triggered.
Event ATTRIB was triggered.
Event CLOSE_WRITE,CLOSE was triggered.
Event ATTRIB was triggered.
The file "test" was deleted
Terminating process...
Terminated
Terminating process...
Terminated