apt-get upgrade auto restart services

I have an unattended script for installing servers. At the beginning of the script there is a sudo apt-get dist-upgrade --yes. The dist upgrade has a nasty user input screen at its end asking to restart services:
enter image description here

Is it possible to autoaccept service restarts or disable this screen? It breaks my whole script. Also Im afraid it might leave my server stuck at some point when updating...

same result with apt-get upgrade

edit: I tried without success:

#!/bin/bash
sudo apt-get update
sudo apt-get remove apt-listchanges --assume-yes --force-yes &&
#using export is important since some of the commands in the script will fire in a subshell
export DEBIAN_FRONTEND=noninteractive &&
export APT_LISTCHANGES_FRONTEND=none &&
#lib6c was an issue for me as it ignored the DEBIAN_FRONTEND environment variable and fired a prompt anyway. This should fix it
echo 'libc6 libraries/restart-without-asking boolean true' | debconf-set-selections &&
echo "executing wheezy to jessie" &&
find /etc/apt -name "*.list" | xargs sed -i '/^deb/s/wheezy/jessie/g' &&
echo "executing autoremove" &&
sudo apt-get -fuy --force-yes autoremove &&
echo "executing clean" &&
sudo apt-get --force-yes clean &&
echo "executing update" &&
sudo apt-get update &&
echo "executing upgrade" &&
sudo apt-get --force-yes -o Dpkg::Options::="--force-confold" --force-yes -o Dpkg::Options::="--force-confdef" -fuyq upgrade &&
echo "executing dist-upgrade" &&
sudo apt-get --force-yes -o Dpkg::Options::="--force-confold" --force-yes -o Dpkg::Options::="--force-confdef" -fuyq dist-upgrade
1

4 Answers

Try sudo DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade --y, it should prevent any of these prompts

Use:

sudo NEEDRESTART_SUSPEND=1 apt-get dist-upgrade --yes
1

The prompt is probably coming from needrestart

1

Vardogor's answer worked for me, just with a tiny difference, one dash (-y) and not two (--y):

sudo DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -y

It gives this error if I use two dashes:

E: Command line option --y is not understood in combination with the other options

I'm doing it on Ubuntu 22.04 LTS

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like