Bug#996926: unattended-upgrades reboots when Unattended-Upgrade::Automatic-Reboot = False

2021-10-20 Thread Bálint Réczey
Control: tags -1 moreinfo unreproducible invalid

Hi Chris,

Chris Stromsoe  ezt írta (időpont: 2021. okt. 20., Sze, 23:03):
>
> Package: unattended-upgrades
> Version: 1.11.2
>
> I recently started using unattended-upgrades to keep a machine up to date.
> After installing, I've had a few instances where the machine restarted on
> its own.  I believe that unattended-upgrades rebooted my machine even
> though Automatic-Reboot is set to False.
>
> Logged from syslog:
>
> Oct 20 12:15:43 potato systemd[1]: Started Unattended Upgrades Shutdown.

This is just the unattended-upgrades.service starting.

> From /etc/apt/apt.conf.d/50unattended-upgrades:
>
> Unattended-Upgrade::Automatic-Reboot "false";
>
>
> Looking at the source for /usr/bin/unattended-upgrade, reboots are handled
> by reboot_if_requested_and_needed().  The check for Automatic-Reboot is on
> lines 1336 and 1337.  I believe the check is wrong.
>
> The test for False on line 1337 should be True, to indicate that if
> Automatic-Reboot is not set to True in the configuration file, the
> function should return without proceeding.
>
> 1331 def reboot_if_requested_and_needed():
> 1332 # type: () -> None
> 1333 """auto-reboot (if required and the config for this is set)"""
> 1334 if not os.path.exists(REBOOT_REQUIRED_FILE):
> 1335 return
> 1336 if not apt_pkg.config.find_b(
> 1337 "Unattended-Upgrade::Automatic-Reboot", False):
> 1338 return
> 1339 # see if we need to check for logged in users
> 1340 if not apt_pkg.config.find_b(
> 1341 "Unattended-Upgrade::Automatic-Reboot-WithUsers", True):
> 1342 users = logged_in_users()
> 1343 if users:
> 1344 msg = gettext.ngettext(
> 1345 "Found %s, but not rebooting because %s is logged in." % 
> (
> 1346 REBOOT_REQUIRED_FILE, users),
> 1347 "Found %s, but not rebooting because %s are logged in." 
> % (
> 1348 REBOOT_REQUIRED_FILE, users),
> 1349 len(users))
> 1350 logging.warning(msg)
> 1351 return
> 1352 # reboot at the specified time
> 1353 when = apt_pkg.config.find(
> 1354 "Unattended-Upgrade::Automatic-Reboot-Time", "now")
> 1355 logging.warning("Found %s, rebooting" % REBOOT_REQUIRED_FILE)
> 1356 cmd = ["/sbin/shutdown", "-r", when]
> 1357 try:
> 1358 shutdown_msg = subprocess.check_output(cmd, 
> stderr=subprocess.STDOUT)
> 1359 if shutdown_msg.strip():
> 1360 logging.warning("Shutdown msg: %s", shutdown_msg.strip())
> 1361 except Exception as e:
> 1362 logging.error("Failed to issue shutdown: %s", e)
> 1363

This seems to work OK according to your next email.
I think something else restarted the system.

Cheers,
Balint



Bug#996926: unattended-upgrades reboots when Unattended-Upgrade::Automatic-Reboot = False

2021-10-20 Thread Chris Stromsoe

Package: unattended-upgrades
Version: 1.11.2

I recently started using unattended-upgrades to keep a machine up to date. 
After installing, I've had a few instances where the machine restarted on 
its own.  I believe that unattended-upgrades rebooted my machine even 
though Automatic-Reboot is set to False.


Logged from syslog:

Oct 20 12:15:43 potato systemd[1]: Started Unattended Upgrades Shutdown.



From /etc/apt/apt.conf.d/50unattended-upgrades:


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


Looking at the source for /usr/bin/unattended-upgrade, reboots are handled 
by reboot_if_requested_and_needed().  The check for Automatic-Reboot is on 
lines 1336 and 1337.  I believe the check is wrong.


The test for False on line 1337 should be True, to indicate that if 
Automatic-Reboot is not set to True in the configuration file, the 
function should return without proceeding.


1331 def reboot_if_requested_and_needed():
1332 # type: () -> None
1333 """auto-reboot (if required and the config for this is set)"""
1334 if not os.path.exists(REBOOT_REQUIRED_FILE):
1335 return
1336 if not apt_pkg.config.find_b(
1337 "Unattended-Upgrade::Automatic-Reboot", False):
1338 return
1339 # see if we need to check for logged in users
1340 if not apt_pkg.config.find_b(
1341 "Unattended-Upgrade::Automatic-Reboot-WithUsers", True):
1342 users = logged_in_users()
1343 if users:
1344 msg = gettext.ngettext(
1345 "Found %s, but not rebooting because %s is logged in." % (
1346 REBOOT_REQUIRED_FILE, users),
1347 "Found %s, but not rebooting because %s are logged in." % (
1348 REBOOT_REQUIRED_FILE, users),
1349 len(users))
1350 logging.warning(msg)
1351 return
1352 # reboot at the specified time
1353 when = apt_pkg.config.find(
1354 "Unattended-Upgrade::Automatic-Reboot-Time", "now")
1355 logging.warning("Found %s, rebooting" % REBOOT_REQUIRED_FILE)
1356 cmd = ["/sbin/shutdown", "-r", when]
1357 try:
1358 shutdown_msg = subprocess.check_output(cmd, 
stderr=subprocess.STDOUT)
1359 if shutdown_msg.strip():
1360 logging.warning("Shutdown msg: %s", shutdown_msg.strip())
1361 except Exception as e:
1362 logging.error("Failed to issue shutdown: %s", e)
1363