Linux service restart shell script Rumi, November 29, 2013November 29, 2013 I badly needed a script that would check if my running services (in this script it'll check varnish and apache2 services) are alive- if not, it'll restart the dead service and write a log. Pretty handy! #!/bin/sh STARTAPACHE="/etc/init.d/apache2 start" STARTVARNISH="/etc/init.d/varnish start" LOGFILE=/var/log/service_uptime.log ################ Check Varnish ################# SERVICE='varnish' echo "" >> $LOGFILE echo `date` >> $LOGFILE if ps ax | grep -v grep | grep $SERVICE > /dev/null then echo "$SERVICE service running, everything is OK" >> $LOGFILE else echo "$SERVICE is not running, restarting $SERVICE" >> $LOGFILE checkvarnish=`ps ax | grep -v grep | grep -c varnish` if [ $checkvarnish -le 0 ] then $STARTVARNISH if ps ax | grep -v grep | grep $SERVICE > /dev/null then echo "$SERVICE service is now restarted, everything is OK" >> $LOGFILE fi fi fi ############### Check Apache ################ SERVICE='apache2' if ps ax | grep -v grep | grep $SERVICE > /dev/null then echo "$SERVICE service running, everything is OK" >> $LOGFILE else echo "$SERVICE is not running, restarting $SERVICE" >> $LOGFILE checkapache=`ps ax | grep -v grep | grep -c apache2` if [ $checkapache -le 0 ] then $STARTAPACHE if ps ax | grep -v grep | grep $SERVICE > /dev/null then echo "$SERVICE service is now restarted, everything is OK" >> $LOGFILE fi fi fi exit 0 Related Administrations Scripts Service RestartShell
Install Apache2, PHP 7.2 and MariaDB 10.5 on Debian 11 February 18, 2023 First, update all the packages of the system by below-mentioned command: sudo apt update After updating packages, now install the dependencies required by the below-mentioned command: sudo apt install software-properties-common ca-certificates lsb-release apt-transport-https Enable SURY Repository The following step is to integrate the SURY repository into our system. SURY is… Read More
MySQLDump Shell script for backup April 21, 2013 You can use the following script to dump mysql database and can add to crontab entry for daily backup! #!/bin/sh DAY=`/bin/date +%Y%m%d` TFILE="/backup/MYDB.$DAY.gz" mysqldump -u root -p'MYPASSWORD' MYDB | gzip > $TFILE echo "cache dump completed, dump script by rumi (hasan.emdad@mango.com.bd)" Related Read More
Assign range of IP addresses to an interface October 2, 2018 For example, you need to assign the IP range 192.168.10.6 – 192.168.10.100 to your eth0 interface. Create a range file in /etc/sysconfig/network-scripts/ifcfg-eth0-range0 as below DEVICE=eth0 BOOTPROTO=static IPADDR_START=192.168.10.6 IPADDR_END=192.168.10.100 NETMASK=255.255.255.0 CLONENUM_START=1 ONBOOT=yes TYPE=Ethernet CLONENUM_START is the number that will be assigned to the first IP alias interface (eth0:1 in this example)…. Read More