Posts

Showing posts with the label System service

Starting systemd service after network-online.target but DNS is still not available

Question related to starting a systemd service after the network is online, even when DNS may not be available immediately. If you're facing a similar issue, here are some possible solutions: 1. **Wait for DNS Resolution in Your Service Script**:    Inside your systemd service unit, you can specify `ExecStartPre` to execute a script before your service starts. You can use this to check for DNS availability by trying to resolve a well-known domain name and waiting until it succeeds. Here's an example of what it could look like:    ```ini    [Service]    ExecStartPre=/path/to/script.sh    ExecStart=/your/actual/service    ```    In the `script.sh`, you can use a loop to check for DNS resolution:    ```bash    #!/bin/bash    while ! host -t A google.com; do      sleep 1    done    ``` 2. **Use `After` and `Wants` Directives**:    You can adjust your systemd service unit by adding `After` and `Wants` directives to make your service depend on network-online.target but not directly o