5

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

6

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";

It takes the time provided and uses it on /sbin/shutdown -r (source). This means you can use any time that shutdown accepts, in your set timezone.

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
  • 2
    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

Set a cron job to check the existence of reboot-required and reboot if needed:

crontab -e 

Then append the above :

0 0 * * * [ -f /var/run/reboot-required ] && reboot

Save it and it's done.

0 0 * * * means to be executed everyday at 12AM (midnight), change it as you wish.

redseven
  • 230
  • 1
  • 10
Reda Salih
  • 241
  • 2
  • 7