generated from NethServer/ns8-kickstart
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Put config file generation in "expand-config" helper command. Handle the special case when the configuration does not exist with an hardcoded default. - Invoke the helper in create-module and at every service startup. - Restart (and reconfigure) DNSMasq if a Samba instance appears on the local node.
- Loading branch information
1 parent
c6ec5e8
commit 4989a99
Showing
5 changed files
with
78 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2024 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
import json | ||
import sys | ||
import agent | ||
|
||
# Read configuration from a JSON file or initialize it. | ||
try: | ||
config = json.load(open("config.json")) | ||
except FileNotFoundError: | ||
print(agent.SD_NOTICE, "Generating a new config.json file...", file=sys.stderr) | ||
config = { | ||
"interface": "", | ||
"dhcp-server": { | ||
"enabled": False, | ||
"start": "", | ||
"end": "", | ||
"lease": 12 | ||
}, | ||
"dns-server": { | ||
"enabled": False, | ||
"primary-server": "", | ||
"secondary-server": "" | ||
}, | ||
} | ||
json.dump(config, fp=open("config.json", "w")) | ||
|
||
|
||
# convert json to configuration file | ||
with open("dnsmasq.d/00config.conf", "w") as file: | ||
file.write("# This file is automatically generated by NethServer, manual changes will be lost.\n") | ||
# write interface only if dhcp-server or dns-server are enabled | ||
if config["dhcp-server"]["enabled"] or config["dns-server"]["enabled"]: | ||
file.write("interface=" + config["interface"] + "\n") | ||
|
||
# write dhcp-server configuration | ||
if config["dhcp-server"]["enabled"]: | ||
file.write("dhcp-range=set:default," + config["dhcp-server"]["start"] + "," + config["dhcp-server"]["end"] + "," + str(config["dhcp-server"]["lease"]) + "h\n") | ||
|
||
# write dns-server configuration | ||
if config["dns-server"]["enabled"]: | ||
file.write("server=" + config["dns-server"]["primary-server"] + "\n") | ||
if config["dns-server"]["secondary-server"] != "": | ||
file.write("server=" + config["dns-server"]["secondary-server"] + "\n") | ||
else: | ||
# shut down dns server if not enabled | ||
file.write("port=0\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2024 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
import json | ||
import os | ||
import sys | ||
|
||
import agent | ||
|
||
data = json.load(sys.stdin) | ||
|
||
# skip if the event comes from another node | ||
if os.environ['NODE_ID'] != str(data['node']): | ||
sys.exit(0) | ||
|
||
agent.run_helper('systemctl', 'restart', os.getenv('MODULE_ID')) |