January 11, 20251 yr I would like to see a services web page with buttons and status... root@BMM-Unraid:~# cd /etc/rc.d root@BMM-Unraid:/etc/rc.d# ls rc.0@ rc.acpid* rc.cgroup2unraid* rc.inet1* rc.krb5kdc rc.modules* rc.rpc* rc.sshd* rc.wsdd2* rc.4* rc.apcupsd* rc.cpufreq* rc.inet1.conf rc.library.source rc.modules.local* rc.rsyslogd* rc.swapfile@ rc0.d@ rc.4.local* rc.atd* rc.crond* rc.inet2* rc.libvirt* rc.mysqld rc.runlog rc.sysstat rc6.d/ rc.6* rc.avahidaemon* rc.dnsmasq rc.inetd* rc.local* rc.nfsd* rc.samba* rc.sysvinit* rc.K* rc.avahidnsconfd* rc.docker* rc.ip_forward* rc.local_shutdown* rc.nginx* rc.saslauthd rc.tailscale@ rc.M* rc.bind rc.elogind* rc.kadmind rc.loop* rc.ntpd* rc.serial* rc.udev* rc.S* rc.cgconfig rc.flash_backup* rc.keymap* rc.mcelog* rc.openldap rc.setterm* rc.unraid-api* rc.S.cont* rc.cgred rc.font rc.kpropd rc.messagebus* rc.php-fpm* rc.smartd rc.wireguard* root@BMM-Unraid:/etc/rc.d# simlar in truenas scale where i can master enable or stop a service. this wepage can be justa status page or buton to stop start restart... exmaple code: Backend Script (/usr/local/emhttp/plugins/services_manager/scripts/manage_services.sh) #!/bin/bash SERVICES_DIR="/etc/rc.d" # Handle input arguments ACTION=$1 SERVICE=$2 # Function to get the service status get_status() { if pgrep -f "$SERVICES_DIR/$SERVICE" > /dev/null; then echo "running" else echo "stopped" fi } # Perform the requested action case $ACTION in status) get_status ;; start|stop|restart) if [ -x "$SERVICES_DIR/$SERVICE" ]; then "$SERVICES_DIR/$SERVICE" $ACTION echo "$(get_status)" else echo "invalid" fi ;; *) echo "Usage: $0 {status|start|stop|restart} <service_name>" ;; esac HTML Web Page (/usr/local/emhttp/plugins/services_manager/services.html) <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Unraid Services Manager</title> <style> body { font-family: Arial, sans-serif; margin: 20px; } table { width: 100%; border-collapse: collapse; } th, td { border: 1px solid #ddd; padding: 8px; text-align: left; } th { background-color: #f4f4f4; } .status-running { color: green; font-weight: bold; } .status-stopped { color: red; font-weight: bold; } button { padding: 5px 10px; margin: 2px; } </style> </head> <body> <h1>Unraid Services Manager</h1> <table> <thead> <tr> <th>Service</th> <th>Status</th> <th>Actions</th> </tr> </thead> <tbody id="services-table"></tbody> </table> <script> async function fetchServices() { const services = [ "rc.acpid", "rc.crond", "rc.docker", "rc.ntpd", "rc.samba" // Add more services as needed ]; const tableBody = document.getElementById("services-table"); tableBody.innerHTML = ""; for (const service of services) { const status = await fetch(`/plugins/services_manager/scripts/manage_services.sh?status&${service}`) .then(response => response.text()) .catch(() => "error"); const row = document.createElement("tr"); row.innerHTML = ` <td>${service}</td> <td class="${status === "running" ? "status-running" : "status-stopped"}">${status}</td> <td> <button onclick="performAction('${service}', 'start')">Start</button> <button onclick="performAction('${service}', 'stop')">Stop</button> <button onclick="performAction('${service}', 'restart')">Restart</button> </td> `; tableBody.appendChild(row); } } async function performAction(service, action) { await fetch(`/plugins/services_manager/scripts/manage_services.sh?${action}&${service}`); fetchServices(); // Refresh the status } // Initial fetch fetchServices(); </script> </body> </html> Notes The script is designed to dynamically check and operate on services listed in the /etc/rc.d/ directory. Update the services array in the JavaScript code with the list of services you want to manage. For better security, restrict access to these scripts using Unraid's built-in mechanisms. idelay i would want this to be the master contorl over a service stop start in the web ui so if its stoped here its stop and will not run unless called via termianl / this page...
January 11, 20251 yr Author Revised backend front end script to dynamical autodetect running services: Key Changes Backend Script: Added list functionality to dynamically list services in /etc/rc.d/. The script will only display services prefixed with rc.. HTML Frontend: Fetches the list of services dynamically from the backend using the list action. The status of each service is queried and displayed in real-time. (/usr/local/emhttp/plugins/services_manager/scripts/manage_services.sh) This script now includes a list action to fetch all the services in the /etc/rc.d/ directory. #!/bin/bash SERVICES_DIR="/etc/rc.d" # Handle input arguments ACTION=$1 SERVICE=$2 # Function to get the service status get_status() { if pgrep -f "$SERVICES_DIR/$SERVICE" > /dev/null; then echo "running" else echo "stopped" fi } # Function to list all available services list_services() { for file in "$SERVICES_DIR"/rc.*; do basename "$file" done } # Perform the requested action case $ACTION in list) list_services ;; status) get_status ;; start|stop|restart) if [ -x "$SERVICES_DIR/$SERVICE" ]; then "$SERVICES_DIR/$SERVICE" $ACTION echo "$(get_status)" else echo "invalid" fi ;; *) echo "Usage: $0 {list|status|start|stop|restart} <service_name>" ;; esac Updated HTML Web Page (/usr/local/emhttp/plugins/services_manager/services.html) The HTML now dynamically fetches the list of services from the backend. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Unraid System Services</title> <style> body { font-family: Arial, sans-serif; margin: 20px; } h1 { text-align: center; color: #333; } table { width: 100%; border-collapse: collapse; margin-top: 20px; } th, td { border: 1px solid #ddd; padding: 10px; text-align: center; } th { background-color: #f4f4f4; } .status-running { color: green; font-weight: bold; } .status-stopped { color: red; font-weight: bold; } .status-error { color: orange; font-weight: bold; } button { padding: 5px 10px; margin: 0 5px; } button:hover { background-color: #ddd; } </style> </head> <body> <h1>Unraid System Services</h1> <table> <thead> <tr> <th>Status</th> <th>Service Name</th> <th>Actions</th> </tr> </thead> <tbody id="services-table"></tbody> </table> <script> async function fetchServices() { const tableBody = document.getElementById("services-table"); tableBody.innerHTML = ""; // Fetch the list of services const services = await fetch(`/plugins/services_manager/scripts/manage_services.sh?list`) .then(response => response.text()) .then(data => data.trim().split("\n")) .catch(() => []); // Populate the table for (const service of services) { const status = await fetch(`/plugins/services_manager/scripts/manage_services.sh?status&${service}`) .then(response => response.text()) .catch(() => "error"); // Determine the status class let statusClass = "status-error"; if (status === "running") statusClass = "status-running"; if (status === "stopped") statusClass = "status-stopped"; const row = document.createElement("tr"); row.innerHTML = ` <td class="${statusClass}">${status}</td> <td>${service}</td> <td> <button onclick="performAction('${service}', 'start')">Start</button> <button onclick="performAction('${service}', 'stop')">Stop</button> <button onclick="performAction('${service}', 'restart')">Restart</button> </td> `; tableBody.appendChild(row); } } async function performAction(service, action) { await fetch(`/plugins/services_manager/scripts/manage_services.sh?${action}&${service}`); fetchServices(); // Refresh the status } // Initial fetch fetchServices(); </script> </body> </html>
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.