Skip to content
Snippets Groups Projects

doc/systemd: system service example

Open Stefan Agner requested to merge agners/weston:weston-systemd into main

There are many bad and even worse attempts to make Weston run as a systemd service, and very few good ones. Let's add a good one as an example in upstream: does not use weston-launch, does not run weston as root, does not need wrapper scripts, and relies on logind and PAM.

This example has been composed from a couple of real-world Weston unit files used in production.

The service file is not installed by the build. It would likely need small adjustments for each distribution or system to be deplyed on.

Fixes: #7 Signed-off-by: Pekka Paalanen pekka.paalanen@collabora.co.uk Signed-off-by: Stefan Agner stefan@agner.ch

This merge request is based on !39 (closed).

@pq I allowed to put myself author to avoid wrongly attributed mentions on Gitlab. We are probably around 50% of contribution each, let me know if you prefer it the other way around.

Merge request reports

Members who can merge are allowed to add commits.

Pipeline #157288 passed

Pipeline passed for d9148c75 on agners:weston-systemd

Approval is optional
Ready to merge by members who can write to the target branch.

Merge details

  • The source branch is 2770 commits behind the target branch.
  • 8 commits and 1 merge commit will be added to .
  • Source branch will not be deleted.

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
21 protocol, and also allows socket activation and configuring listening sockets
22 via systemd.
23
24
25 weston@.service
26 ---------------
27
28 `weston@.service` is an example systemd service file on how to run Weston as a
29 system service. The service starts a user session of the named user on the given
30 virtual terminal. This is useful for running a login manager or for dedicated
31 systems that do not have personal user accounts and do not need the user to log
32 in.
33
34 The service uses the PAM service name `weston-autologin` to setup the user
35 session. Make sure to install a suitable PAM configuration file in
36 `/etc/pam.d/weston-autologin`. A basic configuration file could look like this:
  • 50 TTYReset=yes
    51 TTYVHangup=yes
    52 TTYVTDisallocate=yes
    53
    54 # Fail to start if not controlling the tty.
    55 StandardInput=tty-fail
    56 StandardOutput=journal
    57 StandardError=journal
    58
    59 # Log this user with utmp, letting it show up with commands 'w' and 'who'.
    60 UtmpIdentifier=%I
    61 UtmpMode=user
    62
    63 [Install]
    64 WantedBy=graphical.target
    65 DefaultInstance=tty7
  • mentioned in issue #428 (closed)

  • I am also starting Weston with a systemd service unit, but I have the problem, that the Weston log messages, written to stderr, are not showing up in the systemd journal (journalctl -o short-precise -u weston.service -b).

    systemd’s StandardError= is set to the default value inherit.

    Can you confirm that with your setup?

  • 3
    4 These examples rely on Weston's logind and systemd support. Weston needs to be
    5 built with options: `--enable-dbus --enable-systemd-login
    6 --enable-systemd-notify`
    7
    8 Furthermore, Weston needs to be configured to load systemd-notify.so plugin.
    9 This can be done on the Weston command line:
    10
    11 $ weston --modules=systemd-notify.so
    12
    13 or in weston.ini:
    14
    15 ~~~
    16 [core]
    17 modules=systemd-notify.so
    18 ~~~
    • Is this Markdown syntax? If you intended it with four spaces (or a tab), it’s less overall lines (but copying and pasting from the Markdown files directly is more effort).

    • Please register or sign in to reply
  • 1 systemd integration examples
    2 ============================
    3
    4 These examples rely on Weston's logind and systemd support. Weston needs to be
    5 built with options: `--enable-dbus --enable-systemd-login
    6 --enable-systemd-notify`
    7
    8 Furthermore, Weston needs to be configured to load systemd-notify.so plugin.
    9 This can be done on the Weston command line:
    10
    11 $ weston --modules=systemd-notify.so
    12
    13 or in weston.ini:
  • 15 ~~~
    16 [core]
    17 modules=systemd-notify.so
    18 ~~~
    19
    20 The plugin implements the systemd service notification protocol, watchdog
    21 protocol, and also allows socket activation and configuring listening sockets
    22 via systemd.
    23
    24
    25 weston@.service
    26 ---------------
    27
    28 `weston@.service` is an example systemd service file on how to run Weston as a
    29 system service. The service starts a user session of the named user on the given
    30 virtual terminal. This is useful for running a login manager or for dedicated
    • I do not fully understand the statement regarding the login manager. Do you mean to run it in parallel?

    • It refers to using Weston as the display server in which a login manager UI is shown. Like Xorg or gnome-shell.

    • Thank you for clarifying (though I have no idea, how to accomplish that). Also, Xorg or gnome-shell are different layers for me. Anyway, I’d be great, if the sentence could be clarified.

    • Please register or sign in to reply
  • 19
    20 The plugin implements the systemd service notification protocol, watchdog
    21 protocol, and also allows socket activation and configuring listening sockets
    22 via systemd.
    23
    24
    25 weston@.service
    26 ---------------
    27
    28 `weston@.service` is an example systemd service file on how to run Weston as a
    29 system service. The service starts a user session of the named user on the given
    30 virtual terminal. This is useful for running a login manager or for dedicated
    31 systems that do not have personal user accounts and do not need the user to log
    32 in.
    33
    34 The service uses the PAM service name `weston-autologin` to setup the user
  • 23
    24
    25 weston@.service
    26 ---------------
    27
    28 `weston@.service` is an example systemd service file on how to run Weston as a
    29 system service. The service starts a user session of the named user on the given
    30 virtual terminal. This is useful for running a login manager or for dedicated
    31 systems that do not have personal user accounts and do not need the user to log
    32 in.
    33
    34 The service uses the PAM service name `weston-autologin` to setup the user
    35 session. Make sure to install a suitable PAM configuration file in
    36 `/etc/pam.d/weston-autologin`. A basic configuration file could look like this:
    37
    38 ~~~
  • 33
    34 The service uses the PAM service name `weston-autologin` to setup the user
    35 session. Make sure to install a suitable PAM configuration file in
    36 `/etc/pam.d/weston-autologin`. A basic configuration file could look like this:
    37
    38 ~~~
    39 auth required pam_nologin.so
    40 auth required pam_unix.so try_first_pass nullok
    41
    42 account required pam_nologin.so
    43 account required pam_unix.so
    44
    45 session required pam_env.so
    46 session required pam_unix.so
    47 -session optional pam_systemd.so type=wayland class=user desktop=weston
    48 -session optional pam_loginuid.so
    • I tried this, and was wondering, if this PAM configuration causes user things, like Tracker, from a also installed GNOME DE to be started? These are part of user@1000.service.

      $ systemd-cgls
      Control group /:
      -.slice
      ├─user.slice 
      │ └─user-1000.slice 
      │   ├─user@1000.service 
      │   │ ├─gvfs-goa-volume-monitor.service 
      │   │ │ └─345 /usr/libexec/gvfs-goa-volume-monitor
      │   │ ├─pulseaudio.service 
      │   │ │ └─264 /usr/bin/pulseaudio --daemonize=no
      │   │ ├─gvfs-daemon.service 
      │   │ │ ├─287 /usr/libexec/gvfsd
      │   │ │ └─303 /usr/libexec/gvfsd-fuse /run/user/1000/gvfs -f
      │   │ ├─gvfs-udisks2-volume-monitor.service 
      │   │ │ └─306 /usr/libexec/gvfs-udisks2-volume-monitor
      │   │ ├─init.scope 
      │   │ │ ├─243 /lib/systemd/systemd --user
      │   │ │ └─244 (sd-pam)
      │   │ ├─gvfs-gphoto2-volume-monitor.service 
      │   │ │ └─331 /usr/libexec/gvfs-gphoto2-volume-monitor
      │   │ ├─at-spi-dbus-bus.service 
      │   │ │ └─563 /usr/libexec/at-spi-bus-launcher
      │   │ ├─pipewire.service 
      │   │ │ ├─263 /usr/bin/pipewire
      │   │ │ └─278 /usr/bin/pipewire-media-session
      │   │ ├─dbus.service 
      │   │ │ ├─269 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopi…
      │   │ │ ├─349 /usr/libexec/goa-daemon
      │   │ │ └─395 /usr/libexec/goa-identity-service
      │   │ ├─tracker-miner-fs.service 
      │   │ │ └─266 /usr/libexec/tracker-miner-fs
      │   │ ├─gvfs-mtp-volume-monitor.service 
      │   │ │ └─336 /usr/libexec/gvfs-mtp-volume-monitor
      │   │ └─gvfs-afc-volume-monitor.service 
      │   │   └─340 /usr/libexec/gvfs-afc-volume-monitor
      │   ├─session-c1.scope 
      │   │ ├─230 /usr/bin/weston --backend /usr/lib/x86_64-linux-gnu/libweston-9/fbd…
      │   │ ├─267 (sd-pam)
      │   │ ├─279 /usr/lib/x86_64-linux-gnu/weston-keyboard
      │   │ ├─280 /usr/lib/x86_64-linux-gnu/weston-desktop-shell
      │   │ ├─504 /usr/bin/weston-terminal
      │   │ ├─505 /bin/bash
      │   │ ├─515 firefox-esr /run/log/bootchart-20201123-0943.svg
      │   │ ├─585 /usr/lib/firefox-esr/firefox-esr -contentproc -childID 1 -isForBrow…
      │   │ ├─637 /usr/lib/firefox-esr/firefox-esr -contentproc -childID 2 -isForBrow…
      │   │ ├─677 /usr/lib/firefox-esr/firefox-esr -contentproc -childID 3 -isForBrow…
      │   │ ├─711 /usr/lib/firefox-esr/firefox-esr -contentproc -childID 4 -isForBrow…
      │   │ ├─764 systemd-cgls
      │   │ └─765 pager
      │   └─session-3.scope 
      │     ├─768 sshd: lu [priv]
      │     ├─775 sshd: lu@pts/1
      │     ├─776 -bash
      │     ├─782 systemd-cgls
      │     └─783 more
      ├─init.scope 
      │ └─1 /lib/systemd/systemd
      └─system.slice 
        ├─systemd-networkd.service 
        │ └─206 /lib/systemd/systemd-networkd
        ├─systemd-udevd.service 
        │ └─197 /lib/systemd/systemd-udevd
        ├─polkit.service 
        │ └─231 /usr/libexec/polkitd --no-debug
        ├─rtkit-daemon.service 
        │ └─270 /usr/libexec/rtkit-daemon
        ├─bluetooth.service 
        │ └─487 /usr/libexec/bluetooth/bluetoothd
        ├─accounts-daemon.service 
        │ └─210 /usr/libexec/accounts-daemon
        ├─anacron.service 
        │ └─766 /usr/sbin/anacron -d -q -s
        ├─systemd-journald.service 
        │ └─188 /lib/systemd/systemd-journald
        ├─upower.service 
        │ └─407 /usr/libexec/upowerd
        ├─udisks2.service 
        │ └─310 /usr/libexec/udisks2/udisksd
        ├─dbus.service 
        │ └─212 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile…
        ├─systemd-timesyncd.service 
        │ └─195 /lib/systemd/systemd-timesyncd
        ├─system-getty.slice 
        │ └─getty@tty1.service 
        │   └─226 /sbin/agetty -o -p -- \u --noclear tty1 linux
        ├─avahi-daemon.service 
        │ ├─211 avahi-daemon: running [gepard.local]
        │ └─217 avahi-daemon: chroot helper
        └─systemd-logind.service 
          └─215 /lib/systemd/systemd-logind
    • Please register or sign in to reply
  • 46 session required pam_unix.so
    47 -session optional pam_systemd.so type=wayland class=user desktop=weston
    48 -session optional pam_loginuid.so
    49 ~~~
    50
    51 Install the service template to `/etc/systemd/system`. You should at the very
    52 least customize the user, but likely also the weston command line. You can edit
    53 the service template before installing, or use `systemctl edit` if the service
    54 template is already installed. The tty can be customized by the instance name
    55 (the portion after the @ symbol). To enable and start the service use:
    56
    57 systemctl enable weston@tty7.service
    58 systemctl start weston@tty7.service
    59
    60 Note: With this unit pam_systemd creates a new user session and session scope
    61 with it. With that systemd now longer considers Weston to be part of the
  • 49 ~~~
    50
    51 Install the service template to `/etc/systemd/system`. You should at the very
    52 least customize the user, but likely also the weston command line. You can edit
    53 the service template before installing, or use `systemctl edit` if the service
    54 template is already installed. The tty can be customized by the instance name
    55 (the portion after the @ symbol). To enable and start the service use:
    56
    57 systemctl enable weston@tty7.service
    58 systemctl start weston@tty7.service
    59
    60 Note: With this unit pam_systemd creates a new user session and session scope
    61 with it. With that systemd now longer considers Weston to be part of the
    62 weston@ttyX.service unit, but the newly created session slice. Use `loginctl` to
    63 find the session name. Logs can be found in `journalctl
    64 --unit=session-<name>.scope`.
  • 1 # This is a system unit for launching Weston with auto-login as the
    2 # user configured here.
    3 #
    4 # Weston must be built with "launcher-logind" and "systemd" support.
    5
    6 [Unit]
    7 Description=Weston, a Wayland compositor, as a system service
    8 Documentation=man:weston(1) man:weston.ini(5)
    9 Documentation=http://wayland.freedesktop.org/
  • 1 [Unit]
    2 Description=Weston Wayland socket
    3 After=user-runtime-dir@1000.service
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading