Linux service restart shell script Rumi, June 6, 2014 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 Configurations (Linux) Scripts LinuxShell
Install LAMP on Centos 7 with PHP 5.x/7.0/7.1/7.2 March 10, 2019 In this tutorial, I use the hostname server1.example.com with the IP p 192.168.1.100. These settings might differ for you, so you have to replace them where appropriate. I will add the EPEL repo here to install latest phpMyAdmin as follows: rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY* yum -y install epel-release To edit files… Read More
Install Xen Orchestra on Ubuntu / Debian September 23, 2023 Step 1: Update System Let’s start the installation by updating all the system packages: sudo apt update Also consider performing an upgrade: sudo apt upgrade -y Step 2: Install Node.js on Ubuntu / Debian Install dependencies. sudo apt install -y ca-certificates curl gnupg Import GPG repository keys: sudo mkdir -p… Read More
Install Rocket Chat on Centos 7with Jitsi Video Conferencing September 21, 2018 Add the epel repository and update everything. yum -y install epel-release nano && yum -y update Populate the yum repo with the mongodb-org repository nano /etc/yum.repos.d/mongodb-org.repo Paste this into the new file: [mongodb-org] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc To write and save do: CTRL-O, CTRL-X Now we need to… Read More