diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..6285def --- /dev/null +++ b/debian/changelog @@ -0,0 +1,10 @@ +naas (1.0.0-1) unstable; urgency=medium + + * Initial release of NaaS (No as a Service) + * HTTP service that always responds with "no" + * Multiple response formats: text, JSON, XML, YAML, boolean + * Minimalist web frontend and interactive playground + * Health check endpoint + * Systemd service integration + + -- Ole-Morten Duesund Fri, 27 Sep 2024 15:00:00 +0200 \ No newline at end of file diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..597924d --- /dev/null +++ b/debian/control @@ -0,0 +1,26 @@ +Source: naas +Section: net +Priority: optional +Maintainer: Ole-Morten Duesund +Build-Depends: debhelper-compat (= 13), cargo | rustup, rustc | rustup +Standards-Version: 4.6.0 +Homepage: https://kode.naiv.no/naas +Vcs-Git: https://kode.naiv.no/naas.git +Vcs-Browser: https://kode.naiv.no/naas + +Package: naas +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, systemd +Description: No as a Service - HTTP service that always says "no" + NaaS (No as a Service) is a lightweight HTTP service written in pure Rust + that always responds with "no" in various formats including plain text, + JSON, XML, YAML, and boolean. + . + Features include: + - Minimal dependencies (pure Rust, standard library only) + - Multiple response formats + - Mobile-responsive web frontend + - CORS support + - Health check endpoint + - Optimized for small binary size (~1MB) + - Container-ready with health checks \ No newline at end of file diff --git a/debian/naas.default b/debian/naas.default new file mode 100644 index 0000000..17ae10e --- /dev/null +++ b/debian/naas.default @@ -0,0 +1,12 @@ +# Configuration for NaaS (No as a Service) +# This file is sourced by the systemd service + +# Port to listen on (default: 8080) +PORT=8080 + +# Bind address (default: 127.0.0.1 for localhost only) +# Use 0.0.0.0 to listen on all interfaces +BIND_ADDR=127.0.0.1 + +# Additional options can be added here as needed +# RUST_LOG=info \ No newline at end of file diff --git a/debian/naas.install b/debian/naas.install new file mode 100644 index 0000000..cbe2069 --- /dev/null +++ b/debian/naas.install @@ -0,0 +1 @@ +target/release/naas usr/bin/ \ No newline at end of file diff --git a/debian/naas.service b/debian/naas.service new file mode 100644 index 0000000..6067a02 --- /dev/null +++ b/debian/naas.service @@ -0,0 +1,34 @@ +[Unit] +Description=No as a Service (NaaS) +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +Restart=always +RestartSec=10 +TimeoutStopSec=30 + +# User configuration +User=naas +Group=naas + +# Load configuration from /etc/default/naas +EnvironmentFile=-/etc/default/naas + +# Binary execution +ExecStart=/usr/bin/naas + +# Security settings +NoNewPrivileges=true +PrivateTmp=true +ProtectSystem=strict +ProtectHome=true +ReadWritePaths= + +# Resource limits +MemoryLimit=256M +CPUQuota=50% + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/debian/postinst b/debian/postinst new file mode 100755 index 0000000..d9e37fe --- /dev/null +++ b/debian/postinst @@ -0,0 +1,31 @@ +#!/bin/bash + +set -e + +case "$1" in + configure) + # Create naas user if it doesn't exist + if ! getent passwd naas >/dev/null; then + adduser --system --group --no-create-home \ + --disabled-password --disabled-login \ + --shell /bin/false naas + fi + + # Reload systemd daemon to pick up new service file + if [ -d /run/systemd/system ]; then + systemctl daemon-reload || true + fi + + # On upgrade, restart the service if it's already enabled + if [ -n "$2" ] && [ -d /run/systemd/system ]; then + if systemctl is-enabled naas >/dev/null 2>&1; then + echo "Restarting naas service..." + systemctl restart naas || true + fi + fi + ;; +esac + +#DEBHELPER# + +exit 0 \ No newline at end of file diff --git a/debian/postrm b/debian/postrm new file mode 100755 index 0000000..7752fc2 --- /dev/null +++ b/debian/postrm @@ -0,0 +1,27 @@ +#!/bin/bash + +set -e + +case "$1" in + purge) + # Remove naas user on purge (only if package is completely removed) + if getent passwd naas >/dev/null; then + deluser --system naas 2>/dev/null || true + fi + + # Reload systemd daemon + if [ -d /run/systemd/system ]; then + systemctl daemon-reload || true + fi + ;; + remove) + # Reload systemd daemon to remove service + if [ -d /run/systemd/system ]; then + systemctl daemon-reload || true + fi + ;; +esac + +#DEBHELPER# + +exit 0 \ No newline at end of file diff --git a/debian/prerm b/debian/prerm new file mode 100755 index 0000000..1bd387a --- /dev/null +++ b/debian/prerm @@ -0,0 +1,18 @@ +#!/bin/bash + +set -e + +case "$1" in + remove|deconfigure) + # Stop the service if it's running + if [ -d /run/systemd/system ]; then + if systemctl is-active naas >/dev/null 2>&1; then + systemctl stop naas || true + fi + fi + ;; +esac + +#DEBHELPER# + +exit 0 \ No newline at end of file diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..a4def83 --- /dev/null +++ b/debian/rules @@ -0,0 +1,20 @@ +#!/usr/bin/make -f + +%: + dh $@ + +override_dh_auto_build: + cargo build --release + +override_dh_auto_test: + cargo test + +override_dh_auto_clean: + cargo clean || true + +override_dh_auto_install: + dh_auto_install + # Install config file + install -D -m 644 debian/naas.default debian/naas/etc/default/naas + # Install systemd service + install -D -m 644 debian/naas.service debian/naas/lib/systemd/system/naas.service \ No newline at end of file diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..9f67427 --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (native) \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 7523540..c4d647c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -330,7 +330,8 @@ const PLAYGROUND_FRONTEND: &str = r#" fn main() { let port = std::env::var("PORT").unwrap_or_else(|_| "8080".to_string()); - let addr = format!("0.0.0.0:{}", port); + let bind_addr = std::env::var("BIND_ADDR").unwrap_or_else(|_| "0.0.0.0".to_string()); + let addr = format!("{}:{}", bind_addr, port); let listener = TcpListener::bind(&addr).expect("Failed to bind to address"); println!("No as a Service running on http://{}", addr);