How to shut the service gracefully?

When I tap the Shutdown buttonon the web UI, the unit shuts down and “falls asleep”. But when I type something like “shutdown now” or “systemctl stop pwnagotchi” in the console, it just leaves its current face there. So how can I terminate the service properly before shutting down my Pi, or it’s unnecessary to do so? I have to write a program or something to shut it down on a specific time.

Now I send a post request just like the web UI does, but this feels stupid. How can I do the same thing by using something in the system itself?

If you’re just looking to clear the display the pwnagotchi cli has the --clear Flag which will clear the display for you. You could run that after shutting down the service with systemctl

No i want him look like this:

and do other necessary tasks before terminating.
Just like using the "shutdown"button in the webui.

Besides, I have tried this before:

import pwnagotchi

and it shut down immediately without changing its screen.