First, you need a UPS or a laptop so the PC can stay on, otherwise this does not work.
Then use a relay that closes contacts when there is power, wire one contact to LinuxCNC feed-hold so it stops when power goes off.
Note the gcode line it stoped, shut down and wait for power to come back.
LinuxCNC has a feature to save the joint position on power failure so you can always know where is stopped.
It also has "run from line" as long as that line is not an arc.
Marlin writes to SD every line it is executing, so it can continue easily.
-
We have ocasional power cuts, no UPS, nothing, just run from the line it stoped. On plenty of machines, so far never needed anything more.
ASUS ROG Crosshair VIII Impact - AMD X570