Start a Service When Network Connects

Learn how to create and manage systemd services that depend on network connectivity. This scenario teaches you to build robust services that wait for network availability before starting, ensuring your applications have the network resources they need.

What you'll learn:

  • Creating network-dependent systemd services
  • Using network-online.target for true connectivity
  • Implementing proper network dependency ordering
  • Configuring automatic restart on network failures
  • Managing NetworkManager-wait-online service
  • Verifying network target status and connectivity

About Network-Dependent Services

Network-dependent services are crucial for applications that require internet connectivity, such as web servers, database connections, API clients, and cloud services. Understanding the difference between network.target and network-online.target is essential for creating reliable services that wait for actual connectivity, not just network interfaces.

💡 Key Concepts:

  • network.target - Network interfaces are up
  • network-online.target - Network is actually reachable
  • After=network-online.target - Start after network is online
  • Wants=network-online.target - Depend on network connectivity
  • NetworkManager-wait-online.service - Ensures true connectivity