2 Commits

Author SHA1 Message Date
Joe Clarke
74010cffff Formatting fixes.
Spotted by:	Miroslav Los
2025-07-09 09:49:11 -04:00
Joe Clarke
f86bfc37b5 Move the firewall rule to the service.
This makes things more seamless.

Suggested by:	Miroslav Los
2025-07-09 09:20:58 -04:00
4 changed files with 10 additions and 62 deletions

View File

@@ -6,7 +6,7 @@ OUT = cml-exporter-installer.sh
# List of macros and corresponding files
SHELL := /bin/bash
FILES = scripts/cml-exporter scripts/cml-exporter.py scripts/cml-exporter.service scripts/cml-exporter.sh
FILES = scripts/cml-exporter scripts/cml-exporter.py scripts/cml-exporter.service scripts/cml-exporter.sh
# Generate sed script to replace macros with file contents
SED_SCRIPT = $(OUT).sed
@@ -31,4 +31,4 @@ $(OUT): $(SRC) $(FILES) $(SED_SCRIPT)
clean:
rm -f $(SED_SCRIPT)
spotless: clean
rm -f $(OUT)
rm -f $(OUT)

View File

@@ -294,6 +294,7 @@ After=virl2.target
[Service]
EnvironmentFile=/etc/default/cml-exporter
ExecPreStart=/usr/bin/firewall-cmd --zone public --permanent --add-port="${EXPORTER_PORT}/tcp" && /usr/bin/firewall-cmd --reload
ExecStart=/usr/local/bin/cml-exporter.sh
User=virl2
Restart=on-failure
@@ -322,17 +323,6 @@ create_venv() {
fi
}
add_firewall_rule() {
local port="9100"
if ! firewall-cmd --list-ports | grep -q "${port}/tcp"; then
echo "Adding firewall rule for port $port"
firewall-cmd --zone public --permanent --add-port="${port}/tcp"
firewall-cmd --reload
else
echo "Firewall rule for port $port already exists"
fi
}
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root." >&2
exit 1
@@ -350,28 +340,12 @@ echo -e "\t✅"
echo -n "installing service unit"
install_service_unit
echo -e "\t✅"
echo -n "adding firewall rule"
add_firewall_rule
echo -e "\t✅"
cat <<EOF
**************************************************************
* ⚠️ IMPORTANT! ⚠️ *
* you need to ensure that you change the username *
* and password for a user of the system that can *
* start the labs in /etc/default/cml-exporter *
* *
* If using a port other than 9100, run the *
* following command to add a firewall rule: *
* *
* firewall-cmd --zone public --permanent --add-port=PORT/tcp *
* *
* Then run: *
* firewall-cmd --reload *
* *
* You can then start the service with: *
* *
* systemctl start cml-exporter.service. *
* *
* you need to edit /etc/default/cml-exporter and set the *
* CML_USERNAME and CML_PASSWORD variables for a user that. *
* has access to see all labs in CML. *
**************************************************************
EOF

View File

@@ -63,17 +63,6 @@ create_venv() {
fi
}
add_firewall_rule() {
local port="9100"
if ! firewall-cmd --list-ports | grep -q "${port}/tcp"; then
echo "Adding firewall rule for port $port"
firewall-cmd --zone public --permanent --add-port="${port}/tcp"
firewall-cmd --reload
else
echo "Firewall rule for port $port already exists"
fi
}
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root." >&2
exit 1
@@ -91,28 +80,12 @@ echo -e "\t✅"
echo -n "installing service unit"
install_service_unit
echo -e "\t✅"
echo -n "adding firewall rule"
add_firewall_rule
echo -e "\t✅"
cat <<EOF
**************************************************************
* ⚠️ IMPORTANT! ⚠️ *
* you need to ensure that you change the username *
* and password for a user of the system that can *
* start the labs in /etc/default/cml-exporter *
* *
* If using a port other than 9100, run the *
* following command to add a firewall rule: *
* *
* firewall-cmd --zone public --permanent --add-port=PORT/tcp *
* *
* Then run: *
* firewall-cmd --reload *
* *
* You can then start the service with: *
* *
* systemctl start cml-exporter.service. *
* *
* you need to edit /etc/default/cml-exporter and set the *
* CML_USERNAME and CML_PASSWORD variables for a user that. *
* has access to see all labs in CML. *
**************************************************************
EOF

View File

@@ -5,6 +5,7 @@ After=virl2.target
[Service]
EnvironmentFile=/etc/default/cml-exporter
ExecPreStart=/usr/bin/firewall-cmd --zone public --permanent --add-port="${EXPORTER_PORT}/tcp" && /usr/bin/firewall-cmd --reload
ExecStart=/usr/local/bin/cml-exporter.sh
User=virl2
Restart=on-failure