The "-S" switch is important as it works with sockets if you use "-f" it will not detect the socket file is there.
if [ ! -S "/var/lib/mysql/mysql.sock" ]; then
echo "Socket does not exist, restarting"
service mysqld restart
bash, socket, mysql, existsthe, quot, sockets, detect, var, lib, echo, restarting, mysqld, restart, fi,