Shell Script - How to run script after mysql is ready?
Solution 1
Finally I found the answer! :D
while !(mysqladmin ping)
do
sleep 3
echo "waiting for mysql ..."
done
echo "starting the main script"
#main script
#main script
#main script
Solution 2
THANK YOU for bringing that mysqladmin ping command to my attention!
It's going to be a big help when dealing with Docker.
Here's what I ended up doing:
# Returns true once mysql can connect.
mysql_ready() {
mysqladmin ping --host=database --user=root --password=MYSQL_ROOT_PASSWORD > /dev/null 2>&1
}
while !(mysql_ready)
do
sleep 3
echo "waiting for mysql ..."
done
Related videos on Youtube
KiddoDeveloper
Updated on September 18, 2022Comments
-
KiddoDeveloper over 1 year
I am learning Kubernetes. I have a question related to the K8s run command.
Command:
kubectl run testpod --image=nginx:alpine
As per K8s documentation., run command creates a deployment or job to manage the containers.
Question: When I run the above commands, I can not see any new deployment. Why? Is it creating only pod?
Question: I am using Docker desktop. When I run above command, it is showing two different instances in docker desktop. Why two different instances?
Question: If I delete any instance from Docker desktop, a new instance is automatically generated. Why? I knew about deployment like if deployment behind of pod and that pod is down or deleted, deployment will automatically create a new pod. But, I cannot any deployment there.
-
Gayan Weerakutti over 8 years
-
Oki Erie Rinaldi over 8 yearsI need the script to run at the startup. So it must wait for mysql service. Good reference anyway ..
-
ItayB over 2 yearsdid you try
kubectl get deployment --all-namespaces
? -
KiddoDeveloper over 2 yearsYes, I knew this command and already cross-checked it. This command is showing only 1 deployment i.e.'kube-system'
-
ItayB over 2 yearswhat about
replicaset
? -
Arutsudar Arut over 2 yearsCan you check all the resources using the command
kubectl get po,rs,rc,deploy
. If possible attach the output of this. (May be at least the ones which have the nametestpod
.) We can see if any ReplicationSet or ReplicationController or Deployment is available in your cluster. -
Arutsudar Arut over 2 yearsCan you check what is the
kind
displayed in the yaml, when you run the commandkubectl run testpod --image=nginx:alpine --dry-run -o yaml
. If possible attach this output as well.
-
-
gwarah almost 8 yearsBe careful with many iterations on shell loop. Se this issue.