3

I have setup automatic updates and it updates automatically. However, there are updates that require a restart and I know

Unattended-Upgrade::Automatic-Reboot "true";

will set it to reboot. But it reboots as soon as it updates. That could be at any time of the day, when my users are using my server. I want it to restart at a specific time, say 12:00 am that night. How do I do that?

2 Answers2

4

Have a look in /etc/apt/apt.conf.d/50unattended-upgrades. You want Unattended-Upgrade::Automatic-Reboot-Time:

// If automatic reboot is enabled and needed, reboot at the specific
// time instead of immediately
//  Default: "now"
//Unattended-Upgrade::Automatic-Reboot-Time "02:00";
Andrew Schulman
  • 8,561
  • 21
  • 31
  • 47
  • 1
    Do you know whether this time is in local timezone or in UTC? I don’t see this detail mentioned in [`unattended-upgrade(8)`](https://manpages.debian.org/bullseye/unattended-upgrades/unattended-upgrade.8.en.html). – Franklin Yu Dec 11 '21 at 01:19
  • I don't know. I guess it depends on whether apt has your TZ environment variable set. – Andrew Schulman Dec 16 '21 at 22:49
1

You can disable automatic reboot by setting in your configuration file :

Unattended-Upgrade::Automatic-Reboot "false"

Reconfigure it :

dpkg-reconfigure -plow unattended-upgrades

Write a script to check whether a reboot is required :

#!/bin/bash
if [ -f /var/run/reboot-required ]; then 
/sbin/reboot now 
fi

Set the correct permissions on the script :

chmod +x <script_name>.sh

Set a cron job so it will be executed everyday at 12 am.

crontab -e 

Then append the above :

0 0 * * * <path_to_your_script>.sh

Save it and it's done.

Reda Salih
  • 231
  • 2
  • 7