Compare commits

...
Author SHA1 Message Date
kraemr 5e1b74a583 removed extraneous configuration 2026-01-21 18:41:09 +01:00
kraemr ee93bb150d fixed formatting 2026-01-21 18:33:30 +01:00
kraemr 208fe5734f fixed linter error 2026-01-21 18:30:18 +01:00
kraemr 2abb6b2ce0 fixed formatting 2026-01-21 18:26:40 +01:00
kraemr 6f986d3c45 fixed potential error where a failed setup_loop kills dns 2026-01-21 18:25:04 +01:00
5 changed files with 63 additions and 2 deletions

No files matched your search

+10
View File
@@ -126,6 +126,16 @@ in {
value = "-20";
}
];
# needed so dnsmasq can get managed by server
security.polkit.extraConfig = ''
polkit.addRule(function(action, subject) {
if (action.id == "org.freedesktop.systemd1.manage-units" &&
action.lookup("unit") == "dnsmasq.service" &&
subject.user == "${cfg.user}") {
return polkit.Result.YES;
}
});
'';
# Desktop integration
xdg.mime.enable = true;
+2
View File
@@ -322,10 +322,12 @@ in {
services.dnsmasq = {
enable = true;
resolveLocalQueries = false;
settings = {
interface = "enp1s0"; # only this interface
bind-interfaces = true;
server = [ "1.1.1.1" "8.8.8.8" ];
# DHCP subnet + pool
dhcp-range = "10.10.10.50,10.10.10.250,255.255.255.0,12h";
+15
View File
@@ -19,6 +19,7 @@ use ethercat_hal::devices::wago_modules::ip20_ec_di8_do8::{
IP20_EC_DI8_DO8_PRODUCT_ID, IP20_EC_DI8_DO8_VENDOR_ID, IP20EcDi8Do8,
};
use crate::utils::{start_dnsmasq, stop_dnsmasq};
use ethercrab::std::ethercat_now;
use ethercrab::{MainDevice, MainDeviceConfig, PduStorage, RetryBehaviour, Timeouts};
use machines::machine_identification::{
@@ -172,6 +173,14 @@ pub async fn setup_loop(
) -> Result<EthercatSetup, anyhow::Error> {
tracing::info!("Starting Ethercat PDU loop");
let res = stop_dnsmasq();
match res {
Ok(_) => (),
Err(e) => tracing::error!("Failed to stop dnsmasq: {:?}", e),
};
// Small Timeout to ensure interfaces get released
smol::Timer::after(Duration::from_millis(1500)).await;
// Setup ethercrab tx/rx task
let pdu_storage = Box::leak(Box::new(PduStorage::<MAX_FRAMES, MAX_PDU_DATA>::new()));
let (tx, rx, pdu) = pdu_storage.try_split().expect("can only split once");
@@ -481,6 +490,12 @@ pub async fn setup_loop(
main_namespace.emit(MainNamespaceEvents::EthercatDevicesEvent(event));
}
let res = start_dnsmasq();
match res {
Ok(o) => o,
Err(e) => tracing::error!("Failed to start dnsmasq: {:?}", e),
};
Ok(EthercatSetup {
devices,
group: group_op,
+5 -2
View File
@@ -16,6 +16,7 @@ use machines::{
};
#[cfg(feature = "development-build")]
use std::sync::atomic::{AtomicBool, Ordering};
use utils::start_dnsmasq;
use app_state::{HotThreadMessage, SharedState};
use ethercat::ethercat_discovery_info::send_ethercat_discovering;
@@ -57,6 +58,7 @@ pub mod panic;
pub mod performance_metrics;
pub mod rest;
pub mod socketio;
pub mod utils;
pub async fn send_empty_machines_event(shared_state: Arc<SharedState>) {
shared_state.current_machines_meta.lock().await.clear();
@@ -137,7 +139,6 @@ pub async fn start_interface_discovery(
let interface = find_ethercat_interface().await;
tracing::info!("Inferface found {}, setting up EtherCAT loop", interface);
set_ethercat_iface(interface.clone());
let res = setup_loop(&interface, app_state.clone()).await;
match res {
@@ -152,9 +153,10 @@ pub async fn start_interface_discovery(
module_path!(),
e
);
// if this doesnt work, unlucky
let _ = start_dnsmasq();
}
}
send_ethercat_found(app_state.clone(), &interface).await;
}
@@ -338,6 +340,7 @@ fn main() {
let app_state = Arc::new(shared_state);
let _loop_thread = start_loop_thread(receiver, CYCLE_TARGET_TIME);
let _ = start_api_thread(app_state.clone());
spawn_runtime_metrics_sampler(RuntimeMetricsConfig {
csv_path: "runtime_metrics.csv".to_string(),
interval: Duration::from_secs(1),
+31
View File
@@ -0,0 +1,31 @@
use std::process::Command;
pub fn start_dnsmasq() -> std::io::Result<()> {
// action can be "start", "stop", or "restart"
let status = Command::new("systemctl")
.arg("start")
.arg("dnsmasq.service")
.status()?;
if status.success() {
tracing::info!("Successfully started dnsmasq");
} else {
tracing::info!("Failed to start dnsmasq");
}
Ok(())
}
pub fn stop_dnsmasq() -> std::io::Result<()> {
// action can be "start", "stop", or "restart"
let status = Command::new("systemctl")
.arg("stop")
.arg("dnsmasq.service")
.status()?;
if status.success() {
tracing::info!("Successfully stopped");
} else {
tracing::info!("Failed to stop dnsmasq");
}
Ok(())
}