Automatic flatpak update systemd service fails

It works fine when I start the service manually.

flatpak-update.sh

#!/usr/bin/env bash

notify-send --app-name="Flatpak Automatic Update" \
    --icon="system-software-update" --hint="string:desktop-entry:discover" \
    "Updating applications..."

(flatpak update --assumeyes --noninteractive && \
    notify-send --app-name="Flatpak Automatic Update" \
        --icon="system-software-update" \
        --hint="string:desktop-entry:discover" \
        "Application updates have been successfully installed") || \
    notify-send --app-name="Flatpak Automatic Update" \
        --icon="system-software-update" \
        --hint="string:desktop-entry:discover" \
        "Failed to update applications"

cat update-system-flatpaks.service

[Unit]
Description=Update system Flatpaks
After=graphical-session.target network-online.target
Wants=network-online.target

[Service]
Type=oneshot
ExecStart=%h/.local/bin/flatpak-updates.sh

[Install]
WantedBy=default.target

cat update-system-flatpaks.timer

[Unit]
Description=Update system Flatpaks every Saturday after login

[Timer]
OnCalendar=Sat 10:00
Persistent=true

[Install]
WantedBy=timers.target

systemctl --user status update-system-flatpaks

β—‹ update-system-flatpaks.service - Update system Flatpaks
     Loaded: loaded (/home/rob/.config/systemd/user/update-system-flatpaks.service; disabled; preset: disabled)
    Drop-In: /usr/lib/systemd/user/service.d
             └─10-timeout-abort.conf
     Active: inactive (dead) since Sat 2025-05-17 10:14:21 CEST; 6h ago
 Invocation: 67e540a8e18a4b3c83aee6708aeb8da6
TriggeredBy: ● update-system-flatpaks.timer
    Process: 177183 ExecStart=/home/rob/.local/bin/flatpak-updates.sh (code=exited, status=0/SUCCESS)
   Main PID: 177183 (code=exited, status=0/SUCCESS)
   Mem peak: 6.7M
        CPU: 116ms

May 17 10:14:20 hp-laptop systemd[1517]: Starting update-system-flatpaks.service - Update system Flatpaks...
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since runtime/org.kde.Platform/x86_64/6.9 is already installed: No such ref 'runtime/org.kde.Platform/x86_64/6.9' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since runtime/org.kde.Platform/x86_64/6.8 is already installed: No such ref 'runtime/org.kde.Platform/x86_64/6.8' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since runtime/org.kde.Platform.Locale/x86_64/6.9 is already installed: No such ref 'runtime/org.kde.Platform.Locale/x86_64/6.9' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since runtime/org.kde.Platform.Locale/x86_64/6.8 is already installed: No such ref 'runtime/org.kde.Platform.Locale/x86_64/6.8' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since runtime/org.kde.KStyle.Adwaita/x86_64/6.8 is already installed: No such ref 'runtime/org.kde.KStyle.Adwaita/x86_64/6.8' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since runtime/org.gtk.Gtk3theme.Breeze/x86_64/3.22 is already installed: No such ref 'runtime/org.gtk.Gtk3theme.Breeze/x86_64/3.22' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since runtime/org.gnome.Platform/x86_64/48 is already installed: No such ref 'runtime/org.gnome.Platform/x86_64/48' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since runtime/org.gnome.Platform.Locale/x86_64/48 is already installed: No such ref 'runtime/org.gnome.Platform.Locale/x86_64/48' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since runtime/org.freedesktop.Platform/x86_64/24.08 is already installed: No such ref 'runtime/org.freedesktop.Platform/x86_64/24.08' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since runtime/org.freedesktop.Platform.openh264/x86_64/2.5.1 is already installed: No such ref 'runtime/org.freedesktop.Platform.openh264/x86_64/2.5.1' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since runtime/org.freedesktop.Platform.VAAPI.Intel/x86_64/24.08 is already installed: No such ref 'runtime/org.freedesktop.Platform.VAAPI.Intel/x86_64/24.08' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since runtime/org.freedesktop.Platform.Locale/x86_64/24.08 is already installed: No such ref 'runtime/org.freedesktop.Platform.Locale/x86_64/24.08' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since runtime/org.freedesktop.Platform.GL.default/x86_64/24.08extra is already installed: No such ref 'runtime/org.freedesktop.Platform.GL.default/x86_64/24.08extra' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since runtime/org.freedesktop.Platform.GL.default/x86_64/24.08 is already installed: No such ref 'runtime/org.freedesktop.Platform.GL.default/x86_64/24.08' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since runtime/net.ankiweb.Anki.Locale/x86_64/stable is already installed: No such ref 'runtime/net.ankiweb.Anki.Locale/x86_64/stable' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since runtime/com.chatterino.chatterino.Locale/x86_64/stable is already installed: No such ref 'runtime/com.chatterino.chatterino.Locale/x86_64/stable' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since runtime/com.bitwarden.desktop.Locale/x86_64/stable is already installed: No such ref 'runtime/com.bitwarden.desktop.Locale/x86_64/stable' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since app/org.nicotine_plus.Nicotine/x86_64/stable is already installed: No such ref 'app/org.nicotine_plus.Nicotine/x86_64/stable' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since app/net.ankiweb.Anki/x86_64/stable is already installed: No such ref 'app/net.ankiweb.Anki/x86_64/stable' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since app/com.chatterino.chatterino/x86_64/stable is already installed: No such ref 'app/com.chatterino.chatterino/x86_64/stable' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since app/com.brave.Browser/x86_64/stable is already installed: No such ref 'app/com.brave.Browser/x86_64/stable' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: F: Warning: Treating remote fetch error as non-fatal since app/com.bitwarden.desktop/x86_64/stable is already installed: No such ref 'app/com.bitwarden.desktop/x86_64/stable' in remote flathub
May 17 10:14:21 hp-laptop flatpak-updates.sh[177241]: Nothing to do.
May 17 10:14:21 hp-laptop systemd[1517]: Finished update-system-flatpaks.service - Update system Flatpaks.

Could the problem be that network-online.target isn’t available to user units, so the service starts before it has a working network connection?

For example as in this Podman issue and this systemd enhancement request.

Changed the service to check for internet in the shell script (not sure if there is a better way of doing this)

rob@hp-laptop:~/.config/systemd/user$ cat update-flatpaks.service
[Unit]
Description=Update Flatpaks retry hourly on fail
Requires=graphical-session.target
After=graphical-session.target

[Service]
Type=oneshot
ExecStart=%h/.local/libexec/update-flatpaks.sh
Restart=on-failure
RestartSec=3600
rob@hp-laptop:~/.config/systemd/user$ cat update-flatpaks.timer
[Unit]
Description=Update system Flatpaks every Saturday at 10:00 after login

[Timer]
OnCalendar=Sat 10:00
Persistent=true

[Install]
WantedBy=timers.target

rob@hp-laptop:~/.config/systemd/user$ cat ~/.local/libexec/update-flatpaks.sh
#!/usr/bin/env bash

if [ "$(nmcli networking connectivity)" != "full" ] ; then
    exit 1
fi

notify-send --app-name="Flatpak Automatic Update" \
    --icon="system-software-update" --hint="string:desktop-entry:discover" \
    "Updating applications..."

(flatpak update --assumeyes --noninteractive && \
    notify-send --app-name="Flatpak Automatic Update" \
        --icon="system-software-update" \
        --hint="string:desktop-entry:discover" \
        "Application updates have been successfully installed") || \
    notify-send --app-name="Flatpak Automatic Update" \
        --icon="system-software-update" \
        --hint="string:desktop-entry:discover" \
        "Failed to update applications"
1 Like