Automate service restart requests caused by updates

Hello
I have an unattanded physical Kali machine running ADGuard Home and I would like to automate the update process without any user input or intervention. I am aware that this is not the optimal choice but I do not care, I can rebuild this box at anytime and I do not have any particular data to worry about. It is a mini-PC with no screen attached, no mouse, and no keyboard, attached to my router via LAN cable.

I sometimes connect to this computer using SSH to run updates with apt and I added the -y option so I do not get prompted whether to keep/uninstall/review etc etc updates.

sudo apt update -y && sudo apt upgrade -y && sudo apt clean -y && sudo apt full-upgrade -y && sudo apt dist-upgrade && sudo apt autoremove -y && sudo apt purge -y

Often, during the update, at the end of the process, I get prompted to restart some services like the following:

And I have to physically press ENTER on my remote keyboard to accept the default action. My question is: Can this also be automated so that this unattended box remain completely unattanded? Is there a way to say YES (equivalent to PRESS ENTER) automatically?

I would also like to schedule the above command to run it on a particular schedule, hence almost 100% automation. Is this possible?

Thanks

as your running as sudo, add this to the end of your prompt;

&& -E, --preserve-env

basically your saying preserve the running environment for this user, so it should just restart services when its finished updating…

or you could edit the /etc/needrestart/needrestart.conf file, changing the line:

#$nrconf{restart} = ‘i’;

to
$nrconf{restart} = ‘a’; if we want to restart the services automatically, or
$nrconf{restart} = ‘l’; to simply list the services that need restart.

1 Like

Thanks for the great tip, I’ll try both of them and see what suits me. Thanks again