My VPS is running at Ubuntu Linux. The Apache2 Server is serving 6 websites. If, on errors (e.g. out-of-memory), the websites are down until the apache2 server is restarted manually. If, this happens at night, then there will be several hours before websites are back online.
To avoid this, we can test website connectivity every few minutes (added to crontab job) and restart the apache2 server if websites are down.
1 2 3 4 5 6 7 8 9 | #!/bin/bash if ( wget --timeout=5 -q --spider https://helloacm.com ) then echo "ok" else sudo service apache2 restart # or /etc/init.d/httpd restart echo "httpd restarted" fi |
#!/bin/bash if ( wget --timeout=5 -q --spider https://helloacm.com ) then echo "ok" else sudo service apache2 restart # or /etc/init.d/httpd restart echo "httpd restarted" fi
The option –spider ignores downloading the content. You can also mail the apache2 log in the else statement.
Add the script to the crontab (you would need the the root user).
*/5 * * * * /var/www/check_server.sh
With this script, the server will check for apache2 and restart it if websites are down.
–EOF (The Ultimate Computing & Technology Blog) —
GD Star Rating
loading...
233 wordsloading...
Last Post: Static Object, Global Variable, Lazy Loading in C#
Next Post: Compute the Number of Trailing Zeros for a Factorial in C++