Controlled Shutdown

I integrated BBG on my embedded system.
I would like shutdown the bbg when the power supply interrupts.

What do you recommend me to do?

Now, I’m using a signal as analogic input on BBG for check VCC, and with a python script I read the signal and, when the VCC interrupts, a pull down resistor pulls the value of AIN signal to 0V.
In this way, battery remains linked to pmic inputs, ad I see the beaglebone’s blue led D1 always turned on, so I am thinking to use an gpio output singnal from BBG as an enable of battery.

Are there another ways to do that?