Skip to content

Instantly share code, notes, and snippets.

@hx-natthawat
Last active January 15, 2023 03:31
Show Gist options
  • Select an option

  • Save hx-natthawat/5a9aeb12d8059c3135b196e4eb9f2c54 to your computer and use it in GitHub Desktop.

Select an option

Save hx-natthawat/5a9aeb12d8059c3135b196e4eb9f2c54 to your computer and use it in GitHub Desktop.
Script for every 5 mins check and auto restart Bitnami Apache when down.

Don't forget permission to bitnami with permission 755.

#!/bin/bash
# Check if the Apache service is running
status=$(sudo /opt/bitnami/ctlscript.sh status apache)
# Status checker
if [[ $status != *"running"* ]]; then
# Restart the Apache service
sudo /opt/bitnami/ctlscript.sh restart apache
echo "Apache service has been restarted at $(date)" >> /home/bitnami/auto-restart.log
else
echo "Apache service is running at $(date)" >> /home/bitnami/auto-restart.log
fi
# Edit the crontab file
crontab -e
# Add the following line at the bottom of the file
## SAMPLE
# */5 * * * * /path/to/script.sh >> /path/to/log.txt 2>&1
## Example
*/5 * * * * /home/bitnami/auto-restart.sh >> /home/bitnami/auto-restart.log 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment