This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Automatic weekly updates and reboot server if needed Ubuntu
#1
Automatic weekly updates and reboot server if needed Ubuntu
I have been running this for just over 2 years without any issues. This includes the script updating MySQL. But your usage may very. So use with caution.

To do weekly updates and reboot server if needed run:

Code:
nano /etc/cron.weekly/updater

Code:
#!/bin/bash
/usr/bin/dpkg --configure -a
/usr/bin/apt-get update
/usr/bin/apt-get -qy dist-upgrade
/usr/bin/apt-get install -f
/usr/bin/apt-get clean
/usr/bin/apt-get -qy autoremove


if [ -f /var/run/reboot-required ]; then
sudo touch /forcefsck
sudo reboot
else
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
exit 0
fi

Code:
sudo chmod +x '/etc/cron.weekly/updater'
sudo chmod 755 '/etc/cron.weekly/updater'

Also make sure you edit fsck so it forces the fix.

Code:
nano /etc/default/rcS

Change the line at the end of that file to:

Code:
FSCKFIX=yes

from:

Code:
#FSCKFIX=no

F3 will save the file and Ctrl+X will exit nano.
Reply
Thanks given by:
#2
RE: Automatic weekly updates and reboot server if needed Ubuntu
Full disclosure. My update script is slightly different as I also clean out logs.

This is what mine looks like:

Code:
#!/bin/bash
/usr/bin/dpkg --configure -a
/usr/bin/apt-get update
/usr/bin/apt-get -qy dist-upgrade
/usr/bin/apt-get install -f
/usr/bin/apt-get clean
/usr/bin/apt-get -qy autoremove

#Backup Logs
rm -rf /var/sentora/hostdata/zadmin/logs.zip
cd /var/
zip -r /var/sentora/hostdata/zadmin/logs.zip log
dropbox_uploader delete /logs.zip
dropbox_uploader upload /var/sentora/hostdata/zadmin/logs.zip /logs.zip

#Clean Logs
find /var/log -type f -delete
touch /var/log/dovecot.log
touch /var/log/dovecot-info.log
touch /var/log/dovecot-debug.log
chown vmail.mail /var/log/dovecot*
service dovecot restart

if [ -f /var/run/reboot-required ]; then
sudo touch /forcefsck
sudo reboot
else
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
exit 0
fi

But it really isn't advised to delete the logs. I have a system that backs up the logs once a week then deletes them.

I did this because my server stopped working after about 18 Months because my log files were over 6GBs (I only had a 20GB drive).

My setup is fully automated. I never have to look after it. I am happy with my setup because it is for me. But I would never do this setup for a client. So use this with your own discretion.

Reply
Thanks given by: TGates
#3
RE: Automatic weekly updates and reboot server if needed Ubuntu
Still using this now.

It works great!
Reply
Thanks given by:


Possibly Related Threads...
Thread Author Replies Views Last Post
Upgrade to Ubuntu 16.04 from 14.04 HogensHero 7 10,078 10-04-2019, 11:20 AM
Last Post: type-00
Ubuntu: How to setup TLS on postfix and dovecot Diablo925 28 59,638 02-15-2018, 08:46 PM
Last Post: duane
[How-To] Install the perfect Sentora server using CentOS 7 betatester3.0 0 3,221 10-18-2017, 12:55 AM
Last Post: betatester3.0

Forum Jump:


Users browsing this thread: 1 Guest(s)