Skip to content

Commit

Permalink
T6983: treat vyos-domain-resolver as a real service (#4261)
Browse files Browse the repository at this point in the history
* op-mode: T6983: add "show log" and "monitor log" commands for vyos-domain-resolver

* firewall: T6983: drop unused variable domain_resolver_usage_nat

* T6983: introduce Python logging module in vyos-domain-resolver

* T6983: treat vyos-domain-resolver as a real service
  • Loading branch information
c-po authored Dec 30, 2024
1 parent e9b1e26 commit b58576d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
6 changes: 6 additions & 0 deletions op-mode-definitions/monitor-log.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@
</properties>
<command>journalctl --no-hostname --boot --follow --unit vyos-configd.service</command>
</leafNode>
<leafNode name="vyos-domain-resolver">
<properties>
<help>Monitor last lines of VyOS domain resolver daemon log</help>
</properties>
<command>journalctl --no-hostname --boot --follow --unit vyos-domain-resolver.service</command>
</leafNode>
<node name="wireless">
<properties>
<help>Monitor last lines of Wireless interface log</help>
Expand Down
6 changes: 6 additions & 0 deletions op-mode-definitions/show-log.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,12 @@
</properties>
<command>journalctl --no-hostname --boot --unit vyos-configd.service</command>
</leafNode>
<leafNode name="vyos-domain-resolver">
<properties>
<help>Show log for VyOS domain resolver daemon</help>
</properties>
<command>journalctl --no-hostname --boot --unit vyos-domain-resolver.service</command>
</leafNode>
<node name="wireless">
<properties>
<help>Show log for Wireless interface</help>
Expand Down
1 change: 0 additions & 1 deletion src/conf_mode/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

nftables_conf = '/run/nftables.conf'
domain_resolver_usage = '/run/use-vyos-domain-resolver-firewall'
domain_resolver_usage_nat = '/run/use-vyos-domain-resolver-nat'

sysctl_file = r'/run/sysctl/10-vyos-firewall.conf'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import json
import time
import logging

from vyos.configdict import dict_merge
from vyos.configquery import ConfigTreeQuery
Expand Down Expand Up @@ -48,6 +49,11 @@
'ip6 raw'
}

logger = logging.getLogger(__name__)
logs_handler = logging.StreamHandler()
logger.addHandler(logs_handler)
logger.setLevel(logging.INFO)

def get_config(conf, node):
node_config = conf.get_config_dict(node, key_mangling=('-', '_'), get_first_key=True,
no_tag_node_value_mangle=True)
Expand Down Expand Up @@ -163,23 +169,23 @@ def update_fqdn(config, node):
nft_conf_str = "\n".join(conf_lines) + "\n"
code = run(f'nft --file -', input=nft_conf_str)

print(f'Updated {count} sets in {node} - result: {code}')
logger.info(f'Updated {count} sets in {node} - result: {code}')

if __name__ == '__main__':
print(f'VyOS domain resolver')
logger.info(f'VyOS domain resolver')

count = 1
while commit_in_progress():
if ( count % 60 == 0 ):
print(f'Commit still in progress after {count}s - waiting')
logger.info(f'Commit still in progress after {count}s - waiting')
count += 1
time.sleep(1)

conf = ConfigTreeQuery()
firewall = get_config(conf, base_firewall)
nat = get_config(conf, base_nat)

print(f'interval: {timeout}s - cache: {cache}')
logger.info(f'interval: {timeout}s - cache: {cache}')

while True:
update_fqdn(firewall, 'firewall')
Expand Down
4 changes: 3 additions & 1 deletion src/systemd/vyos-domain-resolver.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ ConditionPathExistsGlob=/run/use-vyos-domain-resolver*
[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/python3 -u /usr/libexec/vyos/vyos-domain-resolver.py
ExecStart=/usr/bin/python3 -u /usr/libexec/vyos/services/vyos-domain-resolver
SyslogIdentifier=vyos-domain-resolver
SyslogFacility=daemon
StandardError=journal
StandardOutput=journal

Expand Down

0 comments on commit b58576d

Please sign in to comment.