Something went wrong. Try again.
forked from libreqoe/libreqos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178#!/bin/bash
# This script builds the Rust sub-system and places the results in the# `src/bin` directory.## You still need to setup services to run `lqosd` and possibly `lqos_scheduler` automatically.## Don't forget to setup `/etc/lqos.conf`
# Check Pre-Requisitessudo apt install python3-pip clang gcc gcc-multilib llvm libelf-dev git nano graphviz curl screen llvm pkg-config linux-tools-common linux-tools-`uname -r` libbpf-dev libssl-dev curl
if ! rustup -V &> /dev/nullthen echo "rustup is not installed." echo "Visit https://rustup.rs and install Rust from there" echo "Usually, you can copy the following and follow the on-screen instructions." echo "Please don't install Rust as root." echo "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh" exit 1else echo "rustup found."fi
# To enable heavy debug mode (slow)#BUILD_FLAGS=""#TARGET=debug# OtherwiseBUILD_FLAGS=--releaseTARGET=release
# Enable this if you are building on the same computer you are running onRUSTFLAGS="-C target-cpu=native"
# Check for Rust versionecho "Checking that Rust is uptodate"rustup update
# Start buildingecho "Please wait while the system is compiled. Service will not be interrupted during this stage."PROGS="lqosd lqtop xdp_iphash_to_cpu_cmdline xdp_pping lqusers lqos_setup lqos_map_perf uisp_integration lqos_overrides lqos_topology"mkdir -p bin/staticpushd rust > /dev/null || exit#cargo cleanfor prog in $PROGSdo # If prog is lqosd if [ $prog == "lqosd" ]; then # If the environment variable FLAMEGRAPHS is set, set the FEATURE variable to flamegraph, otherwise it's empty if [ -n "$FLAMEGRAPHS" ]; then echo "Building lqosd with flamegraph support" FEATURE="-F flamegraphs" else echo "Building lqosd without flamegraph support" FEATURE="" fi echo "Building lqosd" pushd lqosd > /dev/null || exit cargo build $BUILD_FLAGS $FEATURE if [ $? -ne 0 ]; then echo "Cargo build failed. Exiting with code 1." exit 1 fi popd > /dev/null || exit else pushd $prog > /dev/null || exit cargo build $BUILD_FLAGS if [ $? -ne 0 ]; then echo "Cargo build failed. Exiting with code 1." exit 1 fi popd || exit fidonepopd > /dev/null || exit
echo "Installing new binaries into bin folder."pushd rust > /dev/null || exitfor prog in $PROGSdo echo "Installing $prog in bin folder" cp target/$TARGET/$prog ../bin/$prog.new || exit # Use a move to avoid file locking mv ../bin/$prog.new ../bin/$prog || exitdonepopd > /dev/null || exit
# Copy the node manager's static web contentmkdir -p bin/static2/vendorpushd rust/lqosd > /dev/null || exit./copy_files.shpopd > /dev/null || exit
# Copy the Python library for LibreQoS.py et al.pushd rust/lqos_python > /dev/null || exitcargo build $BUILD_FLAGSpopd > /dev/null || exitcp rust/target/$TARGET/liblqos_python.so ./liblqos_python.so.newmv liblqos_python.so.new liblqos_python.so
# Update the lqos_api binaryecho "Updating lqos_api binary..."bash ./update_api.sh || echo "Warning: Failed to update lqos_api (continuing)."
# If we're running systemd, we need to restart processesservice_exists() { local n=$1 if [[ $(systemctl list-units --all -t service --full --no-legend "$n.service" | sed 's/^\s*//g' | cut -f1 -d' ') == $n.service ]]; then return 0 else return 1 fi}
refresh_service_unit() { local unit_name=$1 local src="./bin/${unit_name}.service.example" local dst="/etc/systemd/system/${unit_name}.service" if [ -f "$src" ] && [ -f "$dst" ]; then echo "Refreshing $dst from $src" sudo cp "$src" "$dst" SERVICE_UNITS_UPDATED=1 fi}
clear_pinned_maps_before_lqosd_restart() { local script_path="./rust/remove_pinned_maps.sh" if [ ! -x "$script_path" ]; then echo "Expected $script_path to exist and be executable before restarting lqosd." exit 1 fi
echo "Removing pinned BPF maps before restarting lqosd." if ! sudo "$script_path"; then echo "Failed to remove pinned maps. Skipping service restarts to avoid restarting lqosd with stale map state." exit 1 fi}
SERVICE_UNITS_UPDATED=0refresh_service_unit lqosdrefresh_service_unit lqos_schedulerrefresh_service_unit lqos_api
if [ "$SERVICE_UNITS_UPDATED" -eq 1 ]; then echo "Reloading systemd unit definitions." sudo systemctl daemon-reloadfi
if service_exists lqos_node_manager; then echo "lqos_node_manager is running as a service. It's not needed anymore. Killing it." sudo systemctl stop lqos_node_manager sudo systemctl disable lqos_node_managerfiif service_exists lqosd; then clear_pinned_maps_before_lqosd_restart echo "lqosd is running as a service. Restarting it. You may need to enter your sudo password." sudo systemctl restart lqosdfiif service_exists lqos_scheduler; then echo "lqos_scheduler is running as a service. Restarting it. You may need to enter your sudo password." sudo systemctl restart lqos_schedulerfiif service_exists lqos_api; then echo "lqos_api is running as a service. Restarting it. You may need to enter your sudo password." sudo systemctl restart lqos_apifi
echo "-----------------------------------------------------------------"echo "Don't forget to setup /etc/lqos.conf!"echo "Template .service files can be found in bin/"echo "If src/deb-requirements-constraints.txt exists, Debian package installs use it to constrain Python dependencies."echo "Use ./systemd_hotfix.sh to evaluate or install the Ubuntu 24.04 networkd hotfix from the LibreQoS APT repo at https://repo.libreqos.com."echo "The hotfix installer now offers to schedule a reboot after it finishes."echo "LibreQoS package installs on affected Ubuntu 24.04 hosts stop until the hotfix is installed; finish with sudo dpkg --configure -a after the reboot."