upgrades: Use a custom service for manual update

- Do not enable/start service during package install/upgrade
- Configure needrestart to skip restarting service

Closes: #1638.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
[sunil: Provide proper regex string in needrestart configuration with qr()]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2020-06-13 20:32:09 -04:00 committed by Sunil Mohan Adapa
parent 10617b900e
commit 2d1ced84cd
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
4 changed files with 17 additions and 2 deletions

View File

@ -83,12 +83,12 @@ def parse_arguments():
def subcommand_run(_):
"""Run unattended-upgrades"""
try:
subprocess.Popen(['unattended-upgrades', '-v'],
subprocess.Popen(['systemctl', 'start', 'freedombox-manual-upgrade'],
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, close_fds=True,
start_new_session=True)
except FileNotFoundError:
print('Error: unattended-upgrades is not available.', file=sys.stderr)
print('Error: systemctl is not available.', file=sys.stderr)
sys.exit(2)
except Exception as error:
print('Error: {0}'.format(error), file=sys.stderr)

4
debian/rules vendored
View File

@ -14,3 +14,7 @@ override_dh_auto_install-indep:
override_dh_auto_test:
PYBUILD_SYSTEM=custom \
PYBUILD_TEST_ARGS="{interpreter} setup.py test" dh_auto_test
override_dh_installsystemd:
# Do not enable or start freedombox-manual-upgrade.service.
dh_installsystemd --exclude=freedombox-manual-upgrade.service

View File

@ -1,2 +1,5 @@
# Automatically restart services when needed.
$nrconf{restart} = 'a';
# Don't restart freedombox-manual-upgrade.service.
$nrconf{override_rc}->{qr(^freedombox-manual-upgrade\.service$)} = 0;

View File

@ -0,0 +1,8 @@
[Unit]
Description=Run unattended-upgrade once
[Service]
Type=oneshot
ExecStart=unattended-upgrade --verbose
KillMode=process
TimeoutStopSec=900