iRule: Same host two ports, if port 1 is not listening traffic should not go on port 2

Any sample iRule available for below scenario? or any other functionality available in F5 that i can use for below case.

Scenario:

One host have service1 listening on port 1 (pool#1) and ftp traffic listening on port 2 (pool#2)

if service1 is marked down by the f5 monitor then traffic on ftp port 2 also should stop receiving the traffic.

Both ports are configured in separate Virtual servers i.e. service1 pool and ftp pool are separated, have two separate f5 pools.

You could use a Local Traffic Profile or an iRule to check that both pools are available before selecting the pool for your FTP service.

I’ve provided an example of an iRule below:

when CLIENT_ACCEPTED {
    if {([active_members pool1] < 1) && ([active_members pool2] < 1)} {
        pool pool2
    }
}

create a new monitor for port 1 with alias port fixed…

assign this monitor to pool2

this configuration will mark pool2 member down if monitor on port 1 fails

Thank you! those both answers server my two different purposes. Appreciate your help!

Cheers!