This commit is contained in:
Mateusz Gruszczyński
2025-10-24 08:15:47 +02:00
parent cceabd6873
commit 3222eaa930

View File

@@ -344,7 +344,7 @@ WantedBy=multi-user.target
""" """
# ========== Angie ========== # ========== Angie ==========
def setup_angie(): def setup_angie(ipv6_enabled: bool):
with step("Adding Angie repo and installing Angie packages"): with step("Adding Angie repo and installing Angie packages"):
# Ubuntu/Debian: common base # Ubuntu/Debian: common base
apt_try_install(["ca-certificates", "curl", "gnupg", "apt-transport-https", "software-properties-common"]) apt_try_install(["ca-certificates", "curl", "gnupg", "apt-transport-https", "software-properties-common"])
@@ -374,25 +374,17 @@ exec sudo -n /usr/sbin/angie "$@"
Path("/etc/nginx/conf.d/include").mkdir(parents=True, exist_ok=True) Path("/etc/nginx/conf.d/include").mkdir(parents=True, exist_ok=True)
with step("Setting resolver (IPv4 only) and cache directories"): with step("Setting resolver(s) and cache directories"):
nameservers = [] write_resolvers_conf(ipv6_enabled)
for line in Path("/etc/resolv.conf").read_text().splitlines(): for p in ["/var/lib/angie/cache/public", "/var/lib/angie/cache/private"]:
if line.strip().startswith("nameserver"): Path(p).mkdir(parents=True, exist_ok=True)
ns = line.split()[1].split("%")[0] os.chmod(p, 0o755)
if ":" in ns:
continue
nameservers.append(ns)
write_file(Path("/etc/nginx/conf.d/include/resolvers.conf"),
f"resolver {' '.join(nameservers)} valid=10s;\n", 0o644)
for p in ["/var/lib/angie/cache/public", "/var/lib/angie/cache/private"]:
Path(p).mkdir(parents=True, exist_ok=True)
os.chmod(p, 0o755)
with step("Installing corrected systemd unit for Angie"): with step("Installing corrected systemd unit for Angie"):
write_file(Path("/etc/systemd/system/angie.service"), ANGIE_UNIT, 0o644) write_file(Path("/etc/systemd/system/angie.service"), ANGIE_UNIT, 0o644)
def write_metrics_files(): def write_metrics_files():
"""Create /etc/angie/prometheus_all.conf and /etc/angie/metrics.conf (port 82 with console & status).""" """Create /etc/angie/metrics.conf (port 82 with console & status)."""
with step("Adding Angie metrics & console on :82"): with step("Adding Angie metrics & console on :82"):
metrics = """include /etc/angie/prometheus_all.conf; metrics = """include /etc/angie/prometheus_all.conf;
server { server {
@@ -519,10 +511,8 @@ def adjust_nginx_like_paths_in_tree(root: Path):
def install_node_and_yarn(node_pkg: str): def install_node_and_yarn(node_pkg: str):
# Node # Node
apt_install([node_pkg]) apt_install([node_pkg])
# Yarn (Ubuntu/Debian variance)
if shutil.which("yarn") or shutil.which("yarnpkg"): if shutil.which("yarn") or shutil.which("yarnpkg"):
return return
# try install 'yarn' then 'yarnpkg'
apt_try_install(["yarn"]) apt_try_install(["yarn"])
if not shutil.which("yarn") and not shutil.which("yarnpkg"): if not shutil.which("yarn") and not shutil.which("yarnpkg"):
apt_try_install(["yarnpkg"]) apt_try_install(["yarnpkg"])
@@ -740,11 +730,31 @@ def create_systemd_units(ipv6_enabled: bool):
def gather_versions(npm_app_version: str): def gather_versions(npm_app_version: str):
ip = run_out(["bash","-lc","hostname -I | awk '{print $1}'"]).strip() ip = run_out(["bash","-lc","hostname -I | awk '{print $1}'"]).strip()
angie_v = run_out(["bash","-lc","angie -v 2>&1 | awk 'NR==1{print $2}'"], check=False).strip() angie_v = run_out(["bash","-lc","angie -v 2>&1 | awk 'NR==1{print $3}'"], check=False).strip()
node_v = run_out(["bash","-lc","node -v | sed 's/^v//'"], check=False).strip() node_v = run_out(["bash","-lc","node -v | sed 's/^v//'"], check=False).strip()
yarn_v = run_out(["bash","-lc","yarn -v || yarnpkg -v"], check=False).strip() yarn_v = run_out(["bash","-lc","yarn -v || yarnpkg -v"], check=False).strip()
return ip, angie_v, node_v, yarn_v, npm_app_version return ip, angie_v, node_v, yarn_v, npm_app_version
def write_resolvers_conf(ipv6_enabled: bool):
ns_v4, ns_v6 = [], []
try:
for line in Path("/etc/resolv.conf").read_text().splitlines():
line = line.strip()
if not line.startswith("nameserver"):
continue
ip = line.split()[1].split("%")[0]
(ns_v6 if ":" in ip else ns_v4).append(ip)
except Exception:
pass
ips = ns_v4 + (ns_v6 if ipv6_enabled else [])
if not ips:
ips = ["1.1.1.1", "8.8.8.8"] + (["2606:4700:4700::1111", "2001:4860:4860::8888"] if ipv6_enabled else [])
ipv6_flag = " ipv6=on" if ipv6_enabled and any(":" in x for x in ips) else ""
content = f"resolver {' '.join(ips)} valid=10s{ipv6_flag};\n"
write_file(Path("/etc/angie/conf.d/include/resolvers.conf"), content, 0o644)
def update_motd(enabled: bool, info, ipv6_enabled: bool): def update_motd(enabled: bool, info, ipv6_enabled: bool):
if not enabled: if not enabled:
return return
@@ -756,7 +766,7 @@ def update_motd(enabled: bool, info, ipv6_enabled: bool):
OS: {OSREL['PRETTY']} ({OSREL['ID']} {OSREL['VERSION_ID']}) OS: {OSREL['PRETTY']} ({OSREL['ID']} {OSREL['VERSION_ID']})
Nginx Proxy Manager: http://{ip}:81 Nginx Proxy Manager: http://{ip}:81
Angie stats & Prometheus: http://{ip}:82/console | http://{ip}:82/p8s Angie stats & Prometheus: http://{ip}:82/console | http://{ip}:82/p8s
Angie: v{angie_v} (conf: /etc/angie -> /etc/nginx, reload: angie -s reload) Angie: {angie_v} (conf: /etc/angie -> /etc/nginx, reload: angie -s reload)
Node.js: v{node_v} Yarn: v{yarn_v} Node.js: v{node_v} Yarn: v{yarn_v}
NPM app: v{npm_v} NPM app: v{npm_v}
Paths: app=/opt/npm data=/data cache=/var/lib/angie/cache Paths: app=/opt/npm data=/data cache=/var/lib/angie/cache
@@ -966,7 +976,7 @@ def main():
apt_install(["ca-certificates","curl","gnupg","openssl","apache2-utils","logrotate","sudo","acl", apt_install(["ca-certificates","curl","gnupg","openssl","apache2-utils","logrotate","sudo","acl",
"python3","python3-venv","sqlite3","build-essential"]) "python3","python3-venv","sqlite3","build-essential"])
setup_angie() setup_angie(ipv6_enabled=args.enable_ipv6)
write_metrics_files() write_metrics_files()
install_certbot_with_dns_plugins() install_certbot_with_dns_plugins()
install_node_and_yarn(args.nodejs_pkg) install_node_and_yarn(args.nodejs_pkg)