Skip to content

Instantly share code, notes, and snippets.

@rcubitto
Last active May 29, 2018 17:15
Show Gist options
  • Save rcubitto/466ff1151e45c6e04da73a5fb0929d52 to your computer and use it in GitHub Desktop.
Save rcubitto/466ff1151e45c6e04da73a5fb0929d52 to your computer and use it in GitHub Desktop.
Monitor Nginx, PHP, and MySQL and notify via Slack
#!/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