How to delay an app launch until network is online after boot?

Hey Manjaro users,

I have a Python-based app I want to autostart after login, but it needs a working internet connection to authenticate and sync data.

I added it to my session autostart (XFCE), but sometimes it launches before the Wi-Fi connects, causing it to fail silently.

Is there a clean way to delay the app launch until the system is connected to the network?

Would nm-online or a custom script in ~/.config/autostart be the best route? Or is there a Manjaro-friendly way to manage this with systemd or NetworkManager hooks?

Appreciate any tips or working examples!

— Jhonn Mick

#!/bin/bash

while ! ping -c1 -W1 8.8.8.8 &>/dev/null; do
    echo "Waiting for connection..."
    sleep 1
done

echo "hello"

Easy using a bash script. Instead of echo “hello”, run your app

6 Likes

Welcome to the Manjaro community

As a new or infrequent forum user, please take some time to familiarise yourself with Forum requirements, and the many ways to use the forum to your benefit:


Update Announcements

The Update Announcements contain important information and a Known Issues and Solutions section that should generally be checked before posting a request for support.

System Information

While information from *-fetch type apps might be fine for someone wishing to buy your computer, for Support purposes it’s better to ask your system directly; :eyes:

Output of the inxi command with appropriate parameters will achieve this (naturally, formatted according to forum guidelines) and will generally be more useful for those wishing to help:

inxi --filter --verbosity=8

or the short form:

inxi -zv8

Be prepared to provide output from other commands whenever asked. It’s equally important to provide as much actionable information as possible in your first post, rather than simply indicating there is a problem.

Highly Recommended
Required Reading
Technical Resources

There is many ways you can do this… nm-online is just one - I would create a function as part of the app - to check for internet connection - using the requests library.

Our mirror utility pacman-mirrors contains functionality like this - so the following snippet will only work on a Manjaro Linux system

from pacman_mirrors.functions import httpFn

print(httpFn.check_internet_connection())

But the code providing the response is fairly simple…

1 Like