You would need a third device monitoring both for this edge case. Once the server has been told to shut down, it's going to shut down.
The third device (also on the UPS, like an Rpi or ESP) can then check for power availability through the UPS and whatever logic you want to apply, can then use wake on lan to the server to power it up once it shuts down.