How can OnOff Shim cleanly shut down my server?

Hi,

I’m installing the OnOff Shim on a Minecraft server (RPi4). The OnOff Shim works perfectly but how to configure it to shutdown safely my Minecraft server before to shutdown the power? This question doesn’t concern specifically Minecraft, it concerns any kind of servers in which a dedicated shutdown process must be triggered to avoid a server data corruption.

The problem is I cannot launch the server shutdown in parallel to the shutdown process because the server shutdown takes a litte bit of time (arround 20s), and as a safety measure I have to check that it is effectively stopped.

In my case I should:

  • intercept the button request (GPIO 17)
  • initiate the server shutdown (typically a stop.sh script) and wait until it’s done
  • then continue with the power shutdown (GPIO 4)

I tried to understand what the OnOff scripts are doing exactly but it appears a little bit cryptic for me…

Any help is welcome.
Thank you.

Matock

Found it. I deliver here the solution for those who are interested.

The server is launched on boot as a service by using the parameter ExecStart=…start.sh
In the same way I used the parameter ExecStop=…stop.sh

So when a shutdown is triggered, all services are properly stopped before the system shutdown and poweroff.

I’m learning, I’m learning…
Cheers