Unattended-Upgrade upgrades and restarts my machine without any issues. However, I have a python script that runs infrequently, but when it runs it may take days to complete. I would like to suspend automatic reboots while this script runs.

What is the easiest way of achieving this?

  • Unattended upgrades does not allow a way to run a command to check. It, instead, uses the presence of /var/run/reboot-required to restart - so, if you could somehow prevent that file from being formed while your process is running...
    – muru
    Apr 21, 2015 at 15:17

2 Answers 2


You can use the configuration in this file (thx @muru):


and this line:

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

In a shell I would do that:

sudo sed -i 's/^Unattended-Upgrade::Automatic-Reboot "true";$/Unattended-Upgrade::Automatic-Reboot "false";/g' /etc/apt/apt.conf.d/50unattended-upgrades

Create a script for that and start you program inside the script. If it's finished revert the changes.

Or you can use this file:


and this line:

APT::Periodic::Unattended-Upgrade "0";
  • "0" means disabled
  • ">0" is the time interval in days.

This disables auto-update system-wide.

  • 2
    It would be better to disable automatic restart (Unattended-Upgrade::Automatic-Reboot "false";) than disable unattended upgrades altogether.
    – muru
    Apr 21, 2015 at 15:15
  • I don't want to disable automatic upgrade or automatic reboot, I just want to put either of them on hold while my python process is running.
    – Karalga
    Apr 21, 2015 at 15:31
  • @Karalga I have improved my answer.
    – A.B.
    Apr 21, 2015 at 15:38
  • 1
    hmm, but then the python process would need to run as root. But I suppose I could run a cron job that checks if my process is running, and if so change the line in unattended-upgrades. If its not running, the cron job could enable automatic restart again.
    – Karalga
    Apr 21, 2015 at 15:44
  • 1
    @Karalga: As you've never accepted any answer on this site: If this answer helped you, don't forget to click the grey at the left of this text, which means "yes, this answer is valid"! ;-)
    – Fabby
    Apr 21, 2015 at 20:40

I decided to create a script that checks if python is running and creates and deletes a configuration override file accordingly. Of course the test for the running python program can be more spicific, for example using -f /proc/$(cat something.pid)/status.

The bash files is:

#! /bin/bash
case "$(pgrep -xc python)" in

0) echo "No python running, ok to reboot" >> /root/scripts/pythonCheck.log
   if [ -e "/etc/apt/apt.conf.d/60dontreboot" ]; then
     rm "/etc/apt/apt.conf.d/60dontreboot"

*) echo "Python is running, shouldn't reboot" >> /root/scripts/pythonCheck.log
   if [ ! -e "/etc/apt/apt.conf.d/60dontreboot" ]; then
     echo 'Unattended-Upgrade::Automatic-Reboot "false"' > /etc/apt/apt.conf.d/60dontreboot

In my case, I have set the automatic reboot for 4am (also in 50unattended-upgrades), so I have added a crontab to execute the above script at 3:59am. I am happy with loosing one minute of work; my python script will just begin a couple of minutes later.

The crontab entry is:

59 3 * * * /root/scripts/pythonCheck.sh
  • I find it unlikely that the only python process that's running is your script, unless you don't have any GUI elements at all. Also, you don't have to replace that particular line. Just create a 60dontreboot file in /etc/apt/apt.conf.d/ that contains Unattended-Upgrade::Automatic-Reboot "false";, and delete it when done. Later files override earlier ones.
    – muru
    Apr 22, 2015 at 21:24
  • I have used a specific pid file in my actual code, but I wanted to keep the answer most general. When you say: "later files override earlier ones", do you mean by timestamp or because 60 > 50?
    – Karalga
    Apr 22, 2015 at 21:37
  • Because 60 > 50 (in lexicographic ordering, 6 > 50 as well).
    – muru
    Apr 22, 2015 at 21:38
  • may I enquire the reason for the downvote?
    – Karalga
    Apr 23, 2015 at 9:26
  • At the moment, that comment only notifies me. And I didn't downvote.
    – muru
    Apr 23, 2015 at 12:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .