Stop DVR server when battery is low

I would like to stop the DVR server when my MacBook Pro battery is at a specific value (25% for example) and restart the server when AC power returns. This will allow the MacBook to go into deep sleep and recover when power returns. (I need to stay logged in on the MAC because I need transcoding; I can’t auto login because I need FileVault.)

Any ideas for a configuration change or a Terminal script/process to do this? Getting rid of the Channels “do not sleep” assertion would also work since I have Amphetamine to prevent sleep until a determined battery level.

Maybe applescript?
But honestly you'd be better off with an Intel NUC rather than running on a laptop or really any mini pc with like an n100 chip. Using a laptop as a server is not really a great idea for reasons like this, plus you can also plug a small PC into a small UPS, and that'll handle shutdown.