Don't forget permission to bitnami with permission 755.
Last active
January 15, 2023 03:31
-
-
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.
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 | |
| # 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 |
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
| # 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