diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fa0ee5529..e54e7fc1b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,7 +16,7 @@ code-quality: stage: test needs: [] script: - - python3 -m flake8 --exclude actions/domainname-change,actions/hostname-change,actions/networks container plinth actions/* + - python3 -m flake8 --exclude actions/domainname-change,actions/networks container plinth actions/* unit-tests: stage: test diff --git a/actions/hostname-change b/actions/hostname-change deleted file mode 100755 index c5bdee448..000000000 --- a/actions/hostname-change +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: AGPL-3.0-or-later - -hostname="$1" - -hostnamectl set-hostname --transient --static "$hostname" - -service avahi-daemon restart diff --git a/plinth/modules/config/privileged.py b/plinth/modules/config/privileged.py index e2bf76869..077a4a674 100644 --- a/plinth/modules/config/privileged.py +++ b/plinth/modules/config/privileged.py @@ -3,6 +3,7 @@ import os import pathlib +import subprocess import augeas @@ -19,6 +20,15 @@ FREEDOMBOX_APACHE_CONFIG = os.path.join(APACHE_CONF_ENABLED_DIR, JOURNALD_FILE = pathlib.Path('/etc/systemd/journald.conf.d/50-freedombox.conf') +@privileged +def set_hostname(hostname: str): + """Set system hostname using hostnamectl.""" + subprocess.run( + ['hostnamectl', 'set-hostname', '--transient', '--static', hostname], + check=True) + action_utils.service_restart('avahi-daemon') + + def load_augeas(): """Initialize Augeas.""" aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD + diff --git a/plinth/modules/config/views.py b/plinth/modules/config/views.py index 1e5599022..97d8dc6d0 100644 --- a/plinth/modules/config/views.py +++ b/plinth/modules/config/views.py @@ -102,7 +102,7 @@ class ConfigAppView(views.AppView): def set_hostname(hostname): - """Sets machine hostname to hostname""" + """Set machine hostname and send signals before and after.""" old_hostname = config.get_hostname() domainname = config.get_domainname() @@ -114,7 +114,7 @@ def set_hostname(hostname): new_hostname=hostname) LOGGER.info('Changing hostname to - %s', hostname) - actions.superuser_run('hostname-change', [hostname]) + privileged.set_hostname(hostname) LOGGER.info('Setting domain name after hostname change - %s', domainname) actions.superuser_run('domainname-change', [domainname])