From 24d2d92ab59578d6bc846cd82129c1e3e95031f4 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 27 Oct 2025 21:34:58 -0700 Subject: [PATCH] Run service using systemd even for development - This means that systemd sandbox will be in effect even during development. We won't miss out on bugs in sandbox configuration. - We won't have disable systemd sandbox features just because we can test properly on development setup. Such as JoinsNamespaceOf=. - This also leads to significant reduction in hacky code for setting up for development and functional tests. - One disadvantage is that first setup is run before user gets a chance to interact with the started container/VM. However, this is okay since first setup can be re-run easily by removing the /var/lib/plinth/plinth.sqlite3 file and also the need for doing this is rare. Tests: - Start a fresh container and run functional tests with './container run-tests' on it. The tests run as expected (succeed or fail). - While first setup is in progress, running the command 'make wait-while-first-setup' waits while printing dots. After the first setup is done, it exists. - Running the command freedombox-logs shows FreedomBox logs for both the web and privileged services. - Changing a source code file in the /freedombox directory (or on the host) leads to a restart of the Plinth web service. Signed-off-by: Sunil Mohan Adapa Reviewed-by: Veiko Aasa --- .ci/Containerfile.functional-tests-stable | 2 +- .ci/functional-tests.yml | 3 +-- HACKING.md | 20 +++++++-------- Makefile | 31 +++++++++++++++++++++-- Vagrantfile | 10 +++----- container | 25 ++---------------- 6 files changed, 46 insertions(+), 45 deletions(-) diff --git a/.ci/Containerfile.functional-tests-stable b/.ci/Containerfile.functional-tests-stable index c773fd339..c63c49353 100644 --- a/.ci/Containerfile.functional-tests-stable +++ b/.ci/Containerfile.functional-tests-stable @@ -16,7 +16,7 @@ RUN apt-get dist-upgrade -y # Install freedombox package so that plint:plinth user/group are created etc. RUN apt-get install -y freedombox/trixie-backports -RUN systemctl mask plinth.service +RUN systemctl disable plinth.service # Don't ask for the secret in first wizard RUN rm -f /var/lib/plinth/firstboot-wizard-secret diff --git a/.ci/functional-tests.yml b/.ci/functional-tests.yml index a3188de4e..987601f48 100644 --- a/.ci/functional-tests.yml +++ b/.ci/functional-tests.yml @@ -16,8 +16,7 @@ - apt-get update - apt-get -y install make - make provision-dev - - sudo -u plinth ./run --develop > plinth.log 2>&1 & - - while ! grep -q "Setup finished" plinth.log; do sleep 1; echo -n .; done + - make wait-while-first-setup script: - FREDOMBOX_URL=https://localhost FREEDOMBOX_SSH_PORT=22 FREEDOMBOX_SAMBA_PORT=445 pytest -v --durations=10 --include-functional --splinter-headless --instafail --template=html1/index.html --report=functional-tests.html artifacts: diff --git a/HACKING.md b/HACKING.md index f89956582..981b06ce5 100644 --- a/HACKING.md +++ b/HACKING.md @@ -143,12 +143,12 @@ directory: guest$ cd /freedombox ``` -Run the development version of FreedomBox Service in the container using the -following command. This command continuously deploys your code changes into the -container providing a quick feedback cycle during development. +FreedomBox Service runs as plinth.service in the container. This service +restarts when it detects a change to the source code file. This provides a quick +feedback cycle during development. To watch service logs run: ```bash -guest$ freedombox-develop +guest$ sudo freedombox-logs ``` If you have changed any system configuration files during your development, @@ -156,7 +156,8 @@ you will need to run the following to install those files properly on to the system and their changes to reflect properly. ```bash -guest$ sudo make build install +guest$ sudo make build install ; +guest$ sudo systemctl restart plinth.service ``` Note: This development container has automatic upgrades disabled by default. @@ -373,13 +374,12 @@ After logging into the virtual machine (VM), the source code is available in vm$ cd /freedombox ``` -Run the development version of FreedomBox Service (Plinth) from your source -directory in the virtual machine using the following command. This command -continuously deploys your code changes into the virtual machine providing a -quick feedback cycle during development. +FreedomBox Service runs as plinth.service in the virtual machine. This service +restarts when it detects a change to the source code file. This provides a quick +feedback cycle during development. To watch service logs run: ```bash -vm$ freedombox-develop +vm$ sudo freedombox-logs ``` If you have changed any system configuration files during your development, diff --git a/Makefile b/Makefile index db908fbf1..7f2ac4a2d 100644 --- a/Makefile +++ b/Makefile @@ -161,6 +161,16 @@ Environment=PYTHONPATH=/freedombox/ endef export DEVELOP_SERVICE_CONF +define DEVELOP_LOGS_SCRIPT +#!/usr/bin/bash + +set -e +set -x + +journalctl --follow --unit=plinth.service --unit=freedombox-privileged.service +endef +export DEVELOP_LOGS_SCRIPT + # Run basic setup for a developer environment (VM or container) provision-dev: # Install newer build dependencies if any @@ -170,9 +180,15 @@ provision-dev: # Install latest code over .deb $(MAKE) build install - # Configure privileged daemon for development setup + # Configure privileged and web daemon for development setup mkdir -p /etc/systemd/system/freedombox-privileged.service.d/ echo "$$DEVELOP_SERVICE_CONF" > /etc/systemd/system/freedombox-privileged.service.d/develop.conf + mkdir -p /etc/systemd/system/plinth.service.d/ + echo "$$DEVELOP_SERVICE_CONF" > /etc/systemd/system/plinth.service.d/develop.conf + + # Create a command to easily watch service logs + echo "$$DEVELOP_LOGS_SCRIPT" > /usr/bin/freedombox-logs + chmod 755 /usr/bin/freedombox-logs # Reload newer systemd units, ignore failure -systemctl daemon-reload @@ -183,6 +199,10 @@ provision-dev: -test -d /run/systemd/system && \ systemctl enable --now freedombox-privileged.socket + # Enable and restart plinth service if it is running + -systemctl enable plinth.service + -systemctl restart plinth.service + # Stop any ongoing upgrade, ignore failure -killall -9 unattended-upgr @@ -207,6 +227,12 @@ provision-dev: DEBIAN_FRONTEND=noninteractive apt-get install --yes ncurses-term \ sshpass bash-completion +wait-while-first-setup: + while [ x$$(curl -k https://localhost/plinth/status/ 2> /dev/null | \ + json_pp 2> /dev/null | grep 'is_first_setup_running' | \ + tr -d '[:space:]' | cut -d':' -f2 ) != 'xfalse' ] ; do \ + sleep 1; echo -n .; done + .PHONY: \ build \ check \ @@ -219,4 +245,5 @@ provision-dev: configure \ install \ provision \ - update-translations + update-translations \ + wait-while-first-setup diff --git a/Vagrantfile b/Vagrantfile index 672172aa6..e7dedefbc 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -24,17 +24,13 @@ Vagrant.configure(2) do |config| config.vm.provision "shell", inline: <<-SHELL cd /freedombox/ make provision-dev - - echo 'alias freedombox-develop="cd /freedombox; sudo -u plinth /freedombox/run --develop"' >> /home/vagrant/.bashrc SHELL config.vm.provision "tests", run: "never", type: "shell", path: "plinth/tests/functional/install.sh" config.vm.post_up_message = "FreedomBox virtual machine is ready -for development. You can run the development version of Plinth using -the following command. +for development. Plinth will be available at https://localhost:4430/plinth +(with an invalid SSL certificate). To watch logs: $ vagrant ssh -$ freedombox-develop -Plinth will be available at https://localhost:4430/plinth (with -an invalid SSL certificate). +$ sudo freedombox-logs " config.trigger.after [:up, :resume, :reload] do |trigger| diff --git a/container b/container index e2e3941fe..edbf447a9 100755 --- a/container +++ b/container @@ -196,9 +196,6 @@ cd /freedombox/ sudo apt-get -y install make sudo make provision-dev -echo 'alias freedombox-develop="cd /freedombox; sudo -u plinth /freedombox/run --develop"' \ - >> /home/fbx/.bashrc - # Make some pytest related files and directories writable to the fbx user sudo touch geckodriver.log sudo chmod a+rw geckodriver.log @@ -241,25 +238,7 @@ fi # Run the plinth server if functional tests are requested if [[ "{pytest_command}" =~ "--include-functional" ]] then - is_plinth_running=0 - ps -ax -o cmd | grep -q "^sudo -u plinth /freedombox/run" && \ - is_plinth_running=1 - ps -ax -o cmd | grep -q "^/usr/bin/python3 /usr/bin/plinth" && \ - is_plinth_running=1 - - if [[ $is_plinth_running -eq 1 ]] - then - echo "> In machine: Plinth is already running" - else - echo -n "> In machine: Starting plinth ... " - sudo -u plinth /freedombox/run --develop > plinth.log 2>&1 & - while ! grep -q "Setup finished" plinth.log - do - sleep 1 - echo -n . - done - echo - fi + make -C /freedombox wait-while-first-setup if [[ "{pytest_command}" != *"--splinter-headless"* ]] then @@ -1074,7 +1053,7 @@ Folder overlay : (host, read-only){project_folder} SSH easily : {script} ssh {options} Run tests : {script} run-tests {options} [ --pytest-args ... ] -Run FreedomBox inside : freedombox-develop +Watch FreedomBox logs : sudo freedombox-logs Web access : https://{ip_address}/ Ports access : Any port on {ip_address}