User Tools

Site Tools


computing:servicebuilder

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
computing:servicebuilder [2026/09/05 23:25] oemb1905computing:servicebuilder [2026/09/05 23:33] (current) oemb1905
Line 26: Line 26:
 </code> </code>
  
 +====== Apache Restart ======
 +~~NOTOC~~
  
 +<code>
 +cat > /usr/local/bin/apache-restart.sh << 'EOF'
 +#!/bin/sh
 +#functions
 +RESTART="/bin/systemctl restart apache2.service"
 +SERVICE="apache2.service"
 +LOGFILE="/home/logs/apache.log"
 +#check for the word dead in the service output from systemctl
 +if
 +        systemctl status apache2.service | grep 'failed\|dead'
 +then
 +        echo "Jonathan, apache failed at $(date), so I restarted it for you." >> $LOGFILE
 +        $RESTART >> $LOGFILE
 +        mail -s "[apache2-restart]-$(hostname -f)-$(date)" friend@haacksnetworking.org < $LOGFILE
 +else
 +exit
 +fi
 +EOF
 +chmod 750 /usr/local/bin/apache-restart.sh
 +</code>
 +
 +====== Mariadb Restart =====
 +
 +<code>
 +cat > /usr/local/bin/mariadb-restart.sh << 'EOF'
 +#!/bin/sh
 +#functions
 +RESTART="/bin/systemctl restart mariadb.service"
 +STATUS="/bin/systemctl status mariadb.service"
 +SERVICE="mariadb.service"
 +LOGFILE="/home/logs/mysql.log"
 +#check for the word dead in the service output from systemctl
 +if
 +        $STATUS | grep "dead\|failed"
 +then
 +        echo "Jonathan, mariadb failed at $(date), so I restarted it for you." >> $LOGFILE
 +        $RESTART >> $LOGFILE
 +        mail -s "[mariadb-restart]-$(hostname)-$(date)" friend@haacksnetworking.org < $LOGFILE
 +else
 +exit
 +fi
 +EOF
 +chmod 750 /usr/local/bin/mariadb-restart.sh
 +</code>
 +
 +====== Fail2Ban Restart =====
 +<code>
 +cat > /usr/local/bin/fail2ban-restart.sh << 'EOF'
 +#!/bin/sh
 +#functions
 +RESTART="/bin/systemctl restart fail2ban.service"
 +SERVICE="fail2ban.service"
 +LOGFILE="/home/logs/fail2ban.log"
 +#check for the word dead in the service output from systemctl
 +if
 +        systemctl status fail2ban.service | grep 'failed\|dead'
 +then
 +        echo "Jonathan, fail2ban failed at $(date), so I restarted it for you." >> $LOGFILE
 +        $RESTART >> $LOGFILE
 +        mail -s "[fail2ban-restart]-$(hostname)-$(date)" friend@haacksnetworking.org < $LOGFILE
 +else
 +exit
 +fi
 +EOF
 +chmod 750 /usr/local/bin/fail2ban-restart.sh
 +</code>
 +
 +====== Qemu Agent Restart =====
 +<code>
 +cat > /usr/local/bin/qemuagent-restart.sh << 'EOF'
 +#!/bin/sh
 +#functions
 +RESTART="/bin/systemctl restart qemu-guest-agent.service"
 +SERVICE="qemu-guest-agent.service"
 +LOGFILE="/home/logs/qemu-guest-agent.log"
 +#check for the word dead in the service output from systemctl
 +if
 +        systemctl status qemu-guest-agent.service | grep 'failed\|dead'
 +then
 +        echo "Jonathan, qemu-guest-agent failed at $(date), so I restarted it for you." >> $LOGFILE
 +        $RESTART >> $LOGFILE
 +        mail -s "[qemu-guest-agent-restart]-$(hostname)-$(date)" friend@haacksnetworking.org < $LOGFILE
 +else
 +exit
 +fi
 +EOF
 +chmod 750 /usr/local/bin/qemuagent-restart.sh
 +</code>
 +
 +====== Amavis Restart =====
 +<code>
 +cat > /usr/local/bin/amavis-restart.sh << 'EOF'
 +#!/bin/sh
 +#functions
 +RESTART="/bin/systemctl restart amavis.service"
 +SERVICE="amavis.service"
 +LOGFILE="/home/logs/amavis.log"
 +#check for the word dead in the service output from systemctl
 +if
 +        systemctl status $SERVICE | grep 'failed\|dead'
 +then
 +        echo "Jonathan, amavis failed at $(date), so I restarted it for you." >> $LOGFILE
 +        $RESTART >> $LOGFILE
 +        mail -s "[amavis-restart]-$(hostname -f)-$(date)" friend@haacksnetworking.org < $LOGFILE
 +        rm $LOGFILE
 +else
 +exit
 +fi
 +EOF
 +chmod 750 /usr/local/bin/amavis-restart.sh
 +</code>
 +
 +====== ClamAV Restart =====
 +<code>
 +cat > /usr/local/bin/clamav-restart.sh << 'EOF'
 +#!/bin/sh
 +#functions
 +RESTART="/bin/systemctl restart clamav-freshclam.service"
 +SERVICE="clamav-freshclam.service"
 +LOGFILE="/home/logs/clamav.log"
 +#check for the word dead in the service output from systemctl
 +if
 +        systemctl status $SERVICE | grep 'failed\|dead'
 +then
 +        echo "Jonathan, clamav failed at $(date), so I restarted it for you." >> $LOGFILE
 +        $RESTART >> $LOGFILE
 +        mail -s "[clamav-restart]-$(hostname -f)-$(date)" friend@haacksnetworking.org < $LOGFILE
 +        rm $LOGFILE
 +else
 +exit
 +fi
 +EOF
 +chmod 750 /usr/local/bin/clamav-restart.sh
 +</code>
 +
 +====== Dovecot Restart =====
 +<code>
 +cat > /usr/local/bin/dovecot-restart.sh << 'EOF'
 +#!/bin/sh
 +#functions
 +RESTART="/bin/systemctl restart dovecot.service"
 +SERVICE="dovecot.service"
 +LOGFILE="/home/logs/dovecot.log"
 +#check for the word dead in the service output from systemctl
 +if
 +#       systemctl status $SERVICE | grep 'failed\|dead'
 +        systemctl status $SERVICE | grep 'inactive'
 +then
 +        echo "Jonathan, dovecot failed at $(date), so I restarted it for you." >> $LOGFILE
 +        $RESTART >> $LOGFILE
 +        mail -s "[dovecot-restart]-$(hostname -f)-$(date)" friend@haacksnetworking.org < $LOGFILE
 +        rm $LOGFILE
 +else
 +exit
 +fi
 +EOF
 +chmod 750 /usr/local/bin/dovecot-restart.sh
 +</code>
 +
 +====== Postfix Restart =====
 +<code>
 +cat > /usr/local/bin/postfix-restart.sh << 'EOF'
 +#!/bin/sh
 +#functions
 +RESTART="/bin/systemctl restart postfix.service"
 +SERVICE="postfix.service"
 +LOGFILE="/home/logs/postfix.log"
 +#check for the word dead in the service output from systemctl
 +if
 +        systemctl is-active $SERVICE | grep 'inactive'
 +then
 +        echo "Jonathan, postfix failed at $(date), so I restarted it for you." >> $LOGFILE
 +        $RESTART >> $LOGFILE
 +        mail -s "[postfix-restart]-$(hostname -f)-$(date)" friend@haacksnetworking.org < $LOGFILE
 +        rm $LOGFILE
 +else
 +exit
 +fi
 +EOF
 +chmod 750 /usr/local/bin/postfix-restart.sh
 +</code>
 +
 +====== Spam Assassin Restart =====
 +<code>
 +cat > /usr/local/bin/spamass-restart.sh << 'EOF'
 +#!/bin/sh
 +#functions
 +RESTART="/bin/systemctl restart spamassassin.service"
 +SERVICE="spamass-milter.service"
 +LOGFILE="/home/logs/spamass.log"
 +#check for the word dead in the service output from systemctl
 +if
 +        systemctl status $SERVICE | grep 'failed\|dead'
 +then
 +        echo "Jonathan, spamassassin failed at $(date), so I restarted it for you." >> $LOGFILE
 +        $RESTART >> $LOGFILE
 +        mail -s "[spamass-restart]-$(hostname -f)-$(date)" friend@haacksnetworking.org < $LOGFILE
 +        rm $LOGFILE
 +else
 +exit
 +fi
 +EOF
 +chmod 750 /usr/local/bin/spamass-restart.sh
 +</code>
 +
 +====== MariaDB Dump =====
 +<code>
 +cat > /usr/local/bin/mariadb-dump.sh << 'EOF'
 +DATE=`date +"%Y%m%d-%H:%M:%S"`
 +START1="$(date +%s)"
 +LOGFILE="/home/logs/mysql-dump.log"
 +/usr/bin/mysqldump    \
 +--defaults-extra-file=/etc/mysql/mysqlpassword.cnf \
 +--add-drop-database \
 +--all-databases     \
 +--allow-keywords    \
 +--comments          \
 +--complete-insert   \
 +--lock-all-tables   \
 +--skip-dump-date    \
 +--events            \
 +--flush-logs        \
 +--flush-privileges  \
 +--hex-blob          \
 +--opt               \
 +--routines          \
 +> /root/name-databases-all.sql
 +END1="$(date +%s)"
 +DURATION1=$[ ${END1} - ${START1} ]
 +MINUTES=$[ ${DURATION1} / 60 ]
 +echo "$(date) Jonathan, the db dump took exactly ${DURATION1} seconds and approximately ${MINUTES} minutes to complete." | tee -a $LOGFILE
 +mail -s "[mariadb-dump]-$(hostname)-$(date)" friend@haacksnetworking.org < $LOGFILE
 +rm $LOGFILE
 +EOF
 +chmod 750 /usr/local/bin/mariadb-dump.sh
 +</code>
 +
 + --- //[[alerts@haacksnetworking.org|oemb1905]] 2026/09/05 23:25//
computing/servicebuilder.1788650739.txt.gz · Last modified: by oemb1905