Merge ~dilyn-corner/chromium-browser/+git/snap-from-source:daemon into ~chromium-team/chromium-browser/+git/snap-from-source:daemon

Proposed by Nathan Teodosio
Status: Merged
Merged at revision: c73e3bbdc8bd60d12dbe645ea1193ca482d7c6e8
Proposed branch: ~dilyn-corner/chromium-browser/+git/snap-from-source:daemon
Merge into: ~chromium-team/chromium-browser/+git/snap-from-source:daemon
Diff against target: 109 lines (+75/-0)
4 files modified
launcher/chromium.launcher (+11/-0)
launcher/daemon.wrapper (+17/-0)
snap/hooks/configure (+13/-0)
snapcraft.yaml (+34/-0)
Reviewer Review Type Date Requested Status
Nathan Teodosio Approve
Sebastien Bacher Pending
Review via email: mp+437450@code.launchpad.net

This proposal supersedes a proposal from 2023-02-16.

Description of the change

This MR does one key thing: add a configure and install hook to enable the daemon just in case a specific value is set (daemon=true)
Because the daemon is installed disabled by default, only people who intentionally enable it have the daemon run. Allowing a config option to be set with `snap set` means that this can be set as a default value for Ubuntu Core systems.

Other changes include adding a wrapper to guarantee the Wayland socket is in the right place, and avoiding space splitting in the url set by `snap set chromium url`.

To post a comment you must log in.
Revision history for this message
Nathan Teodosio (nteodosio) wrote : Posted in a previous version of this proposal

I deleted the 037c879 and a8740c8 (corresponding to the patch sent via e-mail) from the target branch so as we could review the whole changes.

Launchpad picked it up in the "Unmerged commits" below but the it nonetheless didn't list them in the "Preview diff".

I am superseding this proposal so that we can have a whole diff for review. Sorry for the inconvenience.

Revision history for this message
Nathan Teodosio (nteodosio) wrote :

Thanks for the merge request, Dilyn. Some points I'd like to better understand:

1. I don't see any statement to set daemon to true, only to false. Why is that? And why do we need to set it to false if (as far as I know) nothing checks whether it is false?

2. Do we need both an install and a configure hook? Judging by the documentation[1], if the install hook is run, so is the configure hook, and *install + configure* seems to do essentially the same a lone *configure*, namely "if snapctl get daemon, then start and enable the service, else stop and disable it".

[1] https://snapcraft.io/docs/supported-snap-hooks#heading--the-configure-hook

review: Needs Information
Revision history for this message
Dilyn (dilyn-corner) wrote :

> 1. I don't see any statement to set daemon to true, only to false. Why is that?

The ultimate intention here is to provide a way of running chromium as a proper kiosk. This is probably not the preferred way of running chromium, so we want to safeguard this as an opt-in choice for users of the snap. In addition, people who want to run chromium as a kiosk will probably want to ensure it launches automatically without intervention. Thus, the onus should be on users to explicitly say they want the kiosk feature, and only then should the daemon be enabled.

One use-case is for Ubuntu Core users: they can add a config value to their gadget snap to set daemon=true so that when they install the image on their device, chromium will launch in the right way "out of the box".

> And why do we need to set it to false if (as far as I know) nothing checks whether it is false?

We set it to false at the very least as a sanity check for users - it offers a transparent way to tell if the daemon is actually enabled or not.

> 2. Do we need both an install and a configure hook?

That's a fair question. Examples are provided by us here:
https://github.com/MirServer/iot-example-graphical-snap

Their install hook explicitly checks for whether or not the snap is installed on an Ubuntu Core system. I see no real need for this, as the question can be side-stepped in a simpler way (namely, setting the daemon as enabled via the gadget snap as mentioned above). I think we could safely eliminate the install hook for the reason you point out; I included it here for a more "complete" handling of the snap during its life cycle.

Revision history for this message
Nathan Teodosio (nteodosio) wrote :

>> 1.
> so we want to safeguard this as an opt-in choice for users of the snap.

Ah alright, we never set daemon to true because the user is supposed to run

  snap set chromium daemon=true

, correct?

Revision history for this message
Dilyn (dilyn-corner) wrote :

Exactly, yes!

Revision history for this message
Nathan Teodosio (nteodosio) wrote :

OK, then please remove the install hook for the simplification.

As far as I'm concerned this is good to merge for a latest/stable/daemon
channel.

Revision history for this message
Dilyn (dilyn-corner) wrote :

Done!

Revision history for this message
Nathan Teodosio (nteodosio) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/launcher/chromium.launcher b/launcher/chromium.launcher
2index 1c57644..e0f40db 100755
3--- a/launcher/chromium.launcher
4+++ b/launcher/chromium.launcher
5@@ -151,6 +151,17 @@ esac
6 # Refer to https://bugs.archlinux.org/task/76268.
7 CHROMIUM_FLAGS="$CHROMIUM_FLAGS --disable-features=TFLiteLanguageDetectionEnabled"
8
9+# Check if the user wants to actually run chromium as a daemon
10+daemon="$(snapctl get daemon)"
11+if [ "$daemon" = "true" ]; then
12+ # If chromium is running as a daemon, assume we're running as a kiosk.
13+ CHROMIUM_FLAGS="$CHROMIUM_FLAGS --kiosk --no-sandbox --disable-dev-shm-usage"
14+ # If we're running as a kiosk, we are using Frame, so use Wayland.
15+ CHROMIUM_FLAGS="$CHROMIUM_FLAGS --enable-features=UseOzonePlatform --ozone-platform=wayland"
16+ # If we're running as a kiosk, we are loading a specific URL.
17+ set -- "$@" "$(snapctl get url)"
18+fi
19+
20 if [ $WANT_TEMP_PROFILE -eq 0 ] ; then
21 exec "$SNAP/usr/lib/chromium-browser/chrome" --password-store=$PASSWORD_STORE $CHROMIUM_FLAGS "$@"
22 else
23diff --git a/launcher/daemon.wrapper b/launcher/daemon.wrapper
24new file mode 100755
25index 0000000..1724efd
26--- /dev/null
27+++ b/launcher/daemon.wrapper
28@@ -0,0 +1,17 @@
29+#!/bin/sh
30+
31+set -e
32+
33+real_xdg_runtime_dir=$(dirname "${XDG_RUNTIME_DIR}")
34+real_wayland=${real_xdg_runtime_dir}/${WAYLAND_DISPLAY:-wayland-0}
35+
36+# Permissions applying to the deepest directory is fine
37+#shellcheck disable=2174
38+mkdir -p "$XDG_RUNTIME_DIR" -m 700
39+
40+ln -sf "${real_wayland}" "$XDG_RUNTIME_DIR"
41+ln -sf "${real_wayland}.lock" "$XDG_RUNTIME_DIR"
42+
43+unset DISPLAY
44+
45+exec "$@"
46diff --git a/snap/hooks/configure b/snap/hooks/configure
47new file mode 100755
48index 0000000..1255869
49--- /dev/null
50+++ b/snap/hooks/configure
51@@ -0,0 +1,13 @@
52+#!/bin/sh
53+
54+set -ex
55+
56+daemon="$(snapctl get daemon)"
57+
58+if [ "$daemon" = "true" ]; then
59+ if snapctl services "$SNAP_INSTANCE_NAME.daemon" | grep -q inactive; then
60+ snapctl start --enable "$SNAP_INSTANCE_NAME.daemon" 2>&1 || true
61+ fi
62+else
63+ snapctl stop --disable "$SNAP_INSTANCE_NAME.daemon" 2>&1 || true
64+fi
65diff --git a/snapcraft.yaml b/snapcraft.yaml
66index 3d4ec43..1fccc46 100644
67--- a/snapcraft.yaml
68+++ b/snapcraft.yaml
69@@ -73,6 +73,40 @@ apps:
70 - upower-observe
71 slots:
72 - mpris
73+ daemon:
74+ extensions: [gnome-3-38]
75+ daemon: simple
76+ command: bin/chromium.launcher
77+ command-chain:
78+ - bin/daemon.wrapper
79+ - snap/command-chain/desktop-launch
80+ restart-delay: 3s
81+ install-mode: disable
82+ environment:
83+ CHROME_CONFIG_HOME: $SNAP_USER_COMMON
84+ PIPEWIRE_CONFIG_NAME: $SNAP/usr/share/pipewire/pipewire.conf
85+ PIPEWIRE_MODULE_DIR: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pipewire-0.3
86+ SPA_PLUGIN_DIR: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/spa-0.2
87+ plugs:
88+ - audio-playback
89+ - audio-record
90+ - bluez # for Web Bluetooth (https://launchpad.net/bugs/1887201)
91+ - camera
92+ - cups
93+ - home
94+ - joystick
95+ - mount-observe
96+ - network
97+ - network-manager
98+ - password-manager-service
99+ - pulseaudio # remove once snapd 2.41 is available everywhere
100+ - raw-usb # for WebUSB (https://launchpad.net/bugs/1780678)
101+ - removable-media
102+ - screen-inhibit-control
103+ - system-packages-doc
104+ - u2f-devices
105+ - unity7 # required for xdg-open to work
106+ - upower-observe
107
108 plugs:
109 # This is not used or needed for anything other than to trigger automatic

Subscribers

People subscribed via source and target branches

to status/vote changes: