Restart all daemons

Sometimes a (directadmin) server runs out of swap space. It’s nice to know which service exactly is causing it but sometimes you do not have the time. A fast option to restart all services without having to figure out exactly which services you’ve got running (especially now that there’s the possibility of using 4 different versions of PHP).

#!/bin/bash

# Specifically for directadmin/custombuild and CentOS
# Detects (some) options and restarts daemons, then
# shows free swap space
###
# (c)opyleft Take13

OPTIONS=/usr/local/directadmin/custombuild/options.conf 

# Show free swap space
function swapfree {
	echo Swap free: `free -h | grep Swap | awk '{print $4}'`
	}

# Detect running php-fpm instances, restart
for PHP in `systemctl | grep php-fpm | awk -F . '{print $1}'`; do
	echo Restarting $PHP
	swapfree
done

# Detect webserver config, restart
WEBSERVER=`grep webserver $OPTIONS | awk -F = '{print $2}'`

case $WEBSERVER in
apache)		echo Restart apache
		systemctl restart httpd
		swapfree
;;
nginx)		echo Restart nginx
		systemctl resetart nginx
		swapfree
;;
nginx_apache)	echo Restart nginx
		systemctl restart nginx
		swapfree
		echo Restart apache
		systemctl restart httpd
		swapfree
;;
litespeed)	echo Restart litespeed
		systemctl restart lsws
		swapfree
;;
esac

# Restart exim
echo "Restart exim"
systemctl restart exim
swapfree

# Restart dovecot
echo "Restart dovecot"
systemctl restart dovecot
swapfree

# Detect database, restart
DB=`grep inst $OPTIONS | awk -F = '{print $2}'`
case $DB in
mysql)		echo Restart MySQL
		systemctl restart mysqld
		swapfree
;;
mariadb)	echo Restart MariaDB
		systemctl restart mariadb
		swapfree
;;
esac

echo "*kusje*"

Leave a Reply

Your email address will not be published. Required fields are marked *