Skip to content

Commit

Permalink
defaults: T6989: provide single source of systemd services
Browse files Browse the repository at this point in the history
Some systemd services are re-used over multiple configuration files. Keep a
single source of the real systemd names and only reference them by dictionary
keys.
  • Loading branch information
c-po committed Feb 2, 2025
1 parent 7ae3d37 commit 9212b40
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
7 changes: 6 additions & 1 deletion python/vyos/defaults.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018-2024 VyOS maintainers and contributors <[email protected]>
# Copyright 2018-2025 VyOS maintainers and contributors <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -40,6 +40,11 @@
'ca_certificates' : '/usr/local/share/ca-certificates/vyos'
}

systemd_services = {
'rsyslog' : 'rsyslog.service',
'snmpd' : 'snmpd.service',
}

config_status = '/tmp/vyos-config-status'
api_config_state = '/run/http-api-state'
frr_debug_enable = '/tmp/vyos.frr.debug'
Expand Down
3 changes: 2 additions & 1 deletion src/conf_mode/service_snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from vyos.config import Config
from vyos.configdict import dict_merge
from vyos.configverify import verify_vrf
from vyos.defaults import systemd_services
from vyos.snmpv3_hashgen import plaintext_to_md5
from vyos.snmpv3_hashgen import plaintext_to_sha1
from vyos.snmpv3_hashgen import random
Expand All @@ -43,7 +44,7 @@
config_file_user = r'/var/lib/snmp/snmpd.conf'
default_script_dir = r'/config/user-data/'
systemd_override = r'/run/systemd/system/snmpd.service.d/override.conf'
systemd_service = 'snmpd.service'
systemd_service = systemd_services['snmpd']

def get_config(config=None):
if config:
Expand Down
9 changes: 6 additions & 3 deletions src/conf_mode/system_host-name.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
# Copyright (C) 2018-2024 VyOS maintainers and contributors
# Copyright (C) 2018-2025 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
Expand All @@ -23,6 +23,7 @@
from vyos.base import Warning
from vyos.config import Config
from vyos.configdict import leaf_node_changed
from vyos.defaults import systemd_services
from vyos.ifconfig import Section
from vyos.template import is_ip
from vyos.utils.process import cmd
Expand Down Expand Up @@ -174,11 +175,13 @@ def apply(config):

# Restart services that use the hostname
if hostname_new != hostname_old:
call("systemctl restart rsyslog.service")
tmp = systemd_services['rsyslog']
call(f'systemctl restart {tmp}')

# If SNMP is running, restart it too
if process_named_running('snmpd') and config['snmpd_restart_reqired']:
call('systemctl restart snmpd.service')
tmp = systemd_services['snmpd']
call(f'systemctl restart {tmp}')

return None

Expand Down
6 changes: 4 additions & 2 deletions src/conf_mode/system_syslog.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from vyos.config import Config
from vyos.configdict import is_node_changed
from vyos.configverify import verify_vrf
from vyos.defaults import systemd_services
from vyos.utils.network import is_addr_assigned
from vyos.utils.process import call
from vyos.template import render
Expand All @@ -34,6 +35,9 @@
rsyslog_conf = '/run/rsyslog/rsyslog.conf'
logrotate_conf = '/etc/logrotate.d/vyos-rsyslog'

systemd_socket = 'syslog.socket'
systemd_service = systemd_services['rsyslog']

def get_config(config=None):
if config:
conf = config
Expand Down Expand Up @@ -111,8 +115,6 @@ def generate(syslog):
return None

def apply(syslog):
systemd_socket = 'syslog.socket'
systemd_service = 'syslog.service'
if not syslog:
call(f'systemctl stop {systemd_service} {systemd_socket}')
return None
Expand Down

0 comments on commit 9212b40

Please sign in to comment.