summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Filion <gabster@lelutin.ca>2013-11-15 03:19:40 -0500
committerGabriel Filion <gabster@lelutin.ca>2013-11-15 04:07:28 -0500
commit3c93ba233924d640c77a5b4d153360d1636d0964 (patch)
treeea34e17b3abc28a909000fa1c952beaef2c443ce
parent82cf365b2c7b4c98c84b2b1c39338fcdb33a86d9 (diff)
setmysqlpass: be more careful before plundering into action
Since this script is rooting the database, it'd be good to use a little more precaution so that we don't let systems be in an inconsistent case when crashing. In cases where the PATH variable is not appropriately set (variable is empty by default when script is invoked by puppet) the script shuts down mysql and then is not able to call most commands.
-rw-r--r--files/scripts/CentOS/setmysqlpass.sh20
-rw-r--r--files/scripts/Debian/setmysqlpass.sh21
2 files changed, 41 insertions, 0 deletions
diff --git a/files/scripts/CentOS/setmysqlpass.sh b/files/scripts/CentOS/setmysqlpass.sh
index 01d8fbf..b643edb 100644
--- a/files/scripts/CentOS/setmysqlpass.sh
+++ b/files/scripts/CentOS/setmysqlpass.sh
@@ -2,6 +2,26 @@
test -f /root/.my.cnf || exit 1
+must_have ()
+{
+ # Here, using "which" would not be appropriate since it also depends on
+ # PATH being set correctly. The type builtin command is unaffected by the
+ # environment.
+ type $1 >/dev/null
+ if [ $? -ne 0 ]; then
+ echo "Command '$1' not found, did you correctly set PATH ? Its current value is: $PATH" >&2
+ exit 1
+ fi
+}
+
+# Since this script is doing something rather unsafe with the database, we want
+# to be really careful to have all the necessary tools before doing anything so
+# that we don't end up in an inconsistent state.
+must_have sleep
+must_have mysql
+must_have killall
+must_have chown
+
rootpw=$(grep password /root/.my.cnf | sed -e 's/^[^=]*= *\(.*\) */\1/')
/sbin/service mysqld stop
diff --git a/files/scripts/Debian/setmysqlpass.sh b/files/scripts/Debian/setmysqlpass.sh
index f7d5357..f4ebee6 100644
--- a/files/scripts/Debian/setmysqlpass.sh
+++ b/files/scripts/Debian/setmysqlpass.sh
@@ -2,6 +2,27 @@
test -f /root/.my.cnf || exit 1
+must_have ()
+{
+ # Here, using "which" would not be appropriate since it also depends on
+ # PATH being set correctly. The type builtin command is unaffected by the
+ # environment.
+ type $1 >/dev/null
+ if [ $? -ne 0 ]; then
+ echo "Command '$1' not found, did you correctly set PATH ? Its current value is: $PATH" >&2
+ exit 1
+ fi
+}
+
+# Since this script is doing something rather unsafe with the database, we want
+# to be really careful to have all the necessary tools before doing anything so
+# that we don't end up in an inconsistent state.
+must_have sleep
+must_have mysql
+must_have killall
+must_have ls
+must_have chown
+
rootpw=$(grep password /root/.my.cnf | sed -e 's/^[^=]*= *\(.*\) */\1/')
/etc/init.d/mysql stop