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 <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Sunil Mohan Adapa 2025-10-27 21:34:58 -07:00 committed by Veiko Aasa
parent e5026282fe
commit 24d2d92ab5
No known key found for this signature in database
GPG Key ID: 478539CAE680674E
6 changed files with 46 additions and 45 deletions

View File

@ -16,7 +16,7 @@ RUN apt-get dist-upgrade -y
# Install freedombox package so that plint:plinth user/group are created etc. # Install freedombox package so that plint:plinth user/group are created etc.
RUN apt-get install -y freedombox/trixie-backports 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 # Don't ask for the secret in first wizard
RUN rm -f /var/lib/plinth/firstboot-wizard-secret RUN rm -f /var/lib/plinth/firstboot-wizard-secret

View File

@ -16,8 +16,7 @@
- apt-get update - apt-get update
- apt-get -y install make - apt-get -y install make
- make provision-dev - make provision-dev
- sudo -u plinth ./run --develop > plinth.log 2>&1 & - make wait-while-first-setup
- while ! grep -q "Setup finished" plinth.log; do sleep 1; echo -n .; done
script: 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 - 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: artifacts:

View File

@ -143,12 +143,12 @@ directory:
guest$ cd /freedombox guest$ cd /freedombox
``` ```
Run the development version of FreedomBox Service in the container using the FreedomBox Service runs as plinth.service in the container. This service
following command. This command continuously deploys your code changes into the restarts when it detects a change to the source code file. This provides a quick
container providing a quick feedback cycle during development. feedback cycle during development. To watch service logs run:
```bash ```bash
guest$ freedombox-develop guest$ sudo freedombox-logs
``` ```
If you have changed any system configuration files during your development, 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. system and their changes to reflect properly.
```bash ```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. 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 vm$ cd /freedombox
``` ```
Run the development version of FreedomBox Service (Plinth) from your source FreedomBox Service runs as plinth.service in the virtual machine. This service
directory in the virtual machine using the following command. This command restarts when it detects a change to the source code file. This provides a quick
continuously deploys your code changes into the virtual machine providing a feedback cycle during development. To watch service logs run:
quick feedback cycle during development.
```bash ```bash
vm$ freedombox-develop vm$ sudo freedombox-logs
``` ```
If you have changed any system configuration files during your development, If you have changed any system configuration files during your development,

View File

@ -161,6 +161,16 @@ Environment=PYTHONPATH=/freedombox/
endef endef
export DEVELOP_SERVICE_CONF 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) # Run basic setup for a developer environment (VM or container)
provision-dev: provision-dev:
# Install newer build dependencies if any # Install newer build dependencies if any
@ -170,9 +180,15 @@ provision-dev:
# Install latest code over .deb # Install latest code over .deb
$(MAKE) build install $(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/ mkdir -p /etc/systemd/system/freedombox-privileged.service.d/
echo "$$DEVELOP_SERVICE_CONF" > /etc/systemd/system/freedombox-privileged.service.d/develop.conf 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 # Reload newer systemd units, ignore failure
-systemctl daemon-reload -systemctl daemon-reload
@ -183,6 +199,10 @@ provision-dev:
-test -d /run/systemd/system && \ -test -d /run/systemd/system && \
systemctl enable --now freedombox-privileged.socket 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 # Stop any ongoing upgrade, ignore failure
-killall -9 unattended-upgr -killall -9 unattended-upgr
@ -207,6 +227,12 @@ provision-dev:
DEBIAN_FRONTEND=noninteractive apt-get install --yes ncurses-term \ DEBIAN_FRONTEND=noninteractive apt-get install --yes ncurses-term \
sshpass bash-completion 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: \ .PHONY: \
build \ build \
check \ check \
@ -219,4 +245,5 @@ provision-dev:
configure \ configure \
install \ install \
provision \ provision \
update-translations update-translations \
wait-while-first-setup

10
Vagrantfile vendored
View File

@ -24,17 +24,13 @@ Vagrant.configure(2) do |config|
config.vm.provision "shell", inline: <<-SHELL config.vm.provision "shell", inline: <<-SHELL
cd /freedombox/ cd /freedombox/
make provision-dev make provision-dev
echo 'alias freedombox-develop="cd /freedombox; sudo -u plinth /freedombox/run --develop"' >> /home/vagrant/.bashrc
SHELL SHELL
config.vm.provision "tests", run: "never", type: "shell", path: "plinth/tests/functional/install.sh" config.vm.provision "tests", run: "never", type: "shell", path: "plinth/tests/functional/install.sh"
config.vm.post_up_message = "FreedomBox virtual machine is ready config.vm.post_up_message = "FreedomBox virtual machine is ready
for development. You can run the development version of Plinth using for development. Plinth will be available at https://localhost:4430/plinth
the following command. (with an invalid SSL certificate). To watch logs:
$ vagrant ssh $ vagrant ssh
$ freedombox-develop $ sudo freedombox-logs
Plinth will be available at https://localhost:4430/plinth (with
an invalid SSL certificate).
" "
config.trigger.after [:up, :resume, :reload] do |trigger| config.trigger.after [:up, :resume, :reload] do |trigger|

View File

@ -196,9 +196,6 @@ cd /freedombox/
sudo apt-get -y install make sudo apt-get -y install make
sudo make provision-dev 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 # Make some pytest related files and directories writable to the fbx user
sudo touch geckodriver.log sudo touch geckodriver.log
sudo chmod a+rw geckodriver.log sudo chmod a+rw geckodriver.log
@ -241,25 +238,7 @@ fi
# Run the plinth server if functional tests are requested # Run the plinth server if functional tests are requested
if [[ "{pytest_command}" =~ "--include-functional" ]] if [[ "{pytest_command}" =~ "--include-functional" ]]
then then
is_plinth_running=0 make -C /freedombox wait-while-first-setup
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
if [[ "{pytest_command}" != *"--splinter-headless"* ]] if [[ "{pytest_command}" != *"--splinter-headless"* ]]
then then
@ -1074,7 +1053,7 @@ Folder overlay : (host, read-only){project_folder}
SSH easily : {script} ssh {options} SSH easily : {script} ssh {options}
Run tests : {script} run-tests {options} [ --pytest-args ... ] Run tests : {script} run-tests {options} [ --pytest-args ... ]
Run FreedomBox inside : freedombox-develop Watch FreedomBox logs : sudo freedombox-logs
Web access : https://{ip_address}/ Web access : https://{ip_address}/
Ports access : Any port on {ip_address} Ports access : Any port on {ip_address}