Skip to content

Instantly share code, notes, and snippets.

@MattHealy
Last active April 22, 2022 10:58
Show Gist options
  • Save MattHealy/db3524417b21f475354144ff47dcc476 to your computer and use it in GitHub Desktop.
Save MattHealy/db3524417b21f475354144ff47dcc476 to your computer and use it in GitHub Desktop.
Check if Apache is running, and if not, restart it
#!/bin/sh
PORT=80
HP=:$PORT
echo 'Checking to see if Apache is up...'
if ( /usr/sbin/lsof -Pni $HP | grep "$PORT (LISTEN)" 2>&1 >/dev/null ); then
echo 'Apache is up';
else
echo 'Apache is down, restarting...';
/sbin/service httpd restart
logger -p mail.info apache_check_restart.sh restarting Apache
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment