Skip to content

Instantly share code, notes, and snippets.

@zainengineer
Last active September 25, 2019 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zainengineer/2b8066f47c680213a6583f256e0d7452 to your computer and use it in GitHub Desktop.
Save zainengineer/2b8066f47c680213a6583f256e0d7452 to your computer and use it in GitHub Desktop.
auto resume service based on port availability (mysql example)
#!/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