I have a simple shell script that I’m trying to use to test Galera Cluster for MariaDB’s node state change notification mechanism, running on an AWS Ubuntu 20.04 LTS instance. The script is a stripped down one based on the example script provided by Galera:
#!/bin/sh -eu
echo "Node Status Change:" > /home/ubuntu/Notification.txt
while [ $# -gt 0 ]
do
case $1 in
--status)
echo " STATUS=$2" > /home/ubuntu/Notification.txt
shift
;;
--uuid)
echo " CLUSTER_UUID=$2" > /home/ubuntu/Notification.txt
shift
;;
--primary)
echo " PRIMARY=$2" > /home/ubuntu/Notification.txt
shift
;;
--index)
echo " INDEX=$2" > /home/ubuntu/Notification.txt
shift
;;
--members)
echo " MEMBERS=$2" > /home/ubuntu/Notification.txt
shift
;;
esac
shift
done
exit 0
When I run this script myself from the command-line it works as expected, and the echo command arguments are written to /home/ubuntu/Notification.txt
. But when the Galera notification mechanism executes it it fails with (datetime header stripped for brevity):
/etc/mysql/scripts/wsrep_notify.sh: 3: cannot create /home/ubuntu/Notification.txt: Directory nonexistent
I’m logged on as the same user that MariaDB is running as, and the permissions for /home/ubuntu/Notification.txt
are -rw-rw-rw-
.
I tried replacing #!/bin/sh -eu
with #!/bin/bash
, which also executes correctly from the command-line. But that fails when executed by Galera with these errors:
/etc/mysql/scripts/wsrep_notify.sh: line 3: /home/ubuntu/Notification.txt: No such file or directory
/etc/mysql/scripts/wsrep_notify.sh: line 9: /home/ubuntu/Notification.txt: No such file or directory
/etc/mysql/scripts/wsrep_notify.sh: line 13: /home/ubuntu/Notification.txt: No such file or directory
/etc/mysql/scripts/wsrep_notify.sh: line 17: /home/ubuntu/Notification.txt: No such file or directory
/etc/mysql/scripts/wsrep_notify.sh: line 21: /home/ubuntu/Notification.txt: No such file or directory
/etc/mysql/scripts/wsrep_notify.sh: line 25: /home/ubuntu/Notification.txt: No such file or directory
The errors are similar enough that it seems like the underlying cause is the same in both cases, but I’m stumped as far as what that cause could be. The script is clearly executing, so security on the script file isn’t an issue.
Thoughts?
Dan Parker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
How about creating the directory and using twice the same directory?
if [[ ! -d /home/ubuntu ]]; then
mkdir -p /home/ubuntu
fi
2