Script Bash Untuk Restart Otomatis Httpd dan Apache2

Friday, June 17, 2016 , , 0 Comments

Halo gens, ini ane ada script baru buat kalian para sysadmin, si script ini menolong kita ketika server apache down baik karena si server lelah atau karena ada yang iseng. Karena beberapa kali kejadian apache berhenti tiba tiba sehingga web tidak bisa di akses. Oke langsung aja yaa script nya pendek kok ini diaa..

-----------------------------------------
#!/bin/bash
# Apache Process Monitor
# Restart Apache Web Server When It Goes Down
# -------------------------------------------------------------------------
# Copyright (c) 2003 nixCraft project
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://sidharmo.blogspot.com for more information.
# -------------------------------------------------------------------------
# RHEL / CentOS / Fedora Linux restart command
RESTART="/sbin/service httpd restart"
# uncomment if you are using Debian / Ubuntu Linux
#RESTART="/etc/init.d/apache2 restart"
#path to pgrep command
PGREP="/usr/bin/pgrep"
# Httpd daemon name,
# Under RHEL/CentOS/Fedora it is httpd
# Under Debian 4.x it is apache2
HTTPD="httpd"
# find httpd pid
$PGREP ${HTTPD}
if [ $? -ne 0 ] # if apache not running
then
 # restart apache
 $RESTART
fi



lalu save dengan nama terserah.sh kalo gua save pake autorestart.sh terus disimpennya di /home/dharmo/autorestart.sh

terus kasih permision eksekusi
chmod +x autorestart.sh

trus setting cron terserah mau berapa menit, bagus nya sih dibawah 5 menit supaya jika apache down tidak akan terlalu lama web kita mati.
ini gua setting 5 menit kalo mau kurang dari 5 menit ganti aja angka 5 nya
*/5 * * * * /home/dharmo/autorestart.sh

udah itu lu coba stop httpd or apache2 nya trus akses web lu pasti mati ahahah, trus tunggu sampe 5 menit kalo lu setting cron nya 5 menit kalo setelah 5 menit webnya masih belum bisa ke buka ada yang salah berarti cek lagi semuanya :)

0 comments: