My container runs a webserver and some sensors. It is intended as a edge compute unit for field use. I've had issues in the past with the none dockerised version, when it was turned off without using the webserver shutdown button.
The recent design change has allowed me to add a button tied to a GPIO pin. My container runs in privileged mode, I'm assuming that I can monitor this button and run a script with "shutdown -h now" when it is pressed?
Is this the case? The host system is Debian.
You can run
haltwhich will immediately halt your system by sendingreboot(LINUX_REBOOT_CMD_HALTsystemd call to kernel. I/O operations will not be flushed, data may be lost. It's nice to callsyncbefore it.To gracefully shutdown your system, you have to communicate to your system manager the intent of shutting down.
Some time ago,
shutdownwas just sending a signal to PID 1 (i.e. it's communicating the intent of shutting down). In case of docker, it will kill PID 1 inside the container, so docker container will just be stopped.In case of nowadays with systemd, you would have to send a dbus (or whatever systemd uses to communicate) message to PID 1 systedm process on your host.
The simplest would be to just
sshto your host and executeshutdown(orsystemd-shutdown).I think the much harder solution would be to access the DBUS from host and send the proper message on it.