[CentOS] Systemd service unit file needs to wait until a specific interface is up

Wed Sep 23 14:08:05 UTC 2020
Carlos Lopez <clopmz at outlook.com>

Perfect!! Many thanks Stephen. Works like a charm.

On 23/09/2020, 15:08, "CentOS on behalf of Stephen John Smoogen" <centos-bounces at centos.org on behalf of smooge at gmail.com> wrote:

    On Wed, 23 Sep 2020 at 04:33, Carlos Lopez <clopmz at outlook.com> wrote:

    > Hi all,
    >
    >
    > With SystemD, how can I make certain service dependent on certain network
    > interfaces being up?
    >
    > For example, I have an 802.1ad bond interface I need to wait on for being
    > up (this interface has no ip address assigned, it is used to capture
    > networks packets with a tcpdump’s script). Every time this service fails
    > because bond interface is not up.
    >
    >
    >
    > I have configured the service as:
    >
    >
    > [Unit]
    >
    > Description=tcpdump capture script
    >
    > After=network.target
    >
    > Wants=network-online.target
    >
    >
    >
    > But it doesn’t work …. Any tip or trick?
    >
    >
    >

    So the network just calls the scripts and exits so they can take a while to
    get working. I think this website covers what you want to do

    https://unix.stackexchange.com/questions/257888/systemd-wait-for-network-interface-to-be-up-before-running-service

    systemctl list-units --no-pager | grep subsystem-net

    Then look for the device which matches the one you are listening to. Change
    the After=network.target to


    BindsTo=sys-devices-virtual-net-<device>.device
    After=sys-devices-virtual-net-<device>.device

    where <device> is the interface you found (aka eth2, br9, bond0 etc)



    > My host is CentOS8 x86_64.
    >
    >
    > Regards,
    > C. L. Martinez
    >
    > _______________________________________________
    > CentOS mailing list
    > CentOS at centos.org
    > https://lists.centos.org/mailman/listinfo/centos
    >


    -- 
    Stephen J Smoogen.
    _______________________________________________
    CentOS mailing list
    CentOS at centos.org
    https://lists.centos.org/mailman/listinfo/centos