mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
config: Use privileged decorator for set-hostname action
Tests: - Running flake8 as in .gitlab-ci.yml works. - Changes the hostname works and it is updated in /etc/hostname - Avahi daemon is restarted Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
06b5639986
commit
40bf6add75
@ -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
|
||||
|
||||
@ -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
|
||||
@ -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 +
|
||||
|
||||
@ -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])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user