Last active
September 25, 2019 23:59
-
-
Save zainengineer/2b8066f47c680213a6583f256e0d7452 to your computer and use it in GitHub Desktop.
auto resume service based on port availability (mysql example)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#to find processes use netstat -ntlp | grep "3306" | |
portResponse=$(netstat -lnt | awk '$6 == "LISTEN" && $4 ~ ".3306"') | |
if [ -z "$portResponse" ] | |
then | |
echo "Port available for mysql, staring mysql" | |
service mysql start | |
else | |
echo "mysql already running" | |
fi | |
script_path=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P ) | |
php "$script_path/resume_mysql.php"; | |
date > "$script_path/last_executed.log" | |
#redis restart | |
portResponse=$(echo PING | timeout 2 nc 127.0.0.1 6379) | |
patternCompare="PONG" | |
if [[ $portResponse =~ $patternCompare ]]; | |
then | |
echo "redis is running" | |
else | |
echo "redis is not running" && (cd /apps/docker/docker/redis && docker-compose restart) && echo "redis restarted" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment