Created
February 3, 2025 14:02
-
-
Save zaheeraws/26c4091f0a6033b6436c031cce3687c5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# Configuration | |
SERVICE_NAME="php83-php-fpm.service" | |
THRESHOLD=40 | |
SLACK_TOKEN="xoxb-XXXXXX" | |
SLACK_CHANNEL="CXXXX" | |
# Function to send Slack notification | |
send_slack_notification() { | |
local count=$1 | |
curl -X POST \ | |
-H "Content-type: application/json" \ | |
-H "Authorization: Bearer ${SLACK_TOKEN}" \ | |
-d "{ | |
\"channel\": \"${SLACK_CHANNEL}\", | |
\"text\": \"SS child process count: ${count}\", | |
\"username\": \"SS\", | |
\"icon_emoji\": \":violin:\" | |
}" \ | |
https://slack.com/api/chat.postMessage | |
} | |
# Get process count | |
PROCESS_COUNT=$(sudo systemctl status ${SERVICE_NAME} | grep "pool servings_conf" | wc -l) | |
# Log the current count (useful for debugging) | |
echo "$(date): Current process count: ${PROCESS_COUNT}" | |
# Check if process count exceeds threshold | |
if [ ${PROCESS_COUNT} -gt ${THRESHOLD} ]; then | |
echo "Process count (${PROCESS_COUNT}) exceeds threshold (${THRESHOLD})" | |
# Send notification to Slack | |
send_slack_notification ${PROCESS_COUNT} | |
# Restart the service | |
echo "Restarting ${SERVICE_NAME}..." | |
sudo systemctl restart ${SERVICE_NAME} | |
# Check if restart was successful | |
if [ $? -eq 0 ]; then | |
echo "Service restart completed successfully" | |
else | |
echo "Service restart failed" | |
send_slack_notification "WARNING: Failed to restart ${SERVICE_NAME}" | |
fi | |
else | |
echo "Process count is within normal range" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment