Good day all,
I have a Docker Container with Ubuntu OS and MySQL installed.
I need to restart the MySQL once a day and would normally use cron to do this.
When I run the script via the CLI the scripts runs perfectly within the Docker Container.
Script contents:
#!/bin/bash
echo "Stopping MySQL"
service mysql stop
sleep 15s
echo "Starting MySQL"
service mysql start
sleep 10s
echo "MySql Restarted"
service mysql status
sleep 10s
Log when running from CLI, using ./mysqlRestart >>/var/log/mysqlRestart 2>&1:
Stopping MySQL
Stopping MySQL database server mysqld ...done.
Starting MySQL
Starting MySQL database server mysqld su: warning: cannot change directory to /nonexistent: No such file or directory ...done.
MySql Restarted
/usr/bin/mysqladmin Ver 8.0.30-0ubuntu0.20.04.2 for Linux on x86_64 ((Ubuntu)) Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Server version 8.0.30-0ubuntu0.20.04.2 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/run/mysqld/mysqld.sock Uptime: 11 sec
Threads: 2 Questions: 8 Slow queries: 0 Opens: 119 Flush tables: 3 Open tables: 38 Queries per second avg: 0.727
crontab -e entry: */5 * * * * bash /usr/local/bin/mysqlRestart >>/var/log/mysqlRestart 2>&1
Log when running from crontab:
Stopping MySQL /usr/local/bin/mysqlRestart: line 4: service: command not found
Starting MySQL /usr/local/bin/mysqlRestart: line 7: service: command not found
MySql Restarted /usr/local/bin/mysqlRestart: line 10: service: command not found