Last active
May 29, 2018 17:15
-
-
Save rcubitto/466ff1151e45c6e04da73a5fb0929d52 to your computer and use it in GitHub Desktop.
Monitor Nginx, PHP, and MySQL and notify via Slack
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
#!/bin/bash | |
info="Services restarted: " | |
# Nginx | |
ps -ef | grep nginx | grep -v grep > /dev/null | |
if [ $? != 0 ] | |
then | |
sudo service nginx start > /dev/null | |
info="$info Nginx, " | |
fi | |
# PHP | |
ps -ef | grep php | grep -v grep > /dev/null | |
if [ $? != 0 ] | |
then | |
sudo service php7.1-fpm start > /dev/null | |
info="$info PHP, " | |
fi | |
# MySQL | |
ps -ef | grep mysqld | grep -v grep > /dev/null | |
if [ $? != 0 ] | |
then | |
sudo service mysql start | |
info="$info MySQL." | |
fi | |
# Notify Slack | |
if [ $? != "Services restarted: " ] | |
then | |
url={COMPLETE} | |
escapedText=$(echo $info | sed 's/"/\"/g' | sed "s/'/\'/g" ) | |
json="{\"channel\": \"#general\", \"text\": \"$escapedText\"}" | |
curl -s -d "payload=$json" "$url" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment